





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The notes from a university lecture on searching algorithms, specifically linear search and bubble sort. The lecture covers the implementation of these algorithms, their efficiency analysis, and comparisons between them. The document also includes examples and exercises.
Typology: Study notes
1 / 37
This page cannot be seen from the preview
Don't miss anything!






























^ Acoustic data: frequency computation ^ Touchtone phone
^ Search: Linear Search ^ Sort: Bubble Sort and Insertion Sort ^ Efficiency Analysis
^ Prelim 3 will be returned after lecture. Or pick up fromCS1112 consultants in ACCEL during consulting hrs(today after 4pm)
April 16, 2009
Lecture 24
2
Indiana Jones and the Raiders of the Lost Ark
April 16, 2009
Lecture 24
% f is index of first occurrence%^
of value x in vector v. % f is -1 if x not found.k= 1;while
k<=length(v) && v(k)~=x k= k + 1; endif
k>length(v)f= -1; % signal for x not found else
f= k; end
April 16, 2009
Lecture 24
Linear Search % f is index of first occurrence%^
of value x in vector v. % f is -1 if x not found.k= 1;while
k<=length(v) && v(k)~=x k= k + 1; endif
k>length(v)f= -1; % signal for x not found else
f= k; end
April 16, 2009
Lecture 24
Linear Search % f is index of first occurrence%^
of value x in vector v. % f is -1 if x not found.k= 1;while
k<=length(v) && v(k)~=x k= k + 1; endif
k>length(v)f= -1; % signal for x not found else
f= k; end
April 16, 2009
Lecture 24
Linear Search % f is index of first occurrence%^
of value x in vector v. % f is -1 if x not found.k= 1;while
k<=length(v) && v(k)~=x k= k + 1; endif
k>length(v)f= -1; % signal for x not found else
f= k; end
What if
v^ is sorted?
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24
Compare adjacent values.Swap if “out of order.”
April 16, 2009
Lecture 24