Week 3 – CST370 – Design and Analysis of Algorithms

This week we learned about Brute Force String Matching and Exhaustive Search. We also learned about Depth-First search and Breadth-First search.

Brute Force String Matching is an algorithm used to match a pattern against a string. You align the pattern against the first m characters from left to right until either all the m pairs of the characters match or a mismatching pair is encountered. If a mismatch happens, you simply shift the pattern one character to the right and begin the process again.

Exhaustive search is a brute-force approach to combinatorial problems. Some of these problems include the traveling salesman problem, knapsack problem, and assignment problem. The traveling salesman problem is an algorithm that finds the shortest route through a given number of cities that visits all cities and ends up at the starting city. This problem is ideal when dealing with weighted graphs. The knapsack problem involves items of known weight and value and a knapsack with a limited capacity. The object is to figure out what items accumulate the greatest value within the capacity of the knapsack. Lastly, the assignment problem requires you to assign n number of people n number of jobs, one person per job. The problem is to find an assignment with the minimum total cost.

Depth-First search is an algorithm that can be applied to process all vertices and edges of a graph. It starts the traversal at an arbitrary vertex by marking it visited. On each iteration, the algorithm proceeds to an unvisited vertex that is adjacent to the one it is currently in. If there are several vertices, you can use alphabetical order to proceed to the next unvisited vertex. This continues until you reach a dead-end, where the algorithm backs up one vertex and continues visiting unvisited vertices. It is convenient to use a stack to trace the operation of depth-first search.

Breadth-First search is similar to depth-first but instead it proceeds in a concentric manner by visiting first all the vertices that are adjacent to a starting vertex, then all unvisited vertices two edges apart from it and so on until all vertices in the same connected component as the starting vertex are visited. For Breadth-First, it is convenient to use a queue to trace the operation.

 

Comments

Popular posts from this blog