Coding Paradise. Learn. Ask. Code. REPEAT.

Showing posts with label Search-Sort. Show all posts
Showing posts with label Search-Sort. Show all posts

Monday, 24 August 2015

Selection sort using C language

PROBLEM STATEMENT

SELECTION SORT


Write a C program to perform selection sort on an array of n elements.
Selection sort algorithm starts by comparing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:

Print result after every Iteration.

Sunday, 23 August 2015

Implementation of Binary Search in C

PROBLEM STATEMENT

Write a C program to implement Binary Search Algorithm.
Include a function
int BinarySearch (int, int, int *, int x) --- The 1st parameter is the lower limit of the list or array, the 2nd parameter is the upper limit of the list or array, the third parameter is a pointer to the array and the fourth parameter is the search element.
Please note that the index of the search element is returned by the function. If the search element is not present in the array, -1 is returned.
Assume that the maximum size of the array is 10 . Please note that if a is the array, then a[0] is in position 0, a[1] is in position 1 ...

Saturday, 22 August 2015

Searching element in an array : C


PROBLEM STATEMENT

Searching an Array
Write a C program to search for an element ‘a’ in the array. (Linear Search)
Input Format:
Input consists of n+2 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the array. The last integer corresponds to ‘a’, the element to be searched.
Assume that the maximum size of the array is 20.
Output Format:
Refer  sample output for details.

Popular Posts

Powered by Blogger.