Find a Fixed Point in a given array

Fixed point in a array means A[i] = i Example : Input: arr[] = {1, Air Max Baratas 8,

  • ROSHE ONE
  • 2, Todd Gurley College Jerseys 9, adidas nmd r1 uomo 17} Output: 2 // arr[2] == 2 Algorithm : Using linear search Code :

    int findFixedpoint(int arr[],  <a href="http://www.redskinsnewarrive.com/players/kirk-cousins-redskins-jerseys.html">Kirk Cousins Redskins Jerseys</a> int n) { int i; for(i = 0; i &lt; n; i++) { if(arr[i] == i) return i; } return -1; //If no fixed point }

    Note : you can use binary search if array is sorted ,

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    For Inserting code :
    Paste your code in the comment form, select it and then click the language link

    C | C++ | Java |

    *