CST370 Week 3

  This was our third week in CST 370 - Design and Analysis of Algorithms.

 Brute Force String Matching

The first algorithm we looked at this week was Brute Force String Matching. In this algorithm we loop through each character of a string. Then for each character we loop again, starting at that character, until we find the pattern we are looking for (in which case we return true) or find a character that does not match the pattern (in which case go back to the first loop.

Exhaustive Search

The class lecture defines Exhaustive Search (ES) as a Brute-Force approach to solve combinatorial problems. The basic concepts of Exhaustive Search are:

  • Generate all potential solutions (or all possible cases) to the problem.
  • Evaluate each case one by one.
  • Determine the solution among the possible cases.

Our class lecture discusses using ES to solve some different problems. 

Traveling Salesman Problem (TSP)

To solve this problem using ES we compute each permutation of the graph and their costs, then select the optimal permutations. Solving TSP in this way has a time efficiency of n!.

 

Knapsack Problem (KP)

To solve this problem using ES we calculate the weight and total value of all subsets of items. Solving KP in this way has a time efficiency of 2^n

 

Assignment Problem (AP)

To solve AP using ES we calculate the total hours of each possible permutation of the people in the matrix.

 

Depth-First Search (DFS)

From our textbook: "Depth-first search starts a graph’s traversal at an arbitrary vertex by marking it as visited. On each iteration, the algorithm proceeds to an unvisited vertex that is adjacent to the one it is currently in. This process continues until a dead end—a vertex with no adjacent unvisited vertices— is encountered. At a dead end, the algorithm backs up one edge to the vertex it came from and tries to continue visiting unvisited vertices from there. The algorithm eventually halts after backing up to the starting vertex, with the latter being a dead end."

 

Breadth-First Search (BFS)

From the textbook: "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 the vertices in the same connected component as the starting vertex are visited."

Divide and Conquer (DC)

Our class lecture defines DC as the following:

  • A problem is divided into several subproblems. Typically, it is divided into two subproblems.
  • Subproblems are solved (recursively until the size is small enough to solve right away).
  • If it's necessary, the subproblems' solutions are combined (or conquered) to get the solution of the original problem.

Master Theorem 

To calculate the time efficiency of a divide and conquer algorithm, we use a technique called Master Theorem. We have three items: b, a, and d.

  • b = Number of subproblems
  • a = Number of subproblems to be solved
  • d = the time to combine the original problem of size n.
  • We can use the following formula to get the items: T(n) = aT(n/b) + f(n)

Then we compare the different items:

  • If a < b^d, then Θ(n^d)
  • If a = b^d, then Θ(n^d * log n)
  • If a > b^d, then Θ(n^(logb a)

Comments

Popular posts from this blog

Week 11

Week 12

Week 19