Finding min and max using binary recursion.

Discussion in 'Mac Programming' started by 103734, Nov 26, 2010.

  1. Guest

    Joined:
    Apr 10, 2007
    #1
    I need to find the min and max number in a integer array using binary recursion. I'm familiar with binary search, and recursion, but not binary recursion. I'm not sure if its just been a long day and i'm brain dead or what but I'm drawing a blank here; just need a very simple break down of what this means to jump start my brain. When I mean simple, I really mean it, don't need anything in depth.
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    Split array into two halves. Call self with lower half. Call self with upper half. Return min or max of two halves. Recursion stops when a half-array is a single element.
     
  3. thread starter Guest

    Joined:
    Apr 10, 2007
    #3
    Thanks!:D Thats all I needed
     
  4. macrumors 6502a

    Joined:
    Dec 2, 2008
    #4
    Recursion stops . . .

    Just to clarify, the above sentence means that your first action should be to test the length of the array. If it's one, then you're done. If not, go ahead and do the splitting thing.
     
  5. macrumors regular

    Joined:
    Mar 5, 2004
    #5
    Unless this is strictly an academic exercise, that seems like a silly way to search for min/max. Why not a simple linear search? The time complexity would be the same, and the constant factor would be smaller as well. Simpler to code and to read too.
     
  6. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    Maybe there's a billion elements and you are writing in a language or with a compiler that can parallelize this for you?

    But really, because that's what the homework said to do.

    -Lee
     
  7. macrumors regular

    Joined:
    Mar 5, 2004
    #7
    A compiler capable of parallelizing a recursive algorithm would likely be able to parallelize a simple loop as well. So... same deal.

    I suspect that was the real reason but nobody had mentioned it.
     
  8. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #8
    I loled at this!
     
  9. thread starter Guest

    Joined:
    Apr 10, 2007
    #9
    correct!

    wrote the code last night, works perfectly. Thanks.
     

Share This Page