Searching - Searching Page 1 of 3 SEARCHING Contents...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
S EARCHING Contents z Introduction z Searching in an Array z The Comparable Interface Introduction Searching is a very common problem, both in life and in computer applications. It is so important that many data structures and algorithms have been designed specifically to make searching as easy and efficient as possible. In this set of notes we will review the three techniques that we discussed the first day of class for searching for a value in an array. Other sets of notes will present several different data structures designed to support efficient searches. Searching in an Array Recall that there are two basic approaches to searching for a given value v in an array: sequential search and binary search . Sequential search involves looking at each value in turn (i.e., start with the value in array[0], then array[1], etc). The algorithm quits and returns true if the current value is v; it quits and returns false if it has looked at all of the values in the array without finding v. If the values are in sorted order, then the algorithm can sometimes quit and return false without having to look at all of the values in the array; in particular, if the current value is greater than v then there is no point in looking at the rest of the values in the array (v is definitely not there). The worst-case time for a sequential search in an array of size N is always O(N), even when the array is sorted (though the average-case time should be better for a sorted array than for a non-sorted
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2008 for the course CS 367 taught by Professor Marvinsolomon during the Spring '08 term at University of Wisconsin.

Page1 / 3

Searching - Searching Page 1 of 3 SEARCHING Contents...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online