BINARY SEARCH

  1. First and foremost step is to check weather the array is sorted or not. If sorted then proceed, if not then apply sorting method to sort it first and then proceed with further mentioned steps.(bubble sort)

  2. Take the element to be searched for in a variable x

  3. Set two pointers low and high at the lowest and highest positions respectively.

  4. Find the middle element “mid” of the array by the formula → mid = high + low / 2

  5. If x==mid, then return the mid as the output.

  6. If x > mid, compare x with the middle element to the element on the right side of the mid element. This is done by setting low = mid + 1

  7. Else, compare x with the middle element of the left side of the mid. This is done by

    high = mid - 1

  8. Repeat the steps 3 - 6 until low and high are equal (low == high)

  9. write “x is found”

  10. Exit

LINEAR SEARCH

  1. Take the input of the element to be searched in x let’s say
  2. starting from first element, compare x with each of the elements in the array one by one
  3. if x==index, return the Index
  4. Else, write “NOT FOUND”

TRANSPOSE OF MATRIX

  1. Declare and initialize a 2-D array p[a][b] of order axb.
  2. Read the matrix p[a][b] from the user and store in a memory location.