CST370 Design and Analysis of ALgorthms Week 3
For week 3 of CST370 Design and Analysis of Algorithms we learn about Brute force string matching and exhaustive search. With the string matching problem, we basically try to match the characters in a text and find a substring of the text that matches the pattern. Brute-Force matching basic idea is to compare the characters by character. If a mismatch occurs shift a character and restart the comparison. The best case for this is when immediate match occurs, a minimum number of comparisons will occur. It is often easy to think about the best case scenario but worst case is not. A worst case scenario may not be too obvious since it may require more comparisons.
Exhaustive search is a brute force approach to solve combinatorial problems. The basic idea of this are to generate all potential solutions to the problem. Evaluate each case one by one and determine the solution among the possible cases. For example Traveling Salesman Problem (TSP) is to find the shortest tour through a given set of n cities that visits each city exactly once before returning to the city where it started. To solve this kind of problem one must fine all permutations of each city(nodes) and find the distance travel. One must then sum up all the travel distance between nodes. The efficiency depends on the number of permutations. If there are n nodes in the question we should identify all possible paths of the (n-1) node, except the starting node. The time efficiency of the problem requires at least (n-1)!.
This week we also learn about Depth-First Search algorithm(DFS) and Breadth-First Search(BFS) Algorithm. Graph traversal has many graph problems require processing all vertices and edges of a graph in a systematic way. These two algorithms are popular graph traversal algorithms. For example DFS uses stack for its operation when trying to traverse a graph. Applications of DFS are checking connectivity, checking acyclicity of a graph and finding connected components. BFS on the other hand uses queue for its operation when traversing graphs. The application of BFS is the same as it is in DFS.Checking connectivity, checking acyclicty of a graph and finding connectivity components. We can also find paths from vertex to all other vertices with the smallest number of edges.
Lastly for this week we alearn about divide and conquer problem solving techniques. A problem is divided into several subproblems. Typically, it is divided into two subproblems. Subproblems are solved recursively. If its necessary the subproblems solutions are combine to get the solution of the original problem. The time efficiency of divide and conquer is base on apply master theorem. Case 1 is if a < b^d, then O(n^d). Case 2is if a = b^d then O(n^d * logn). And lastly Case 3 if a > b^d then O(nlogb^a).
Comments
Post a Comment