|
-
Aug 18th, 2006, 11:23 PM
#13
Hyperactive Member
Re: What is the most fastest way to see if a string already exists in an array
A binary search is basically what the non-idiotic Price is Right contestants do on that beat the clock game.. Say you have 1024 possibilities:
You guess 512 and Bob says "HIGHER!"
You guess 768 (512+256) and Bob says "HIGHER"
You guess 896 (512+256+128) and Bob says "LOWER"
You guess 832 (512+256+128-64) and Bob says "HIGHER"
You guess 864 (512+256+128-64+32) and Bob says "HIGHER"
You guess 880 (512+256+128-64+32+16) and Bob says "LOWER"
You guess 872 (512+256+128-64+32+16-8) and Bob says "LOWER"
You guess 868 (512+256+128-64+32+16-8-4) and Bob says "HIGHER"
You guess 870 (512+256+128-64+32+16-8-4+2) and Bob says "LOWER!!"
You guess 869 (512+256+128-64+32+16-8-4+2-1) Then the music starts playing and you get to pay taxes on something you didn't really want/need..
BTW, 1024=2^10 obviously and I picked a worst case scenario where 10 iterations were needed since we weren't lucky enough to find it outright part way through
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|