Slides - Search

Slides - Search - Searching sequential search binary search...

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

View Full Document Right Arrow Icon
1 Searching ¾ sequential search ¾ binary search Algorithm seqSearch (list, last, traget, locn) // Locate the target in an unordered list of elements. set looker to 0 loop (looker < last AND target not equal list[looker]) increment looker end loop set locn to looker if (target equal list[looker]) set found to true else set found to false end if return found
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Algorithm binarySearch (list, last, target, locn) // Search an ordered list using Binary Search set begin to 0 set end to last loop (begin <= end) set mid to (begin + end) / 2 if (target > list[mid]) set begin to (mid + 1) else if (target < list[mid]) set end to (mid – 1) else set begin to (end + 1) end if end loop set locn to mid if (target equal list[mid]) set found to true else set found to false return found
Background image of page 2
3 C implementation /* Locate target in an unordered list of elements. input parameters: . . . . output parameter(s): . . . . */
Background image of page 3

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

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

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 8

Slides - Search - Searching sequential search binary search...

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

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