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 problem, solve the smaller problem, and then extend the solution to the whole. A common example is the binary search, which decreases the size of a problem by half for each iteration. Topological sorting is also a decrease-and-conquer algorithm because it reduces the size of a problem by a constant (one). Decrease-and-conquer is different than divide-and-conquer because decrease only creates one new subproblem rather than a number of subproblems.
  • DAG = directed acyclic graph. Topological sorting can determine if a graph is a DAG: if there are back nodes, then the graph is not a DAG.
    This week, we practiced the BFS algorithm more in the homework, which I was happy to get working. I took a few hours today troubleshooting why my code was not working. 
    At first, I had trouble understanding what was wrong with my implementation of the BFS algorithm (with the degree of connection array added), since I was not able to traverse through the entire graph. I later figured out that was because the way I implemented the input graph from user data was not correct. Instead of entering data in [x][y] ordering, I had mistakenly pushed data in an [{x y}] format. I had set the initial input graph as a 2D vector of strings, which is why I had to input data in that way. To fix this, I set up the userMap first and then assigned each edge data pair as an int, then pushed it to a 2D vector of ints instead.
Isopod Update: I think I found another pink pak chong, which is exciting!

Comments

Popular posts from this blog

CST300 - Week 4

CST334 - Week 6

CST334 - Week 5