0% found this document useful (0 votes)
10 views13 pages

02.introduction Linear+Binar Search

The document provides an overview of algorithm design and analysis, defining algorithms as finite sets of instructions that transform inputs into outputs. It outlines the properties of good algorithms, types of algorithms, and their applications in various fields such as bioinformatics and electronic commerce. Additionally, it compares the efficiency of searching algorithms, specifically sequential and binary search, highlighting their complexities and performance differences.

Uploaded by

siam.rehman447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

02.introduction Linear+Binar Search

The document provides an overview of algorithm design and analysis, defining algorithms as finite sets of instructions that transform inputs into outputs. It outlines the properties of good algorithms, types of algorithms, and their applications in various fields such as bioinformatics and electronic commerce. Additionally, it compares the efficiency of searching algorithms, specifically sequential and binary search, highlighting their complexities and performance differences.

Uploaded by

siam.rehman447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ICT-307

Algorithm Design and


Analysis

Md. Rakib Hasan


Lecturer
Department of ICT
Comilla University

1
Definition

 a finite set of instructions to perform specific


tasks.

 well-defined computational procedure that


takes some value, or set of values, as input and
produces some value, or set of values, as output.

 sequence of computational steps that


transforms the input into the output.

 tool for solving a well-specified computational


problem
Criteria(Properties of good
Algo.)
1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness
General Concept
Algorithm strategy
◦ Approach to solving a problem
◦ May combine several approaches
Algorithm structure
◦ Iterative  execute action in loop
◦ Recursive  reapply action to
subproblem(s)
Problem type
◦ Satisfying  find any satisfactory solution
◦ Optimization  find best solutions (vs.
cost metric)
Problems solved by algorithms

Human Genome
Project(Bioinformatics)
Internet – Information
management/ route
selection/search engines
Electronic Commerce –
Public/Private Key Cryptography
Resource allocation- Air flight route
selection, Inventory system etc.
and a lot more.
Why Efficient
Algorithm?
 Time to sort n items:

Insertion Sort: C1n2


Merger Sort: C2nlgn [lgn = log2n]

Suppose,
Computer A = 10 Billion Instruction/second
1010]
[

Computer B = 10 Million Instruction/second [


107]

A is 1000 times faster than B

C1 < C2 ; C1 =2
;
C2 = 50
 To sort 10 million items

A takes:
2 X (107) 2 instructions
1010 instructions/Second

=
20,000 sec (more than 5.5 hours)

B takes:
50 X 107 X lg(107) instructions
107 instructions/Second

=
1163 sec (less than 20 min)

Computer B runs more than 17 times faster than computer A!

So, with an efficient algorithm we can solve a problem within a very short time,
even with a slow compiler.
Searching Algorithm

1. Sequential or linear Search

2. Binary Search
1. Sequential Search
Let,
Sequential list (array): X1,X2,…..,Xn
*
X 2 66 11 23 24 88 64 77 108 290

Search object: Z = 24

Algorithm:
i 1
while i < n & Z != X[i] do
i i+1
if i < n then
FOUND
else
NOT FOUND
2. Binary Search
l 1 [start position]
h n [no. of elements]
flag = false
while l < h and not flag do
l+h
mid
2
Xm X[mid]
case
Xm < Z : l mid + 1
Xm > Z : h mid - 1
Xm = Z : flag true

if flag = = true
FOUND
else
NOT FOUND
Complexity
Sequential Search:
 Worst Case Complexity: O(n)
 Best Case Complexity: O(1)
 Average Case Complexity: (n+1)/2
== O(n)

Binary Search
running time of binary search
could be written as O(log n)
Question
Ifwe have an array of length
70000000 but sorted, which
searching algorithm will work
fast and why??

Search item 75 using binary


search algorithm from the
following list.
A= [22, 3, 127, 515, 163, 69, 75,
88, 96, 10]
Thank you

You might also like