A vertex (or node) is a fundamental unit in a graph that represents an entity or point. It can connect to other vertices through edges.
Click to reveal answer
beginner
Define an edge in graph terminology.
An edge is a connection or link between two vertices in a graph. It can be directed or undirected.
Click to reveal answer
beginner
What is the difference between a directed and an undirected edge?
A directed edge has a direction from one vertex to another (like a one-way street). An undirected edge connects two vertices both ways (like a two-way street).
Click to reveal answer
beginner
What does it mean if a graph is weighted?
A weighted graph has edges that carry a value or weight, representing cost, distance, or any measure between vertices.
Click to reveal answer
intermediate
Can a graph have both directed and undirected edges?
Yes, such graphs are called mixed graphs, containing both directed and undirected edges.
Click to reveal answer
What is a vertex in a graph?
AA point or node representing an entity
BA connection between two nodes
CA value assigned to an edge
DA path between two graphs
✗ Incorrect
A vertex is a point or node in a graph representing an entity.
Which type of edge has a direction?
ADirected edge
BWeighted edge
CUndirected edge
DLoop edge
✗ Incorrect
A directed edge has a direction from one vertex to another.
In an undirected graph, edges are:
AOne-way connections
BTwo-way connections
CAlways weighted
DNot connected
✗ Incorrect
Undirected edges connect vertices both ways, like two-way streets.
What does a weight on an edge represent?
AThe color of the edge
BThe direction of the edge
CThe number of vertices
DThe cost or distance between vertices
✗ Incorrect
Weights represent cost, distance, or other measures on edges.
A graph with both directed and undirected edges is called:
ASimple graph
BWeighted graph
CMixed graph
DComplete graph
✗ Incorrect
A mixed graph contains both directed and undirected edges.
Explain the difference between vertices and edges in a graph.
Think of vertices as places and edges as roads connecting them.
You got /3 concepts.
Describe what makes a graph weighted and how weights affect edges.
Imagine roads with different lengths or toll costs.
You got /3 concepts.
Practice
(1/5)
1. In a graph, what do we call the points or nodes where edges meet?
easy
A. Paths
B. Edges
C. Weights
D. Vertices
Solution
Step 1: Understand graph components
A graph consists of points called nodes and connections called edges.
Step 2: Identify the term for nodes
The points or nodes where edges meet are called vertices.
graph[1] is a map with keys 2 and 3, values 5 and 10 respectively.
Step 2: Access graph[1][3]
graph[1][3] accesses the weight from vertex 1 to 3, which is 10.
Final Answer:
10 -> Option C
Quick Check:
Weight from 1 to 3 = 10 [OK]
Hint: Access nested map keys for weights: graph[from][to] [OK]
Common Mistakes:
Confusing weight 5 (edge 1->2) with 1->3
Assuming 0 means no edge but 3 has empty map
Mixing up keys and values in nested maps
4. Identify the error in this Go code snippet for adding an edge to an undirected graph adjacency list:
func addEdge(graph map[int][]int, u, v int) {
graph[u] = append(graph[u], v)
graph[v] = append(graph[u], v)
}
medium
A. Appending v to graph[u] twice
B. Appending v to graph[v] incorrectly
C. Missing initialization of graph map
D. Using wrong data type for graph
Solution
Step 1: Analyze append statements
First append adds v to graph[u], correct for edge u->v.
Step 2: Check second append
Second append incorrectly appends v to graph[u] again instead of graph[v].
Final Answer:
Appending v to graph[v] incorrectly -> Option B
Quick Check:
Second append should be graph[v] = append(graph[v], u) [OK]
Hint: For undirected, append u to v's list and v to u's list [OK]
Common Mistakes:
Appending to wrong slice variable
Forgetting to append both directions
Not initializing map slices before append
5. Given a weighted undirected graph represented as a map[int]map[int]int in Go, how can you ensure that adding an edge between two vertices u and v with weight w updates both directions correctly?