Searching - CIS3023 Programming Fundamentals for CIS Majors...

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

View Full Document Right Arrow Icon
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never meant to know. For everything else, there’s Google! ”
Background image of page 1

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

View Full Document Right Arrow Icon
Searching Querying for something Searching an array for a particular value is a common problem Example: Where is 100 in this array? 101 50 2 89 100 55 -20 75 -10 10 A[0] A[1] A[n-1] n=10
Background image of page 2
Searching Querying for something Searching an array for a particular value is a common problem Example: Where is 100 in this array? 101 50 2 89 100 55 -20 75 -10 10 A[0] A[1] A[n-1] n=10 Must return location in the array (index=4)
Background image of page 3

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

View Full Document Right Arrow Icon
The Search Problem 1. Let A be the array to be searched n - the number of elements k - the search target (or key) 2. Question: Does k occur in A? If k appears in A[0], A[1], …, A[n-1]: “found” determine its index i . that is, find i such that A[i] == k Else “not found”: return -1
Background image of page 4
Linear Search // Performs linear search of array for key, from start index to end index. int linearSearch (int[ ] A, int key, int start, int end) {
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

Searching - CIS3023 Programming Fundamentals for CIS Majors...

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

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