dyba/katas-samples — Issue #1: Kata 2 recursive can be much more efficient
Author: josem
Created: 2011-12-10 16:52:33+00:00
State: open

Why do you try first with the bottom half first and after that with the other?

There is a way much more efficient to do this and actually the whole point of this algorithm. I think you should compare first the integer with the value in the middle of the array, since you know that is already sorted. Something like this:

```ruby
if int < array_of_int[mid]
pos = chop(int, array_of_int[0...mid])
return pos if pos != -1
else
pos = chop(int, array_of_int[mid..-1])
return pos + mid if pos != -1
end
```

Instead of:

```ruby
pos = chop(int, array_of_int[0...mid])
return pos if pos != -1

pos = chop(int, array_of_int[mid..-1])
return pos + mid if pos != -1
```

Regards!