Searching Algorithms - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Searching Algorithms

Description:

Searching Algorithms. Binary Search. first. last. mid. k = T' A. B. D. E. G. H. K. L. M. N. P. Q. R ... Binary Search Example. 7 12 42 59 71 86 104 212. 89 not ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 8
Provided by: depts169
Category:

less

Transcript and Presenter's Notes

Title: Searching Algorithms


1
Searching Algorithms
  • Binary Search

2
k T
A
B
D
E
G
H
K
L
M
N
P
Q
R
T
U
V
W
X
Y
Z
first
last
mid
A
B
D
E
G
H
K
L
M
N
P
Q
R
T
U
V
W
X
Y
Z
first
last
mid
A
B
D
E
G
H
K
L
M
N
P
Q
R
T
U
V
W
X
Y
Z
first
last
mid
A
B
D
E
G
H
K
L
M
N
P
Q
R
T
U
V
W
X
Y
Z
first
last
mid
A
B
D
E
G
H
K
L
M
N
P
Q
R
T
U
V
W
X
Y
Z
first
mid
last
3
Binary Search ? Analysis
  • If key is found at the middle of the array, it is
    returned immediately after only one comparison
  • Best case ?T(n) 1 O(1)
  • Otherwise, search is performed on half the array
  • Worst case, average case ?T(n) O (log n)

4
Binary Search Example
Looking for 89
5
Binary Search Example
Looking for 89
6
Binary Search Example
Looking for 89
7
Binary Search Example
89 not found 3 comparisons 3 Log(8)
Write a Comment
User Comments (0)
About PowerShow.com