What is a key limitation of trees that graphs overcome?
Trees cannot model relationships where nodes have multiple parents or cycles. Graphs can represent these complex connections.
Click to reveal answer
beginner
Why do we need graphs when trees exist?
Graphs exist to model real-world problems where connections are not strictly hierarchical, such as social networks or road maps, which trees cannot represent.
Click to reveal answer
intermediate
What kind of relationships can graphs represent that trees cannot?
Graphs can represent many-to-many relationships, cycles, and complex networks where nodes can connect in any pattern, unlike trees which are strictly hierarchical and acyclic.
Click to reveal answer
intermediate
Explain why a family tree cannot model marriages between cousins but a graph can.
A family tree is hierarchical and does not allow cycles or multiple parents for a node. Marriages between cousins create cycles and multiple parent relationships, which graphs can model but trees cannot.
Click to reveal answer
beginner
What is a cycle in graph theory and why can't trees have them?
A cycle is a path where you can start at a node and return to it by following edges without retracing steps. Trees cannot have cycles because they are acyclic by definition.
Click to reveal answer
Which data structure can represent cycles?
AStack
BGraph
CArray
DTree
✗ Incorrect
Graphs can represent cycles; trees cannot because they are acyclic.
What kind of relationship can a tree NOT model?
AMany-to-many
BMany-to-one
COne-to-many
DNone of the above
✗ Incorrect
Trees cannot model many-to-many relationships because each node has only one parent.
Why are graphs used to model social networks?
ABecause social networks are linear
BBecause social networks have hierarchical data
CBecause social networks have cycles and complex connections
DBecause social networks have no connections
✗ Incorrect
Social networks have cycles and complex connections that graphs can model.
Which of these is NOT true about trees?
AThey can have multiple parents per node
BThey are acyclic
CThey have a hierarchical structure
DThey cannot represent cycles
✗ Incorrect
Trees cannot have multiple parents per node; each node has exactly one parent except the root.
What does a cycle in a graph allow that a tree forbids?
AOnly one child per node
BMultiple roots
CNo edges
DReturning to the same node by following edges
✗ Incorrect
A cycle allows returning to the same node by following edges, which trees forbid.
Explain why trees cannot model many real-world networks and how graphs solve this problem.
Think about family trees vs social networks.
You got /4 concepts.
Describe what a cycle is in graph theory and why it is important for modeling complex relationships.
Imagine a road map where you can drive in a loop.
You got /4 concepts.
Practice
(1/5)
1. Why do we need graphs when we already have trees in data structures?
easy
A. Because graphs use less memory than trees.
B. Because trees are faster to traverse than graphs.
C. Because graphs can represent connections between nodes in any pattern, including cycles and multiple parents.
D. Because trees can only store numbers, but graphs can store any data.
Solution
Step 1: Understand tree limitations
Trees have a strict hierarchy: each node has only one parent and no cycles.
Step 2: Understand graph capabilities
Graphs allow nodes to connect in any way, including cycles and multiple parents.
Final Answer:
Because graphs can represent connections between nodes in any pattern, including cycles and multiple parents. -> Option C
Quick Check:
Graphs model complex connections unlike trees [OK]
Hint: Graphs allow cycles and multiple parents; trees do not [OK]
Common Mistakes:
Thinking trees can have cycles
Confusing data types stored with structure type
Assuming graphs always use less memory
2. Which of the following is the correct way to represent an undirected graph using adjacency lists in Python?
easy
A. graph = [[1, 2], [2, 3], [3, 1]]
B. graph = {1: (2, 3), 2: (1), 3: (1)}
C. graph = {1: 2, 2: 3, 3: 1}
D. graph = {1: [2, 3], 2: [1], 3: [1]}
Solution
Step 1: Understand adjacency list format
Adjacency lists use a dictionary with keys as nodes and values as lists of connected nodes.
Step 2: Check each option
graph = {1: [2, 3], 2: [1], 3: [1]} uses dictionary with lists correctly; others use tuples, lists of pairs, or single values incorrectly.
Final Answer:
graph = {1: [2, 3], 2: [1], 3: [1]} -> Option D
Quick Check:
Adjacency list = dict with lists [OK]
Hint: Adjacency lists use dict keys with list values [OK]
Common Mistakes:
Using tuples instead of lists for adjacency
Using list of pairs instead of dict
Assigning single node instead of list
3. What will be the output of the following Python code that models a graph?