String Matching (Chapter 32)
Text T with N characters Pattern P with M characters The problem: decide whether T has a substring equal to P. Example
kdja;dlkjkaljdfkdjaie4nvoienflkajoienlcjoehahlek kdlajfiekhhieenflodioieatingkajkedfoehaoioenngh kdjk
Implementing Kruskal's algorithm
How to determine whether adding an edge will cause a cycle? Observation: During the execution of the algorithm, the set of edges in the solution (red edges) forms a set of disjoint trees.
4
b
11
8
2 7
c
4
7
d
14
Another application of DFS: Strongly connected components (Ch22.5)
Consider any directed graph G. For any two vertices a, b, let u v denote the fact that there is a directed path from u to v. Let u, v be any two vertices of G. We say u, v are strong
Graph algorithms (Ch.22) Graphs: Set of OBJECTS with pairwise CONNECTIONS Design and analysis of graph algorithms is a challenging branch of computer science. There are hundreds of graph algorithms known, and thousands of practical applications.
Vert
Dynamic Programming
An efficient way to implement some
divide-and-conquer algorithms
CS0250, Set 4
Problem with divide-and-conquer
Usually, a direct implementation of a divide-and-conquer
algorithm is very inefficient.
Example: Computing the Fibonacci nu
Divide and Conquer Divide
Given some problem, divide it into a number of similar, but smaller sub-problems. Solve each of these problems recursively.
Conquer (or Combine)
Combine the solutions of each of these sub-problems into a solution of the ori
Overview of some basic algorithms design techniques
1. Greedy heuristics 2. Divide and Conquer 3. Dynamic programming
CS0250, Set 2
Greedy heuristics How to be greedy?
At every step, make the best move you can make. Keep going until you're done.
What is an algorithm? An algorithm is a sequence of precise and concise instructions that guide you (or a computer) to solve some specific problem. Examples: cooking recipe, VCR trouble shooting instructions, furniture assembly directions.
Note: Un
Linear Programming
A general way for solving problem
What is a linear program (LP)?
maximize 5 x1 4 x2 3x3 subject to 2 x1 3x2 4 x1 x2 3x1 4 x2 x3 2 x3 5
or equivalently
minimize - 5 x1 4 x2 3x3 subject to - 2 x1 3x2 x3 5 11 8 0. - 4 x1 x2 2 x3 - 3
Overview of NP-completeness
Definition: A polynomial time algorithm is an algorithm whose running time is no more than a polynomial on the input size. We agree that
An algorithm is an efficient algorithm if and only if it is a polynomial time algori
Approximation algorithms (Ch.35)
Polynomial-time algorithms that always return "near-optimal" solutions
An example
The vertex-cover (VC) problem
A vertex cover of an undirected graph G=(V, E ) is a subset V ' V such that for every edge (u,v ) of G,