CST 370 - Module 5

 Week 5,

This module's material covered some more algorithms using divide and conquer. One of these algorithms is the quicksort algorithm. The goal of quicksort is to partition the array into two subarrays around a pivot. From there, we recursively sort the two subarrays, then combine the results. The Big Oh notation for quicksort is O(n*log(n)), which is similar to merge sort, however, when dealing with large sorting operations, quicksort beats merge sort by a small margin. 

Next, we talk about a divide and conquer ready data structure called a binary tree. Data is usually inserted to the left or the right of a root node, typically by smaller numbers to the left of the node, and greater numbers to the right. This continues further and further down the tree creating what could be describe as... well... a tree. The main problem with using this data structure is how to traverse the binary tree. In short (got to leave some room for you to research), we talk about three methods, pre-order (root->left->right), in-order (left->root->right), and post-order (left->right->root).

The next important bit of material covered introduced us to decrease and conquer. Decrease and conquer is a technique that solves problems by first making the problem smaller, as it would be easier. There are a couple ways of doing this. Decreasing by a constant, constant factor, and variable size decrease. One real example of a decrease and conquer algorithm is the binary search. When given a key or value to look for within an array, we start in the middle index of the array, if the value is smaller than the key, then we look at the value in the middle of the subarray to the right. If the value is greater than the key, then we look at the middle of the subarray to the left. repeat until we find the value. Every time we compare a value to the key, we cut down the number of elements we compare in half. The Big Oh notation of this would be O(log(n)).

Another topic introduced was DAG (Directed Acyclic Graph) and how we can determine if a directed graph has a cycle or not (DAG if there is no cycle). One way to find this is using Kahn's Algorithm, where we find the topological order using source removal, where we eliminate a vertex or vertices with 0 incoming vertices. After each removal, a vertex or vertices will have one less incoming vertex. If we manage to eliminate all vertices, the graph is indeed a DAG. If we end up with being unable to remove all the vertices, then the graph is not a DAG.

Comments

Popular posts from this blog

CST 338 - Module 4

CST 363 - Module 7

CST 363 Module - 1