Thread: How to do Binary search in 2Dimensional array

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    How to do Binary search in 2Dimensional array

    Hi all,

    how to search a element (value) in 2dimensional integer array using binary search...
    Kindly suggest the solution..

    Thanks,
    sureshcools

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    The solution is to make an effort on your own...

    This forum has a "homework policy"... we don't do your homework for you.
    Even if this isn't homework nobody here is going to give you free code.

    Write the thing as far as you can, then post the parts of the code giving you trouble along with specific questions.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Is the array at least sorted in some manner? If not that's a clue.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    First, hint given by hk_mp5kpdw.
    Second, make a logic over the input number.
    Third, move to that direction in array.
    Fourth, loop from second to third again and again, until you find.
    Finally, if found return or do whatever you want to else hopefully not found there.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    In general there isn't a specific way to apply binary search to anything two dimensional, and depending on the specific circumstance, it may or may not be possible at all.

    We'd need to know a lot more about the problem to work out 'if' and 'how' it may be possible to utilise binary search in your circumstance.

    I guess one question back to you for a start with would be; how would you first sort this two dimensional data?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linear search for structure (record) array
    By jereland in forum C Programming
    Replies: 3
    Last Post: 04-21-2004, 07:31 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. Binary Search in C help
    By kce9751 in forum C Programming
    Replies: 2
    Last Post: 06-17-2003, 08:17 AM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM