graphs Flashcards
Draw Eulerian Cycle, if Exists 1
Figure at 8:15
directed graph
The edges between any two vertices in a “directed graph” graph are directional.
What are entry and exit vertices in Eulerian Path graph
Start and end at two different vertices
If number of vertices with odd degree is more than 2, will there be any Eulerian cycle or path?
No. There can only be Eulerian cycle when all vertices are of even degree, and Eulerian path only when 2 of the vertices are odd degree
Is graph has to be connected if it needs to have Eulerian cycle?
Not true. One connected component within the graph may be eulerian cycle on it’s own.
Sample picture attached
Degree of Vertx
the term “degree” applies to unweighted graphs. The degree of a vertex is the number of edges connecting the vertex. In Figure 1, the degree of vertex A is 3 because three edges are connecting it.
Rule of Thumb for “Eulerian Cycle” to exist in a graph
Every degree of the vertex in the connected component must be even to have valid Eulerian Cycle.
Connected Component
A piece of graph, within which we can reach from one vertex to other. However we can not move the vertices into one from other connected component without loosing it’s connectedness property
If can we draw diagram without lifting pen even once & do not retrace the same line again, and end at the same starting point within a Graph
We call that graph has Eulerian Cycle in it
How to draw Eulerian Cycle within given graph?
1) Start walking randomly
2) Keep going until we can walk
3) When there are no choices and no Eulerian cycle exists - back track from final position until where we would have done wrong turn.
4) Start walking randomly again
5) Anytime make sure we have even number of unused vertices, during this back track and mini walks
6) Repeat process
Draw Eulerian Cycle, if Exists
picture at 1:11/Eulerian Cycle Construction
Eulerian Cycle also known as
Eulerian circuit
Eulerian Tour
Euler Circuit
Euler Tour
Path Length
the number of edges in a path. In Figure 1, the path lengths from person A to C are 2, 3, and 5, respectively.
Cycle
A path where the starting point and endpoint are the same vertex. In Figure 1, [A, B, D, F, E] forms a cycle. Similarly, [A, G, B] forms another cycle.
Eulerian Path
Undirected graph has a non cyclic path that covers each edge exactly once. but doesn’t need to end at same vertex
Path
the sequence of vertices to go through from one vertex to another. In Figure 1, a path from A to C is [A, B, C], or [A, G, B, C], or [A, E, F, D, B, C].
**Note**: there can be multiple paths between two vertices.
If degree of any vertex in connected component is odd, will there be valid Eulerian Cycle
No. Because there will be no unused Edge to exit at some point in the tour.
Is it possible for a graph to have odd number of vertices with odd degree?
No. It’s impossible
If graph is connected, and degree of every vertex is even - Does it have Eulerian cycle?
Yes
Eulerian Cycle
Undirected graph has a cycle, that covers each edge exactly once. And it comes to same vertex as it started
Connectivity
If there exists at least one path between two vertices, these two vertices are connected. In Figure 1, A and C are connected because there is at least one path connecting them.
What is the mathematical condition for a graph to have Eulerian Path
Every vertex in graph except only 2 of them should have even degree.
Always the path should start and end at Odd degree vertices.
All other vertices should have even degree, so tour will not be trapped.
Negative Weight Cycle
In a “weighted graph”, if the sum of the weights of all edges of a cycle is a negative value, it is a negative weight cycle. In Figure 4, the sum of weights is -3.
Draw Eulerian Cycle, if Exists 3
Figure at 8:15
Types of graphs
Undirected
Directed
Unweighted
Weighted
If connected graph has exactly 2 odd degree vertices, does there a valid Eulerian path exist?
Yes
Undirected Graph
The edges between any two vertices in an “undirected graph” do not have a direction, indicating a two-way relationship.
Paste sample pic
Connected Graph
An undirected graph is connected if we can start from any vertex & reach any other vertex
Sample picture
Graph
“Graph” is a non-linear data structure consisting of vertices and edges.
Is it possible for a graph with single vertex with an odd degree?
No
By Maths:
sum of degrees = 2 * number of edges. So it is always even
Draw Eulerian Cycle
Sample pic attached from 3:25
Weighted Graph
Each edge in a “weighted graph” has an associated weight. The weight can be of any metric, such as time, distance, size, etc. The most commonly seen “weighted map” in our daily life might be a city map.
Out degree
“out-degree” is a concept in directed graphs. If the out-degree of a vertex is d, there are d edges incident from the vertex. In Figure 2, A’s outdegree is 3, i,e, the edges A to B, A to C, and A to G.
Vertex
nodes such as A, B, and C are called vertices of the graph.
Draw Eulerian Cycle, if Exists 2
Figure at 8:15
In degree
“in-degree” is a concept in directed graphs. If the in-degree of a vertex is d, there are d directional edges incident to the vertex. In Figure 2, A’s indegree is 1, i.e., the edge from F to A.
Edge
The connection between two vertices are the edges of the graph. In Figure 1, the connection between person A and B is an edge of the graph.