CSCE 146 Algorithmic Design II Exam 2
What are the steps to removing a value from a BINARY search tree?
1) Find value 2) Remove/ Get rid of value 3) Replace with SMALLEST value on the RIGHT subtree, or LARGEST value on the LEFT subtree.
What are the steps to inserting values in a heap?
1) Start from first null value (add to bottom) 2) Bubble Up
For each algorithm, what are its worst runtimes in "Big O" notation? 1.) Binary Search 2.) Merge Sort 3.) Quick Sort 4.) Insertion Sort 5.) Bubble Sort 6.) Selection Sort 7.) Binary Search Tree Insertion 8.) Tower of Hanoi 9.) Traveling Sales Person
1.) O (lg n) 2.) O (n lg n) 3.) O (n lg n) 4.) O (n²) 5.) O (n²) 6.) O (n²) 7.) O (lg n) 8.) O (2ⁿ) 9.) O (n!)
Sort These "Big O" times from fastest to longest O(n) O(n²) O(n lg(n)) O(n³) O(1) O(n!) O(nⁿ) O(lg(n)) O(2ⁿ)
1.) O(1)→ constant value, will always run faster than anything else 2.) O(lg(n))→ Ex. BS Search Tree 3.) O(n)→ linear time 4.) O(n lg(n))→ Ex. Merge Sort 5.) O(n²)→ Ex. Double 'for' loop, selection/bubble sort 6.) O(n³)→ Ex. Matrix Multiplication 7.) O(2ⁿ)→Exponential time 8.) O(n!)→factorial time, Ex. 'Traveling Salesman' Problem 9.) O(nⁿ)→worst run time
What is the algorithm/ trick to find the "pre-order" traversal for a tree?
Algorithm→ access (print) value, then left subtree, then right subtree Trick → start from root, every time pen passes to left, write value down.
What is the algorithm/ trick to find the "post-order" traversal for a tree?
Opposite of "pre-order" traversal Algorithm→ traverse each left subtree, then traverse each right subtree, then visit the root
Describe a MAX heap
the parent's value is greater than any of its children below it
Describe a MIN heap
the parent's value is less than any of its children below it
