CST370 - Week 5
CST370 Week 5 Binary trees: A divide-and-conquer ready data structure. There are three ways to traverse it: preorder, inorder, and postorder traversal methods. Preorder visits from root -> left -> right. Inorder visits from left -> root -> right. Postorder visits from left -> right -> root. Binary search: An application of the decrease-and-conquer algorithm. Complexity is (big O)(logn). Quicksort: For time complexity, the best case is n(logn), while the worst case is n^2. To perform a quicksort, we assign the first value of an array as the pivot, and recursively travel forward (i) and backward(j) to find a spot where the pivot can create a partition. While traveling, we swap values of i and j whenever i > pivot and pivot > j. This should create a partition where all values preceding the pivot will be smaller than it, and all values after the pivot will be larger than it. Decrease-and-conquer: Technique to reduce the size of a problem into one smaller proble...