0
0
DSA Cprogramming~10 mins

Graph Terminology Vertices Edges Directed Undirected Weighted in DSA C - Execution Trace

Choose your learning style9 modes available
Concept Flow - Graph Terminology Vertices Edges Directed Undirected Weighted
Start: Define Graph
Identify Vertices (Nodes)
Identify Edges (Connections)
Check Edge Type
Directed
Check Weight
Weighted
Graph Fully Defined
This flow shows how a graph is built by defining vertices, edges, then classifying edges as directed or undirected, and weighted or unweighted.
Execution Sample
DSA C
Graph G = {
  Vertices: {A, B, C},
  Edges: {(A->B, 5), (B->C, 3)}
};
Defines a graph with 3 vertices and 2 directed weighted edges.
Execution Table
StepOperationVerticesEdgesEdge TypeWeightVisual State
1Initialize graph{}{}N/AN/AGraph is empty
2Add vertex A{A}{}N/AN/AA
3Add vertex B{A, B}{}N/AN/AA B
4Add vertex C{A, B, C}{}N/AN/AA B C
5Add edge A->B with weight 5{A, B, C}{(A->B)}Directed5A --5--> B C
6Add edge B->C with weight 3{A, B, C}{(A->B), (B->C)}Directed3A --5--> B --3--> C
7Check if edges are weighted{A, B, C}{(A->B), (B->C)}DirectedWeightedEdges have weights 5 and 3
8Graph fully defined{A, B, C}{(A->B), (B->C)}DirectedWeightedFinal graph with 3 vertices and 2 weighted directed edges
💡 All vertices and edges added; graph classification complete.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6Final
Vertices{}{A}{A, B}{A, B, C}{A, B, C}{A, B, C}{A, B, C}
Edges{}{}{}{}{(A->B)}{(A->B), (B->C)}{(A->B), (B->C)}
Edge TypeN/AN/AN/AN/ADirectedDirectedDirected
WeightN/AN/AN/AN/A5 (A->B)3 (B->C)Weighted
Key Moments - 3 Insights
Why do we say edges can be directed or undirected?
Because edges show connections between vertices; directed edges have a direction (like one-way street), undirected edges do not (like two-way street). See execution_table steps 5 and 6 where edges are added as directed.
What does it mean for edges to be weighted?
Weighted edges have numbers (weights) showing cost or distance. In the table steps 5 and 6, weights 5 and 3 are assigned to edges, meaning these connections have values.
Can a graph have vertices without edges?
Yes, vertices can exist alone without edges. In step 4, vertices A, B, C exist before edges are added in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the edge type added?
AUndirected
BDirected
CWeighted
DUnweighted
💡 Hint
Check the 'Edge Type' column at step 5 in execution_table.
At which step are all vertices added to the graph?
AStep 4
BStep 3
CStep 2
DStep 6
💡 Hint
Look at the 'Vertices' column in execution_table to see when {A, B, C} appear.
If edges were unweighted, how would the 'Weight' column change at step 6?
AIt would show weights as 0
BIt would show the same weights
CIt would show 'N/A' or no weights
DIt would show negative weights
💡 Hint
Refer to the 'Weight' column in execution_table and think about what unweighted means.
Concept Snapshot
Graph = set of vertices (nodes) and edges (connections).
Edges can be directed (one-way) or undirected (two-way).
Edges can be weighted (have values) or unweighted.
Vertices can exist without edges.
Graph types depend on edge direction and weights.
Full Transcript
A graph is made of vertices and edges. Vertices are points or nodes. Edges connect vertices. Edges can have direction: directed edges go one way, undirected edges go both ways. Edges can also have weights, which are numbers showing cost or distance. Vertices can exist alone without edges. This example shows adding vertices A, B, C, then adding directed weighted edges A to B with weight 5, and B to C with weight 3. The graph is then fully defined as directed and weighted.