অয়লার চক্র/সার্কিট হল একটি পথ; যার মাধ্যমে আমরা প্রতিটি প্রান্ত একবার ঘুরে দেখতে পারি। আমরা একাধিকবার একই শীর্ষবিন্দু ব্যবহার করতে পারি। অয়লার সার্কিট হল একটি বিশেষ ধরনের অয়লার পাথ। যখন অয়লার পথের শুরুর শীর্ষবিন্দুটিও সেই পথের শেষ শীর্ষের সাথে সংযুক্ত থাকে, তখন একে অয়লার সার্কিট বলা হয়।

একটি গ্রাফ ইউলারিয়ান কিনা তা পরীক্ষা করতে, আমাদের দুটি শর্ত পরীক্ষা করতে হবে −
-
গ্রাফটি অবশ্যই সংযুক্ত থাকতে হবে।
-
প্রতিটি শীর্ষবিন্দুর ইন-ডিগ্রী এবং আউট-ডিগ্রী অবশ্যই একই হতে হবে।
ইনপুট − গ্রাফের সংলগ্নতা ম্যাট্রিক্স।
| 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 |
আউটপুট - অয়লার সার্কিট পাওয়া গেছে
অ্যালগরিদম
ট্রাভার্স(u, পরিদর্শন করা)
ইনপুট − কোন নোডটি পরিদর্শন করা হয়েছে তা চিহ্নিত করতে স্টার্ট নোড u এবং ভিজিট করা নোড।
আউটপুট − সমস্ত সংযুক্ত শীর্ষবিন্দু অতিক্রম করুন৷
৷Begin
mark u as visited
for all vertex v, if it is adjacent with u, do
if v is not visited, then
traverse(v, visited)
done
End সংযুক্ত (গ্রাফ)
ইনপুট - গ্রাফ।
আউটপুট − গ্রাফটি সংযুক্ত থাকলে সত্য৷
৷Begin
define visited array
for all vertices u in the graph, do
make all nodes unvisited
traverse(u, visited)
if any unvisited node is still remaining, then
return false
done
return true
End isEulerCircuit(গ্রাফ)
ইনপুট - প্রদত্ত গ্রাফ।
আউটপুট - সত্য যখন একটি অয়লার সার্কিট পাওয়া যায়।
Begin if isConnected() is false, then return false define list for inward and outward edge count for each node for all vertex i in the graph, do sum := 0 for all vertex j which are connected with i, do inward edges for vertex i increased increase sum done number of outward of vertex i is sum done if inward list and outward list are same, then return true otherwise return false End
উদাহরণ কোড
#include<iostream>
#include<vector>
#define NODE 5
using namespace std;
int graph[NODE][NODE] = {{0, 1, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 1, 1},
{1, 0, 0, 0, 0},
{0, 0, 1, 0, 0}};
void traverse(int u, bool visited[]) {
visited[u] = true; //mark v as visited
for(int v = 0; v<NODE; v++) {
if(graph[u][v]) {
if(!visited[v])
traverse(v, visited);
}
}
}
bool isConnected() {
bool *vis = new bool[NODE];
//for all vertex u as start point, check whether all nodes are visible or not
for(int u; u < NODE; u++) {
for(int i = 0; i<NODE; i++)
vis[i] = false; //initialize as no node is visited
traverse(u, vis);
for(int i = 0; i<NODE; i++) {
if(!vis[i]) //if there is a node, not visited by traversal, graph is not connected
return false;
}
}
return true;
}
bool isEulerCircuit() {
if(isConnected() == false) { //when graph is not connected
return false;
}
vector<int> inward(NODE, 0), outward(NODE, 0);
for(int i = 0; i<NODE; i++) {
int sum = 0;
for(int j = 0; j<NODE; j++) {
if(graph[i][j]) {
inward[j]++; //increase inward edge for destination
vertex
sum++; //how many outward edge
}
}
outward[i] = sum;
}
if(inward == outward) //when number inward edges and outward edges
for each node is same
return true;
return false;
}
int main() {
if(isEulerCircuit())
cout << "Euler Circuit Found.";
else
cout << "There is no Euler Circuit.";
} আউটপুট
Euler Circuit Found.