Finding min and max using binary recursion.

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

  1. 103734 Guest

    Apr 10, 2007
    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. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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. 103734 thread starter Guest

    Apr 10, 2007
  4. PatrickCocoa macrumors 6502a

    Dec 2, 2008
    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. vocaro macrumors regular

    Mar 5, 2004
    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. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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.

  7. vocaro macrumors regular

    Mar 5, 2004
    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. chrono1081 macrumors 604


    Jan 26, 2008
    Isla Nublar
    I loled at this!
  9. 103734 thread starter Guest

    Apr 10, 2007

    wrote the code last night, works perfectly. Thanks.

Share This Page