Data Structures Graphs & Heaps Unit Test Prep

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/50

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:40 PM on 4/28/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

51 Terms

1
New cards

What is a graph in data structures?

A collection of nodes (vertices) connected by edges that represent relationships between elements

2
New cards

What is a vertex (node)?

A fundamental unit in a graph that represents an entity or value

3
New cards

What is an edge?

A connection between two vertices in a graph

4
New cards

What is the difference between a directed and undirected graph?

Directed graphs have edges with direction (u → v), while undirected graphs have bidirectional edges (u — v)

5
New cards

What is a cycle in a graph?

A path that starts and ends at the same vertex without repeating edges

6
New cards

What is an acyclic graph?

A graph with no cycles

7
New cards

What is a DAG?

A Directed Acyclic Graph (a directed graph with no cycles)

8
New cards

What is topological ordering?

A linear ordering of vertices in a DAG such that for every directed edge u → v, u comes before v

9
New cards

When is topological ordering possible?

Only when the graph is a DAG (no cycles)

10
New cards

What is an adjacency matrix?

A 2D array used to represent a graph where rows and columns represent nodes

11
New cards

How do you define a graph using an adjacency matrix?

Create an n x n matrix where n is the number of nodes, and fill entries based on edges

12
New cards

What does each row in an adjacency matrix represent?

A source node

13
New cards

What does each column in an adjacency matrix represent?

A destination node

14
New cards

What does a 1 (or non-zero value) mean in an adjacency matrix?

An edge exists between two nodes

15
New cards

What does a 0 mean in an adjacency matrix?

No edge exists between two nodes

16
New cards

How many entries represent an edge in an undirected graph adjacency matrix?

Two entries (symmetric positions)

17
New cards

How many entries represent an edge in a directed graph adjacency matrix?

One entry

18
New cards

What is the time complexity to check if an edge exists using an adjacency matrix?

O(1)

19
New cards

What is a common bug when working with adjacency matrices?

Forgetting symmetry in undirected graphs or mixing up row/column meaning

20
New cards

What should you check when debugging graph code?

Correct edge insertion, proper traversal logic, handling visited nodes, and edge direction

21
New cards

What is a common mistake in graph traversal code?

Not marking nodes as visited, leading to infinite loops

22
New cards

What is DFS (Depth-First Search)?

A traversal that explores as far as possible down one path before backtracking

23
New cards

What is BFS (Breadth-First Search)?

A traversal that explores all neighbors before moving to the next level

24
New cards

What is a heap?

A complete binary tree that satisfies the heap property

25
New cards

What is the heap property?

In a max heap, parent ≥ children; in a min heap, parent ≤ children

26
New cards

What is a complete binary tree?

A tree where all levels are full except possibly the last, filled left to right

27
New cards

What is a max heap?

A heap where the largest element is always at the root

28
New cards

What is a min heap?

A heap where the smallest element is always at the root

29
New cards

How is a heap typically stored?

As an array

30
New cards

What is the index relationship in a heap array?

For node at index i: left child = 2i+1, right child = 2i+2, parent = (i-1)/2

31
New cards

How does adding (inserting) to a heap work?

Add to the end, then bubble up to restore heap property

32
New cards

What is bubbling up?

Swapping a node with its parent until the heap property is satisfied

33
New cards

How does removing from a heap work?

Remove root, replace with last element, then bubble down

34
New cards

What is bubbling down?

Swapping a node with its larger (max heap) or smaller (min heap) child until heap property is restored

35
New cards

What is the time complexity of insert in a heap?

O(log n)

36
New cards

What is the time complexity of remove in a heap?

O(log n)

37
New cards

What is a common bug in heap code?

Incorrect parent/child index calculations

38
New cards

What is another common heap mistake?

Not handling edge cases like empty heap or single element

39
New cards

What does it mean to trace a path between two nodes?

Follow edges step-by-step to determine if a path exists between nodes

40
New cards

What algorithm is often used to trace paths?

DFS or BFS

41
New cards

What should you include in a path-tracing method?

A visited set and a base case when the target is found

42
New cards

What is a base case in recursive graph traversal?

When the current node is the target node

43
New cards

Why is a visited set important?

To prevent infinite loops in cyclic graphs

44
New cards

What might an FRQ ask you to implement with graphs?

Methods like addEdge, hasPath, or traversal functions

45
New cards

What might an FRQ ask you to explain?

How a traversal works or why a bug occurs

46
New cards

What might an FRQ ask you to debug?

Fix incorrect edge handling, traversal logic, or missing visited checks

47
New cards

What is a graph class responsible for?

Managing nodes and edges

48
New cards

What is a node class responsible for?

Storing value and references to neighbors

49
New cards

How do you represent neighbors in a node class?

Using a list or set of adjacent nodes

50
New cards

What is a typical method for checking connectivity?

hasPath(start, end)

51
New cards

What is the general approach for hasPath?

Use DFS or BFS to see if end node is reachable from start