Algorithms: DR M Kaykobad Professor CSE Department, BUET
Algorithms: DR M Kaykobad Professor CSE Department, BUET
Algorithms: DR M Kaykobad Professor CSE Department, BUET
Dr M Kaykobad
Professor
CSE Department, BUET
Searching
• Most frequent operations in a computer.
Knuth(Sorting and Searching) says over 25% of
computer time in 60’s was used in searching.
• Generally we search for solutions/answers in
databases or in computation intensive problems.
• Our shops are arranged to minimize searching
time, as is the chess board or household goods,
admission test results or even dictionaries.
Sequential Search
When objects are placed in a list sequentially we cannot do
better than searching it sequentially.
Sequential_search(A, n, z, index)
i=1, index=-1
While i <= n and A(i) ≠ z do
i++
enddo
If i <=n then
index=i
endif
Sequential Search
• Sequential_search1(A,n,z,index)
A(n+1)=z, i=1, index=-1
while A(i) ≠ z do
i++
enddo
If i ≤ n then
index=i
endif
Sequential search complexity
Best case Worst case Average case