Searching

# Searching - CIS3023: Programming Fundamentals for CIS...

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

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! ”

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

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

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/27/2011 for the course CIS 3023 taught by Professor Dobbins during the Summer '08 term at University of Florida.

### Page1 / 13

Searching - CIS3023: Programming Fundamentals for CIS...

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

View Full Document
Ask a homework question - tutors are online