hello everyone i'm trying to create algoithm for binary search in multi dimensinal array
i have done it on one dimensinal and changed some things but still there is something wrong

here's the code i hope you can help

 public static void binarysearch(int [][] numbers,int searchedvalue)
    {
       int lowrow = 0;
       int lowcolumn = 0;
       int highcolumn = numbers.length;
       int highrow = numbers.length;
       int result;
       int midrow = 0 ,midcolumn = 0;
       while (lowrow < highrow)
       {
           midrow = lowrow + highrow / 2;
           midcolumn = lowcolumn + highcolumn / 2;

           if(numbers[midrow][midcolumn] == searchedvalue)
           {
                result = 1;
                if (result == 1)
                  {
                    System.out.println(searchedvalue + " has been found in index " + midrow + midcolumn);    
                  }
           }

           else if (numbers[midrow][midcolumn] < searchedvalue)
           {
                   lowrow = midrow + 1;       

                   lowcolumn = midcolumn + 1;

           }

           else
           {
              highrow = midrow;
              highcolumn = midcolumn;
           }
       }

        result = 0;



       if (result == 0)
       {
           System.out.println(searchedvalue + " has not been found in the array");
       }

wInline Code Example Here

define : "something's wrong".
is an exception thrown, does it run just not find the element, ..

"changed some things" isn't going to get you a good result. The code you posted is nowhere near right. Before you start any coding you need to be very clear what is the algorithm you are trying to code. Coding without knowing what you are coding is a bad idea. Could you explain how a binary search works on a 2d array to a colleague? If not, then you can't code it either!
Binary search assumes the values in the array are in ascending order. What assumption(s) are you making about the order of the values in your 2d array?

well yeah the program runs but i think it skips some elemnts sometimes it finds it and sometimes it doesn't

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.