MC

These guys

Here’s a study-friendly flashcard format for the content you provided, broken down into clear Q&A style cards for quick review:


🔹 Binary Heap (Min-Heap)

Q: What makes a binary heap valid?
A: It must be a complete binary tree and satisfy the heap property: parent ≤ children.

Q: How do you add to a binary heap?
A: Insert at the next open spot, then bubble up to restore the heap property.

Q: How do you delete from a binary heap (min as priority)?
A: Remove the root, replace with the last node, then bubble down to restore order.


🔹 Binary Search Tree (BST)

Q: What makes a binary search tree valid?
A: It must follow the BST property: left < root < right.

Q: How do you add to a BST?
A: Recursively find the correct spot and insert the value as a leaf.

Q: How do you delete from a BST (min as priority)?
A: Remove node:

  • Leaf → delete

  • 1 child → replace with child

  • 2 children → replace with in-order successor, then delete the successor.


🔹 AVL Tree

Q: What makes an AVL tree valid?
A: It must be a BST and balanced, with a balance factor ∈ {–1, 0, 1}.

Q: How do you add to an AVL tree?
A: Insert like in a BST, then rebalance using rotations (LL, RR, LR, RL) if needed.

Q: How do you delete from an AVL tree (min as priority)?
A: Delete like in a BST, then rebalance up the path to the root using rotations.


📚 Sorting Algorithms Flashcards


🔸 Bubble Sort

Q: How does Bubble Sort work?
A: It repeatedly swaps adjacent elements if they are in the wrong order.

Q: What is Bubble Sort's time complexity?
A: Worst & Average: O(n²), Best: O(n).

Q: What is Bubble Sort's memory usage?
A: O(1) (in-place).

Q: Is Bubble Sort stable?
A: Yes.


🔸 Insertion Sort

Q: How does Insertion Sort work?
A: Builds the sorted list one item at a time by inserting into the correct position.

Q: What is Insertion Sort's time complexity?
A: Worst & Average: O(n²), Best: O(n).

Q: What is Insertion Sort's memory usage?
A: O(1) (in-place).

Q: Is Insertion Sort stable?
A: Yes.


🔸 Selection Sort

Q: How does Selection Sort work?
A: Repeatedly selects the smallest element and moves it to the sorted position.

Q: What is Selection Sort's time complexity?
A: Worst/Average/Best: O(n²).

Q: What is Selection Sort's memory usage?
A: O(1) (in-place).

Q: Is Selection Sort stable?
A: ✘ No.


🔸 Shell Sort

Q: How does Shell Sort work?
A: Improves insertion sort by comparing and sorting elements far apart (using a gap sequence).

Q: What is Shell Sort's time complexity?
A: Worst: O(n²) or better depending on gap, Best: O(n log n).

Q: What is Shell Sort's memory usage?
A: O(1) (in-place).

Q: Is Shell Sort stable?
A: ✘ No.


🔸 Quick Sort

Q: How does Quick Sort work?
A: Divides the array around a pivot and recursively sorts partitions.

Q: What is Quick Sort's time complexity?
A: Worst: O(n²), Average/Best: O(n log n).

Q: What is Quick Sort's memory usage?
A: O(log n) for recursion stack.

Q: Is Quick Sort stable?
A: ✘ No.


🔸 Merge Sort

Q: How does Merge Sort work?
A: Splits the array, recursively sorts halves, and merges them.

Q: What is Merge Sort's time complexity?
A: All cases: O(n log n).

Q: What is Merge Sort's memory usage?
A: O(n) for merging.

Q: Is Merge Sort stable?
A: Yes.