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

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

View Full Document Right Arrow Icon
Today’s Agenda Searching Linear Search Binary Search More than one dimension Two Dimension n Dimension
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
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.
Background image of page 2
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
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
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 ????
Background image of page 4
Image of page 5
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 Right Arrow Icon
Ask a homework question - tutors are online