L24post

L24post - Previous Lecture Acoustic data frequency...

This preview shows pages 1–9. Sign up to view the full content.

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 3-5pm

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
% 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. % 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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
November 19, 2009 Lecture 24 8 % Linear Search % f is index of first occurrence % of value x in vector v.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern