0
0
DSA Typescriptprogramming~10 mins

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

Choose your learning style9 modes available
Concept Flow - Graph Terminology Vertices Edges Directed Undirected Weighted
Start: Define Graph
Vertices: Points/Nodes
Edges: Connections
Directed?
YesEdges have direction
Undirected: Edges bidirectional
Weighted?
YesEdges have weights (costs)
No
Edges unweighted
This flow shows how a graph is built from vertices and edges, then edges can be directed or undirected, and weighted or unweighted.
Execution Sample
DSA Typescript
const vertices = ['A', 'B', 'C'];
const edges = [
  { from: 'A', to: 'B', weight: 5 },
  { from: 'B', to: 'C', weight: 3 }
];
Defines a graph with 3 vertices and 2 directed weighted edges.
Execution Table
StepOperationVerticesEdgesEdge TypeWeightedVisual State
1Initialize vertices['A', 'B', 'C'][]N/AN/AVertices: A, B, C; No edges yet
2Add edge from A to B with weight 5['A', 'B', 'C'][A -> B (5)]DirectedYesA --5--> B; C isolated
3Add edge from B to C with weight 3['A', 'B', 'C'][A -> B (5), B -> C (3)]DirectedYesA --5--> B --3--> C
4Check if edges are directed['A', 'B', 'C'][A -> B (5), B -> C (3)]DirectedYesEdges have direction from source to target
5Check if edges are weighted['A', 'B', 'C'][A -> B (5), B -> C (3)]DirectedYesEdges carry weights 5 and 3
6End of graph definition['A', 'B', 'C'][A -> B (5), B -> C (3)]DirectedYesGraph fully defined
💡 All vertices and edges added; graph is directed and weighted
Variable Tracker
VariableStartAfter Step 2After Step 3Final
vertices[]['A', 'B', 'C']['A', 'B', 'C']['A', 'B', 'C']
edges[][A -> B (5)][A -> B (5), B -> C (3)][A -> B (5), B -> C (3)]
edgeTypeN/ADirectedDirectedDirected
weightedN/AYesYesYes
Key Moments - 3 Insights
Why do we say edges are 'directed' or 'undirected'?
Because directed edges have a clear start and end point (like one-way streets), while undirected edges connect two vertices both ways (like two-way streets). See execution_table rows 2 and 4 where edges are added and identified as directed.
What does it mean for edges to be weighted?
Weighted edges carry a number (weight) that can represent cost, distance, or capacity. In the table rows 2 and 3, each edge has a weight (5 and 3), showing weighted edges.
Can a graph have both directed and undirected edges?
Usually a graph is either directed or undirected for consistency. Mixing them is possible but uncommon and complicates traversal. Our example in rows 4 and 5 shows a directed graph.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, how many edges does the graph have?
A1
B3
C2
D0
💡 Hint
Check the 'Edges' column at step 3 in execution_table
At which step do we confirm the edges are weighted?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look at the 'Weighted' column in execution_table rows
If edges were undirected, how would the visual state change at step 3?
AEdges would have arrows both ways between vertices
BEdges would disappear
CVertices would be removed
DWeights would be ignored
💡 Hint
Refer to concept_flow where directed edges have one arrow, undirected have two-way connection
Concept Snapshot
Graph = vertices (points) + edges (connections)
Edges can be directed (one-way) or undirected (two-way)
Edges can be weighted (carry a number) or unweighted
Directed edges show direction from source to target
Weighted edges represent cost, distance, or capacity
Full Transcript
A graph consists of vertices, which are points or nodes, and edges, which connect these vertices. Edges can be directed, meaning they go from one vertex to another in a specific direction, or undirected, meaning the connection goes both ways. Additionally, edges can be weighted, carrying a number that represents cost or distance, or unweighted, meaning no such number is attached. In the example, we defined three vertices A, B, and C, and added two directed weighted edges: from A to B with weight 5, and from B to C with weight 3. This setup helps understand basic graph terminology and structure.