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 search. With BFS it finds a node in the minimum number of steps from the starting node, so it can easily tell us that a node is connected and how far it is from the start. DFS is more useful for telling us if a vertex is reachable but not how far it is from the starting node.
The weeks lectures ended with an intro to divide and conquer algorithms. First, split the problem into subproblems, then solve the subproblems recursively, and finally combine the sub-solutions to get the solution to the full original problem. An example given was to calculate the sum of numbers in an array by recursively adding smaller and smaller sub-arrays and adding the results of the recursion together. We use the Master Theorem to understand the time efficiency of divide and conquer algorithms.
Master Theorem:
use three parameters a,b,c:
a: number of recursive calls
b: factor by which the input size is reduced
d: exponent in Θ(nd) which is the time needed to divide the problem or combine solutions
Then, get the parameters from the problem, compute bd, then check these cases:
Case 1: if a < bd, then Θ(nd)
Case 2: if a = bd, then Θ(nd · log n)
Case 3: if a > bd, then Θ(nlogba)
Comments
Post a Comment