A vertex (or node) is a fundamental unit in a graph that represents an entity or point. It is where edges connect.
Click to reveal answer
beginner
Define an edge in a graph.
An edge is a connection or link between two vertices in a graph. It shows a relationship or path between them.
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 has no direction and 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, such as distance, cost, or time, representing the strength or cost of the connection.
Click to reveal answer
intermediate
Can a graph have both directed and undirected edges?
Yes, such graphs are called mixed graphs. They contain both directed and undirected edges connecting vertices.
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 direction of an edge
✗ Incorrect
A vertex is a point or node in a graph representing an entity.
Which type of edge has a direction?
AUndirected edge
BDirected edge
CWeighted edge
DLoop edge
✗ Incorrect
A directed edge has a direction from one vertex to another.
What does a weighted edge represent?
AA connection without value
BAn isolated node
CA vertex in the graph
DA connection with a value like cost or distance
✗ Incorrect
A weighted edge carries a value such as cost or distance.
In an undirected graph, edges are:
ATwo-way connections
BOne-way connections
CAlways weighted
DAlways loops
✗ Incorrect
Undirected edges connect vertices both ways, like two-way streets.
What is a mixed graph?
AA graph with no edges
BA graph with only weighted edges
CA graph with both directed and undirected edges
DA graph with only vertices
✗ Incorrect
A mixed graph contains both directed and undirected edges.
Explain the difference between directed and undirected edges in a graph.
Think about how traffic flows on one-way and two-way streets.
You got /3 concepts.
Describe what a weighted graph is and why weights might be useful.
Consider how maps show distances or costs between places.
You got /3 concepts.
Practice
(1/5)
1. In a graph, what do we call the points or nodes where edges meet?
easy
A. Vertices
B. Edges
C. Weights
D. Paths
Solution
Step 1: Understand graph components
A graph consists of points called vertices and connections called edges.
Step 2: Identify the term for points
The points or nodes where edges meet are called vertices.
Final Answer:
Vertices -> Option A
Quick Check:
Points in graph = Vertices [OK]
Hint: Vertices are the points, edges are the lines connecting them [OK]
Common Mistakes:
Confusing edges with vertices
Thinking weights are points
Mixing paths with vertices
2. Which of the following is the correct way to represent a weighted edge from vertex A to vertex B with weight 5 in Python using a tuple?
easy
A. (5, A, B)
B. [A, B, 5]
C. {'A': 'B', 'weight': 5}
D. (A, B, 5)
Solution
Step 1: Understand tuple representation
A weighted edge is often represented as a tuple (start_vertex, end_vertex, weight).
Step 2: Match the correct tuple format
The tuple (A, B, 5) correctly shows an edge from A to B with weight 5.
Final Answer:
(A, B, 5) -> Option D
Quick Check:
Weighted edge tuple = (start, end, weight) [OK]
Hint: Weighted edges use (start, end, weight) tuple format [OK]
Common Mistakes:
Using list instead of tuple
Putting weight first
Using dictionary instead of tuple
3. What will be the output of the following Python code snippet?