CSCE 146 Algorithmic Design II Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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


Kaugnay na mga set ng pag-aaral

Maternity and Newborn Health "Antepartum" 58 Questions

View Set

ISDS 3115 Ch. 3 study plan (concept questions)

View Set

Unit 1 Quiz Corrections ( CH. 2, 3, 4 WRITTEN AND OBJECTIVE )

View Set

Ch. 5 - Closing, Possession and More

View Set

Ch. 36 Interest Rates and Monetary Policy

View Set

merensalsa bio chapter 5 5.1-5.9

View Set

Business 1305: Module 2 Computer Concepts Exam

View Set

Drawbacks of Artificial Intelligence and Their Potential Solutions in the Healthcare Sector

View Set

History of Economic Thought Final

View Set