You are on page 1of 20

SEARCHING ALGORITHMS:

The Broad Picture


 Introduction
 Classes
 Some important algos explained
 Bibliogaphy
Introduction

 Searching Algorithm – procedure written for


finding an item with specified properties
among a collection of items.

 Items maybe stored in database as records or as


math formulae or procedures or graphical
entities.
Classification
 For virtual search spaces :

 Used in constraint satisfaction problem and


Max-Min problem –Linear Search, Brute Force
Search, Binary Search, etc.

 Used in local search methods where elements


of a graph include search space – Simulated
Annealing, Tabu Search, Genetic
Programming, etc.
 Used in Tree Search algorithms where
vertices of tree are elements of search space
and traversing is done in some special order
(breadth-first ,depth-first) – Backtracking and
Branch and Bound algo.
 For sub-structures of a given structure:

 Used in Combinatorial Search – algos that look for


specific sub-structure of a given discrete structure
such as a graph, a string or finite group – Brent’s
algo , Gale – Shapley algo , etc.
 Used in Graph algorithms for finding specific sub-
structure in a given graph- sub graphs, circuits, paths,
etc. – Djikshtra’s algo, Kruskal’s algo, Prim’s algo, etc.

 Used in String Searching algorithms that search for


patterns within strings –

Boyer-Moore algo, Knuth-Morris-Pratt algo, Brute


Force algo, Karp-Rabin algo, Deterministic Finite
Automaton algo, etc.
 For quantum computers :

 Used for designing quantum computers –


theoretically faster than linear or brute-force
search – Grover’s algorithm.
Some Algos Briefed
Simulated Annealing: It has analogy with annealing in
metallurgy, where materials are heated and cooled to
increase size of its crystals and reduce its effects.

 Following analogy, each step of SA algo replaces


current solution by a random ‘nearby’ solution.
 ‘Nearby’ solution is chosen according to diff. b/w
corresponding function values and global parameter
T.

 Dependency is such that current solution changes


almost randomly when T is large, but goes downhill
as T goes to zero.
Pseudocode
s ← s0; e ← E(s)
sbest ← s; ebest ← e
k←0
while k < kmax and e < emax
snew ← neighbour(s)
enew ← E(snew)
if P(e, enew, temp(k/kmax)) > random() then
s ← snew; e ← enew
if enew > ebest then
sbest ← snew; ebest ← enew
k←k+1
return sbest
Branch and Bound : B&B is a general algorithm for
finding optimal solutions of
various optimization problems.

 Goal is to find the minimum value of a function f(x),


where x ranges over some
set S of admissible or candidate solutions or search
space. 
 It includes two steps: Firstly a splitting procedure that
in a given set S returns two or more smaller sets. Its
called branching.

 Secondly, it computes upper and lower bounds for the


minimum value of f(x) within a given subset S. Its
called bounding.
 Three main components of B&B algo:

1. Bounding function : provides lower bound for the best


solution value obtainable in the subspace,

2. Strategy : for selecting the live solution subspace to be


investigated in the current iteration, and

3. Branching rule : to be applied for subdividing the


subspace considered into two or more subspaces to be
investigated in subsequent iterations.
Knuth-Morris-Pratt Algo :

 searches for occurrences of a "word" W within a main


"text string" S by employing the observation that
when a mismatch occurs, the word itself embodies
sufficient information to determine where the next
match could begin, thus bypassing re-examination of
previously matched characters.
 Consider an attempt at a left position j, that is when
the window is positioned on the text factor y[j .. j+m-
1]. Assume that the first mismatch occurs between x[i]
and y[i+j] with 0 < i < m. Then, x[0 .. i-1] = y[j .. i+j-
1] =u and a = x[i]  y[i+j]=b.
When shifting, it is reasonable to expect that a
prefix v of the pattern matches some suffix of the
portion u of the text.

If we want to avoid another immediate mismatch, the


character following the prefix v in the pattern must be
different from a. The longest such prefix v is called
the tagged border of u.
 Now let kmpNext[i] be the length of the longest
border of x[0 .. i-1] followed by a character c different
from x[i] and -1 if no such tagged border exits, for 0
< i  m.

 Then, after a shift, the comparisons can resume


between characters x[kmpNext[i]] and y[i+j] without
missing any occurrence of x in y, and avoiding a
backtrack on the text. The value of kmpNext[0] is set
to -1.
 The table kmpNext can be computed in O(m)

 The searching phase can be performed in O(m+n)


time.

 Algo performs at most 2n-1 text character


comparisons during the searching phase. 
BIBLIOGRAPHY:

 KNUTH D.E., MORRIS (Jr) J.H., PRATT V.R.,
1977, Fast pattern matching in strings, SIAM Journal
on Computing
 CORMEN, T.H., LEISERSON, C.E., RIVEST, R.L.,
1990. Introduction to Algorithms

 http://www-igm.univ-mlv.fr/~lecroq/string/

 www.wikipedia.org

You might also like