A vertex (or node) is a fundamental part of a graph representing a point or position where edges meet. Think of it as a city on a map.
Click to reveal answer
beginner
What is an edge in a graph?
An edge connects two vertices in a graph. It represents a path or link between points, like a road connecting two cities.
Click to reveal answer
beginner
What is the difference between a directed and an undirected edge?
A directed edge has a direction, like a one-way street, showing movement from one vertex to another. An undirected edge has no direction, like a two-way street, allowing movement both ways.
Click to reveal answer
beginner
What does it mean if a graph is weighted?
A weighted graph has edges with values (weights) that represent cost, distance, or time. For example, a road might have a weight showing how long it takes to travel.
Click to reveal answer
intermediate
Can a graph have both directed and undirected edges?
Yes, such graphs are called mixed graphs. They contain some edges with direction and some without, like a map with both one-way and two-way streets.
Click to reveal answer
What is a vertex in a graph?
AA point where edges meet
BA connection between two points
CA direction of travel
DA value assigned to an edge
✗ Incorrect
A vertex is a point or node in a graph where edges connect.
Which type of edge has a direction?
AUndirected edge
BWeighted edge
CDirected edge
DLoop edge
✗ Incorrect
Directed edges have a direction, like one-way streets.
What does a weighted edge represent?
AA connection with a cost or value
BA connection without direction
CA vertex in the graph
DA disconnected node
✗ Incorrect
Weighted edges carry a value like cost, distance, or time.
In an undirected graph, edges are:
AAlways loops
BOne-way connections
CAlways weighted
DTwo-way connections
✗ Incorrect
Undirected edges allow movement both ways between vertices.
What is a mixed graph?
AA graph with only weighted edges
BA graph with both directed and undirected edges
CA graph with no edges
DA graph with only vertices
✗ Incorrect
Mixed graphs have both directed and undirected edges.
Explain the difference between directed and undirected edges in a graph.
Think about how traffic flows on different types of roads.
You got /3 concepts.
Describe what a weighted graph is and give an example of when it might be used.
Imagine planning a trip with different travel times.
You got /3 concepts.
Practice
(1/5)
1. Which of the following best describes a vertex in a graph?
easy
A. A point or node where edges meet
B. A line connecting two vertices
C. A graph with no edges
D. A graph that has weights on edges
Solution
Step 1: Understand the definition of vertex
A vertex is a fundamental unit in a graph representing a point or node.
Step 2: Differentiate vertex from edges and graph types
Edges connect vertices; weights and graph types describe edges or the whole graph, not vertices.
Final Answer:
A point or node where edges meet -> Option A
Quick Check:
Vertex = point/node [OK]
Hint: Vertices are points/nodes, edges are connections [OK]
Common Mistakes:
Confusing edges with vertices
Thinking weights define vertices
Mixing graph types with vertex definition
2. Which of the following is the correct way to declare an undirected weighted graph using adjacency list in Java?
easy
A. Map graph = new HashMap<>();
B. Map graph = new TreeMap<>();
C. Map>> graph = new TreeSet<>();
D. Map>> graph = new HashMap<>();
Solution
Step 1: Identify data structure for weighted edges
Weighted edges need to store both neighbor and weight, so Pair is used.
Step 2: Choose correct map and list types
HashMap with List of pairs is standard for adjacency list of weighted graphs.
Final Answer:
Map>> graph = new HashMap<>(); -> Option D
Quick Check:
Weighted graph uses Pair for edges [OK]
Hint: Weighted edges need pairs: neighbor and weight [OK]
Common Mistakes:
Using List<Integer> for weighted edges
Using TreeSet instead of List for adjacency
Confusing Map types for graph
3. Consider the following Java code snippet for a directed graph: