# Lec c6 - Todays Agenda Searching Linear Search Binary...

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

Today’s Agenda Searching Linear Search Binary Search More than one dimension Two Dimension n Dimension

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

View Full Document
There are very common problems that we use computers to solve: Searching through a lot of records for a specific record. Placing records in order, which we call sorting. There are numerous algorithms to perform searching and sorting.
Searching: Sequential / Linear Search Basic Algorithm Get the search criterion (Key). Get the first element. while ((element != Key) AND (still more elements)) Get the next element end of while loop Q. When do we know that there wasn’t a element

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

View Full Document
Sequential / Linear Search int main (void) { int arr[10], i, key; // Get the array elements printf (“Enter the Element to be searched”); scanf (“%d”,&key); for (i=0;i<10;i++) { if (arr[i] == key) { printf (“Key found at index %d”,i); break; } } // For Loop if (arr[i] != key) printf (“Key does not exist in the list”); } Q. Is the Code Correct ????
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

Lec c6 - Todays Agenda Searching Linear Search Binary...

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

View Full Document
Ask a homework question - tutors are online