Hi,
I was recently asked as to what is the logic behind Binary Logic..and I must say the question made no sense to me..maybe one of you can help me..Thanks..
Asp
Hi,
I was recently asked as to what is the logic behind Binary Logic..and I must say the question made no sense to me..maybe one of you can help me..Thanks..
Asp
The logic behind the search is that if you have an ordered collection of items, you can search for a given item by dividing that collection in half each time until you find what you are looking for.
"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
aspand, just do a google search for "binary search tree". You'll get loads of hits, some have interactive examples as well.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
A binary search returns the item being searched for with the minimum number of steps. You start at the middle, if the key is greater then you divide the second half and do the same thing with it.
In three steps a binary search returned the correct value. This isn't so great with a list of 20 values, but when the list gets to be huge, such as one million items, a binary search will find the correct value with no more than 20 steps. This is very very fast.Code:key = 12 First step: marker | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Second Step: marker | 11 12 13 14 15 16 17 18 19 20 Third Step: marker | 11 12 13 14
-Prelude
My best code is written with the delete key.