EI-331 - Design and Analysis of Algorithms - String Matching
EI-331 - Design and Analysis of Algorithms - String Matching
a b a c a a b a c c a b a c a b a a b b
1 2 3 4 5 6
a b a c a b
7
a b a c a b
8 9 10 11 12
a b a c a b
13
j 0 1 2 3 4 5 a b a c a b
P[j] a b a c a b 14 15 16 17 18 19
F(j) 0 0 1 0 1 2 a b a c a b
EI-331 Design & Analysis of
Algorithms
String Matching
Knuth-Morris-Pratt (KMP) Algorithm
Preprocess the pattern to compute the failure function.
Use the failure function to guide the search in the text.
Achieves linear time complexity.
EI-331 Design & Analysis of
Algorithms
Data Structure Revision
EI-331 Design & Analysis of
Algorithms
Graphs
A graph is a data structure composed of nodes (vertices) and edges
that connect pairs of nodes.
Nodes represent entities, and edges represent relationships between
these entities.
Graphs are versatile and widely used in various fields, including
computer science, social networks, transportation systems, and more.
EI-331 Design & Analysis of
Algorithms
The basic properties of a graph include:
Graphs
Vertices (nodes): The points where edges meet in a graph are known as vertices or nodes. A
vertex can represent a physical object, concept, or abstract entity.
Edges: The connections between vertices are known as edges. They can be undirected
(bidirectional) or directed (unidirectional).
Weight: A weight can be assigned to an edge, representing the cost or distance between two
vertices. A weighted graph is a graph where the edges have weights.
Degree: The degree of a vertex is the number of edges that connect to it. In a directed graph,
the in-degree of a vertex is the number of edges that point to it, and the out-degree is the
number of edges that start from it.
Path: A path is a sequence of vertices that are connected by edges. A simple path does not
contain any repeated vertices or edges.
Cycle: A cycle is a path that starts and ends at the same vertex. A simple cycle does not
contain any repeated vertices or edges.
Connectedness: A graph is said to be connected if there is a path between any two vertices. A
disconnected graph is a graph that is not connected.
EI-331 Design & Analysis of
Algorithms
Graphs
EI-331 Design & Analysis of
Algorithms
Graphs
EI-331 Design & Analysis of
Algorithms
Graphs Representation
EI-331 Design & Analysis of
Algorithms
Graphs Representation
EI-331 Design & Analysis of
Algorithms
Tree vs Graphs
EI-331 Design & Analysis of
Algorithms
Graphs Search
EI-331 Design & Analysis of
Algorithms
Graphs Search