1 / 4

Analysis of Algorithms

Analysis of Algorithms. Linear Search. int linear_search(int array[], int size, int key) { int i ; for ( i = 0; i < size; i ++) { if ( array[i ] == key ) return i ; } return -1 ; }. Binary Search. int binary_search(int array[], int size, int key) {

abia
Télécharger la présentation

Analysis of Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Analysis of Algorithms

  2. Linear Search intlinear_search(int array[], int size, int key) { inti; for (i = 0; i < size; i++) { if (array[i] == key) return i; } return -1; }

  3. Binary Search intbinary_search(int array[], int size, int key) { int mid, hi, low; low = 0; hi = size-1; mid = (low + hi) / 2; while (low <= hi) { if (array[mid] == key) return mid; else if (array[mid] < key) { low = mid + 1; mid = (low + hi) / 2; } else { hi = mid – 1; mid = (low + hi) / 2; } } return -1; }

  4. Selection Sort void selection_sort(int array[], int size) { inti, j, min, temp; for (i = 0; i < size-1; i++) { min = i; for (j = i+1; j < size; j++) { if (array[j] < array[min]) { min = j; } } if (i != min) { temp = array[i]; array[i] = array[min]; array[min] = temp; } } }

More Related