| 04-09-2008, 05:25 PM | #1 |
Hello guys, sorry in advance if what I'm asking here is irrelevant for this section. Also thanks for any help. I was reading about binary search on wikipedia just now and I couldn't figure out the math equation to get how many loops it would take to find a value, for example; In an array of 20 elements, how many comparisons would a binary search require to find a given value. The only way I could think of is to continually divide 20 to 2 which would be: 20/2 = 10; 10/2=5; 5/2 = 2; 2/2 =1; So it would be 4 comparisons. In short what I'm asking is if there is an equation which I could use to get how many comparisons I would need without using multiple equations of N/2=k. Thanks. |
| 04-09-2008, 05:27 PM | #2 |
you people should at least learn about what a logarithm is before trying to learn divide and conquer algorithms. PS: I answered your question in the last paragraph. |
| 04-09-2008, 05:34 PM | #3 |
Ok thanks for the tip vex, I hope I understand it lol. Thanks again. |
