Posts

Showing posts from September, 2026

CST370 week 4

 This week was midterm prep but we also studied merge sort. Merge sort analysis is a first real application of using the Master Theorem on a divide and conquer algorithm. Merge sort works by continually dividing the array to be sorted in half, and sorting that half. Then we merge the two sorted halves by advancing a pointer on each half, coping the lowest value of either pointer to the result array and incrementing the pointer, until one half is exhausted, then we append the remainder of the sorted half to the end of the result array. The dividing is easy, and is a constant step = 1, which is the d  component of the master theorem. the a  is 2, because we divide both halves of the array and recurse, and the b  is 2 because it's dividing by 2. I.e. T(n) = 2T(n/2) + Θ(n), which is case 2 of the Master Theorem which means merge sort is Θ(n log n). 

CST370 week 3

 This week we covered some different searching problems. First was brute force methods for finding a substring in a string, the traveling salesman problem, assignment problem, and the knapsack problem. We looked at the high cost of using brute force on combinatorial problems: TSP and assignment problem are factorial and knapsack is exponential. The brute force strategy here is to do an exhaustive search through all potential solutions, either combinations or permutations, and determine the best solution(s) out of all possible answers. We then learned about depth first search. This was again a review of intro to algorithms. We use a stack and a tracking array, and a list of vertices with adjacency lists to search the whole graph in Θ(|V| + |E|) time. If we used an adjacency matrix it would by Θ(|V|²) time. Breadth first search, by contrast, uses a queue instead of a stack. The time complexity is the same as depth first search. The difference then is in how it performs as a sear...

CST370 week 2

 This week started with a review of the time category of algorithms and the three asymptotic notations we use to specify the bounds of an algorithm's time category. Big Omega is used to denote the best case boundary. Big O is used to denote the worst case boundary. Big Theta is used to denote a tight bound, where best and worst is the same time category. The time categories, in ascending order are 1, log n, n, n*log n, n², n³, 2ⁿ, and n!. Given the same amount of data being processed, the further left the faster the algorithm, and the further right the slower the algorithm. We learned about how to identify the category, by dropping all lower order terms and any constant coefficients to get the final category. For example, 5n*log n + 2n +14 is O(n log n). This is more straightforward to analyze in non-recursive algorithms because we count basic operation in loops or nested loops. Recursion doesn't loop per se, so we solve with backwards substitution by counting the basic operati...

CST 370 week 1

Week 1 of CST 370 introduced what an algorithm is: a finite sequence of unambiguous steps that turns a valid input for a problem into the required output. The GCD problem showed why the definition matters, and contrasted Euclid's algorithm against the middle-school procedure, which is not an algorithm because it has ambiguous steps. The pseudocode lecture set the notation for writing pseudocode which is purposefully different from writing actual code, so the logic of the algorithm takes the focus instead of language or system specific implementation details. We should analyze the problem first, then write the algorithm solution in pseudocode, then code. Up next was groundwork on some key problem types and data structures. Problem types covered were sorting, searching, and graphs. We then reviewed graph definitions and representations, and trees as a special type of graphs. Most of this was review from intro to algorithms. The analysis framework picks a basic operation, usually in t...