CS 240 FINAL: PART 3/4 Flashcards

(14 cards)

1
Q

Q: Time complexity for search/insert/delete in a hash table?

A

A: O(1) average, O(n) worst (many collisions)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: What is a collision and how is it handled?

A

A: When two keys hash to the same index.
Handled by: Chaining (linked list at index) AND Open Addressing (find next empty slot)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How does insertion work in a hash table?

A

A: Hash the key and insert at the index. Handle collisions if necessary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What is Hashing?

A

A: A way to map keys to array indices using a hash function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Time complexity for insert/delete in a Heap?

A

A: O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How is a Heap stored?

A

A: As a complete binary tree using an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How does deletion (root) work in a Heap?

A

A: Replace root with last element, delete last, then heapify down (swap down).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What is a Heap?

A

A: A binary tree where:

In a Min-Heap, parent ≤ children

In a Max-Heap, parent ≥ children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: How does insertion work in a Heap?

A

A: Add at the end, then heapify up (swap up until heap property is restored).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Time complexity (search/insert/delete) in balanced BST?

A

A: O(log n) average, O(n) worst case (unbalanced tree).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How does deletion work in a BST?

A

A:

No child → delete node.

One child → replace with child.

Two children → replace with in-order successor or predecessor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What is a Binary Search Tree (BST)?

A

A: A tree where each left child is smaller and each right child is larger than the parent node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How does searching work in a BST?

A

A: Start at the root, go left if the target is smaller, right if larger, until found or null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: How does insertion work in a BST?

A

A: Compare and go left or right recursively until a null spot is found; insert there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly