Lizzy McDSA

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

1/55

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:58 PM on 10/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

56 Terms

1
New cards

Tree

data that branches instead of forming a line; one item on top, each item can lead to several below it (like folders holding folders).

2
New cards

Root

the top node of a tree.

3
New cards

Parent / Child

the node above / the node below.

4
New cards

Leaf

a node with no children.

5
New cards

Edge

a line connecting parent to child.

6
New cards

Height

number of edges on the longest path down from a node.

7
New cards

Binary Tree

each node has at most two children: left and right.

8
New cards

Node (in code)

holds a value plus left and right links to its children.

9
New cards

Tree as a List

no links stored; position alone tells you the relationships: left child = 2i+1, right child = 2i+2, parent = (i-1)//2.

10
New cards

Preorder Traversal

visit root → left → right.

11
New cards

Inorder Traversal

visit left → root → right.

12
New cards

Postorder Traversal

visit left → right → root.

13
New cards

Level Order Traversal

visit top level first, left to right (uses a queue).

14
New cards

Binary Search Tree (BST)

a binary tree with one rule: smaller goes left, bigger goes right, at every node.

15
New cards

BST Insert

go left if smaller, right if bigger, stop at an empty spot.

16
New cards

BST Search

follow one path down; never look at the whole tree.

17
New cards

BST Delete (3 cases)

no children → just remove; one child → child moves up; two children → copy in the smallest key from the right subtree, then delete that key.

18
New cards

Insertion order matters

the same keys inserted in different orders produce trees of different heights/shapes (sorted input → a long skinny “line” tree).

19
New cards

Priority Queue

serves the most urgent item first, not the one that arrived first.

20
New cards

Heap

a binary tree with two rules: shape rule (filled level by level, no gaps) and order rule (every parent ≤ its children, for min-heap).

21
New cards

Min-Heap

parent is always smaller than its children; smallest value sits on top.

22
New cards

Max-Heap

parent is always bigger than its children; biggest value sits on top.

23
New cards

Heap stored in a list

same index formulas as a tree: left child = 2i+1, right child = 2i+2, parent = (i-1)//2. heap[0] is always the smallest (min-heap).

24
New cards

Insert (heap)

add the new value at the end of the list, then swap it upward until it’s no longer smaller than its parent.

25
New cards

Extract Min

take the root (smallest), move the last item to the top, then swap it downward (sift down) until the heap rule is restored.

26
New cards

sift_down

the helper that repeatedly swaps a value down until it’s smaller than both its children; used by both extract_min and heapify.

27
New cards

Heapify

turn any list into a valid heap by running sift_down on every parent node, from the last parent back to the root; O(n).

28
New cards

Heap Sort

heapify the list, then repeatedly extract the minimum until empty; results come out sorted. O(n log n) average and worst case.

29
New cards

Heap vs. Merge/Quick Sort

heap sort guarantees O(n log n) like merge sort, but (in its classic form) needs only O(1) extra space, unlike merge sort’s O(n).

30
New cards

Python’s heapq

a built-in min-heap module (heappush, heappop) that works just like the hand-built version.

31
New cards

The Problem

searching a plain list for an item gets slower as the list grows (O(n)); a hash table finds things in about one step (O(1)) regardless of size.

32
New cards

Hash Function

takes a key (e.g. a name) and turns it into a bucket number; same key always gives the same number.

33
New cards

Good hash function rules

same key → same number every time; spreads different keys across different buckets; fits the result inside the table size (using % size).

34
New cards

Collision

when two different keys hash to the same bucket number; unavoidable since there are far more possible keys than buckets.

35
New cards

Chaining

handles collisions by letting each bucket hold a list; colliding keys just get added to that bucket’s list.

36
New cards

Open Addressing

handles collisions by finding another empty slot instead of using a list.

37
New cards

Linear Probing

a type of open addressing: if a slot is taken, try the next slot (+1, +2, +3...).

38
New cards

Quadratic Probing

a type of open addressing: if a slot is taken, jump by increasing squared steps (+1, +4, +9...).

39
New cards

Put

hash the key to find its bucket, then add/update the key-value pair there.

40
New cards

Get

hash the key to find its bucket, then search only that bucket’s list for the value.

41
New cards

Load Factor

number of items stored divided by number of buckets; tells you how full the table is.

42
New cards

Rehashing

when the load factor gets too high (commonly over 0.75), grow the table (e.g. double the buckets) and re-insert every key, since each key’s bucket number depends on the table size.

43
New cards

Hash Table vs. BST

hash table: O(1) average lookup but keys are scattered (no sorted order). BST: O(log n) lookup but keys can be retrieved in sorted order (inorder traversal).

44
New cards

Python’s dict

is literally a hash table under the hood ([]= to put, [] to get, in to check membership).

45
New cards

What is the top node of a tree called?

The root.

46
New cards

Which traversal prints a BST’s keys from smallest to biggest?

Inorder traversal (left, root, right).

47
New cards

In the list form, the node at index 2 has its left child at which index?

Index 5, since the left child is at 2i + 1 = 2(2) + 1 = 5.

48
New cards

Insert 10, 20, 30 into an empty BST. What is the height? Which order gives a shorter tree?

The height is 2, because each key is bigger than the last, so the tree becomes a line (10, then 20 to its right, then 30 to the right of that). Inserting 20 first, then 10 and 30 (for example 20, 10, 30), gives a shorter tree with height 1.

49
New cards

In a min-heap stored in a list, where is the smallest value?

At the top of the heap, which is index 0 (heap[0]).

50
New cards

When you insert a value, where does it go first?

At the end of the list (the next open spot in the tree). Then it swaps up with its parent while it is smaller than the parent.

51
New cards

The node at index 2 has its children at which two indexes?

Index 5 and index 6, since the left child is 2i + 1 = 5 and the right child is 2i + 2 = 6.

52
New cards

Is [2, 1, 3] a min-heap? Why or why not?

No. The parent 2 is bigger than its left child 1, which breaks the order rule that every parent must be smaller than or equal to its children. The smallest value (1) should be on top.

53
New cards

Two different keys get the same bucket number. What is that called?

A collision.

54
New cards

A table has 10 buckets and 8 items. What is the load factor? Should it grow?

The load factor is 8 / 10 = 0.8. Yes, it should grow, because 0.8 is above 0.75 and the table is getting crowded.

55
New cards

After rehashing, why must every key be hashed again?

The bucket number depends on the table size (for example % 7 before and % 14 after). With a new size, the same key can get a different bucket number, so each key has to be hashed again to find its correct new spot.

56
New cards

ord(‘B’) is 66 and ord(‘o’) is 111. With our hash function and 7 buckets, where does ‘Bo’ go?

Bucket 2. The letter codes add up to 66 + 111 = 177, and 177 % 7 = 2.