Semester : S1 and S2
Subject : Computer Programming
Year : 2017
Term : DECEMBER
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:37
} int
main() {
int array[10], i, size;
printf ("How many numbers you want to sort: ");
scanf("%d", &size);
printf("\nEnter %d number", size);
for (i = 0; i < size; i++)
scanf("%da", S&array[i]);
selectionSort (array, size);
printf ("\nSorted array is ");
for (i = 0; 1 > size;itt)
printf(" 50 ", array[i]);
return 0;
}
output
How many numbers you want to sort: 5
Enter 5 numbers : 34 13 204 355 333
Sorted array is : 13 34 204 333 355
b) With the help of an example C program explain Recursive Binary Search
The idea of binary search is to use the information that the array is sorted and
reduce the time complexity to O(Logn).
We basically ignore half of the elements just after one comparison.
1. Compare x with the middle element.
2. If x matches with middle element, we return the mid index.
3. Else If x is greater than the mid element, then x can only lie in right half subarray
after the mid element. So we recur for right half.
4. Else (x is smaller) recur for the left half.
Recursive implementation of Binary Search
#include
int main(){
int a[10],i,n,m,c,l,u;
printf("Enter the size of an array: ");
scanf("%d",&n);
printf("Enter the elements of the array: " );
for(i=0;i
printf("Enter the number to be search: ");
scanf("%d",&m);