![Page 1: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/1.jpg)
Final Review
Dr. Yingwu Zhu
![Page 2: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/2.jpg)
Goals
• Use appropriate data structures to solve real-world problems– E.g., use stack to implement non-recursive BST
traversal, – use queue to implement BST level traversal, – use stack to implement non-recursive quicksort– use heaps to do heapsort, and priority queues
• Use appropriate algorithms to slove real-world problems– Search algorithms– Sorting algorithms
![Page 3: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/3.jpg)
Goals
• Use Big-Oh notation to evaluate algorithm efficiency
• Understand ADTs including BST, Heap, Priority Queue, AVL trees
• Understand hashing • Understand sorting algorithms
![Page 4: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/4.jpg)
ADTs
• Tree terminologies
• BST
• AVL Trees
• Heap
• Priority Queue
![Page 5: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/5.jpg)
Trees
• Binary trees
• Complete trees
• Balanced trees
• Level
• Height
![Page 6: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/6.jpg)
BST
• Definition• Recursive ADT• Implementing a BST (recursive and non-
recursive)– Search– Traversals (in-order, pre-order, post-order)– Insertion– Deletion– Other operations: height, level, …
![Page 7: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/7.jpg)
BST
• T(n) = ?• Is BST balanced?• Lopsidedness problem!• BST AVL trees
![Page 8: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/8.jpg)
AVL Trees
• Definition• Four rotation techniques
– Single rotations– Double rotations
• Key to perform rotation: identify the nearest ancestor with BF of +2 or -2 for the inserted item
• Two steps in double rotations– Rotate child and grandchild nodes of the ancestor– Rotate the ancestor and the new child node
![Page 9: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/9.jpg)
Heap
• Defintion
• Recusive data structure
• Semiheap
• What data structures are good to implement a heap? Why?
• Parent-child relationships
![Page 10: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/10.jpg)
Heap
• Implementation– Insertion– Deletion– removeMax– Other operations?
• Two basic operations– Percolate down– Percolate up
![Page 11: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/11.jpg)
Priority Queue
• Definition
• Using different ADTs to implement priority queue– Unsorted lists– Sorted lists– BST– Heap
• Why heap is a good choice?
![Page 12: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/12.jpg)
Hashing
• Why need hashing?
• Definition of hash function?
• Problem of hashing: collision
![Page 13: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/13.jpg)
Hashing
• Collision resolution techniques– Open addressing
• Linear probing• Quadratic probing• Double hashing
– Chaining
![Page 14: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/14.jpg)
Hashing
• Three strategies to improve hashing performance
– Increase hash table capacity– Use a good hash function (how to evaluate a
hash function?)– Use a good collision resolution technique
![Page 15: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/15.jpg)
Algorithm Efficiency
• Big-Oh notation definition T(n)
• Non-recursive algorithms– The most executed instruction
• Recursive algorithms: telescoping principal– Anchor case– Inductive step
![Page 16: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/16.jpg)
Sort
• Selection sort, insertion sort, bubble sort
• Heapsort
• Quicksort
• Mergesort
![Page 17: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/17.jpg)
Selection Sort
• How does it work?
• T(n) = ?
![Page 18: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/18.jpg)
Insertion Sort
• How does it work?
• T(n) = ?
• Recursive and Non-recursive algorithms
![Page 19: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/19.jpg)
Bubble Sort
• How does it work?
• How does it detect partially sort sublist to improve performance
• T(n) = ?
• Best case performance
• Worst case performance
![Page 20: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/20.jpg)
Quicksort
• How does it work?– Devide and conquer
• Basic operation– Split based on pivot
• T(n) = ? best case and worst case?
![Page 21: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/21.jpg)
Quicksort
• How to improve performance– Median-of-three rule in pivot choice– Short sublists are handle first in recursive alg.– Non-recursive– Other solutions
![Page 22: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/22.jpg)
Mergesort
• Internal and external algorithm
• Basic operation: split and merge
• Divide-and-conquer
• T(n) = ?
![Page 23: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/23.jpg)
Heapsort
• Heapify process
• How does heapsort work?– Exploits heap property– T(n) = ?
![Page 24: Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,](https://reader035.vdocuments.site/reader035/viewer/2022081516/56649ebb5503460f94bc4250/html5/thumbnails/24.jpg)
About Final Exam
• Must >= 75 to pass
• Multiple choices
• Short answers
• Coding
• Reminder: do not loose points in basic concept questions!
• Good luck!