This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: ¡ Previous Lecture: ¡ Acoustic data: frequency computation ¡ Touchtone phone ¡ Today’s Lecture: ¡ Search: Linear Search ¡ Sort: Bubble Sort and Insertion Sort ¡ Efficiency Analysis ¡ Announcements ¡ Project 6 due Monday Nov 23. StateNames.m revised W 3pm. ¡ Final exam Dec 14 (Mon) 7pm. Check for conflicts and email us ( [email protected] ) today . Specify your entire exam schedule including course numbers. ¡ Attendance in section next week is optional, but do the exercise! ¡ No office/consulting hour during Thanksgiving Break ¡ TA Chin I.’s Tues office hr moved to this Sunday 35pm November 19, 2009 Lecture 24 2 Searching for an item in a collection Is the collection organized? What is the organizing scheme? Indiana Jones and the Raiders of the Lost Ark November 19, 2009 Lecture 24 3 Searching for an item in an unorganized collection? ¡ May need to look through the whole collection to find the target item ¡ E.g., find value x in vector v ¡ Linear search v x November 19, 2009 Lecture 24 4 % 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; end if k>length(v) f= 1; % signal for x not found else f= k; end November 19, 2009 Lecture 24 5 % 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; end if k>length(v) f= 1; % signal for x not found else f= k; end 12 15 35 33 42 45 v x 31 November 19, 2009 Lecture 24 6 % 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; end if k>length(v) f= 1; % signal for x not found else f= k; end Suppose another vector is twice as long as v. The expected “effort” required to do a linear search is … A. squared C. the same B. doubled D. halved November 19, 2009 Lecture 24 7 % Linear Search % f is index of first occurrence % of value x in vector v....
View
Full
Document
This note was uploaded on 03/06/2010 for the course CS 9339 taught by Professor Gries during the Fall '09 term at Cornell.
 Fall '09
 GRIES

Click to edit the document details