Searching and Sorting Algorithm

Searching and Sorting Algorithm

Searching Technique is done in Sequential Manner.

Sequential Search (A, i, x, n)

  1. Set i =0

  2. if>n

    print element not found.

  3. if A[i]=x

    print Element Found.

  4. i=i+1

  5. Exit

It is Fast Searching Algorithm with Time Complexity 0(log n).

Based on Divide and conquer.

Data Items should be in sorted manner.

Algorithm

  1. while(low<=high)

    mid = (low + high)/2

  2. If X= A[mid]

    return mid

  3. If X>A[mid]

    low=mid+1

    else high =mid-1

  4. Exit

Bubble Sort:

In bubble sort technique each pair of adjacent is Compared and Elements are swapped if they are not in order.

Worst Case time Complexity =0(n^2)

Algorithm

  1. for( jb + k sort ho jaye )

  2. if(list[i]>list[i+1]

  3. Swap(list[i],list[i+1])

    end if

    end for

  4. Exit

Selection Sort:

In this sorting technique the list is divided into 2 parts

Worst Case Time complexity 0(n^2)

Algorithm

  1. Set min =0

  2. Search Minimum Elements in the list.

  3. Swap with value at location min.

  4. Increase min to point to next element.

  5. Repeat Until List is Sorted.

Important Point: 2 ways Selection Sort:

A. Sorted Path

B. Unsorted Path