37:
to update a single array index, rather than taking the midpoint of an upper and a lower bound on each iteration; therefore, it is optimized for architectures (such as Knuth's
682:
668:
29:
686:
715:
696:
62:
58:
38:
700:
692:
48:
many searches will be performed on the same array, or on several arrays of the same length
709:
20:
663:
34:
24:
45:
a table lookup is generally faster than an addition and a shift, and
8:
693:An implementation of Knuth's algorithm
683:An implementation of Knuth's algorithm
61:looks like this, when implemented in
7:
672:, Volume 3. Page 412, Algorithm C.
19:is an optimization of the classic
14:
669:The Art of Computer Programming
30:The Art of Computer Programming
1:
732:
67:
607:"%d is at index %d
277:/* midpoint of array */
59:binary search algorithm
23:algorithm invented by
451:/* Example of use: */
27:and given in Knuth's
17:Uniform binary search
701:Adrianus Warmenhoven
689:, by Han de Bruijn
716:Search algorithms
723:
653:
650:
647:
644:
641:
638:
635:
632:
629:
626:
623:
620:
617:
614:
611:
608:
605:
602:
599:
596:
593:
590:
587:
584:
581:
578:
575:
572:
569:
566:
563:
560:
557:
554:
551:
548:
545:
542:
539:
536:
533:
530:
527:
524:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
491:
488:
485:
482:
479:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
425:
422:
419:
416:
413:
410:
407:
404:
401:
398:
395:
392:
389:
386:
383:
380:
377:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
344:
341:
338:
335:
332:
329:
326:
323:
320:
317:
314:
311:
308:
305:
302:
299:
296:
293:
290:
287:
284:
281:
278:
275:
272:
269:
266:
263:
260:
257:
254:
251:
248:
245:
242:
239:
236:
233:
230:
227:
224:
221:
218:
215:
212:
209:
206:
203:
200:
197:
194:
191:
188:
185:
182:
179:
176:
173:
170:
167:
164:
161:
158:
155:
152:
149:
146:
143:
140:
137:
134:
131:
128:
125:
122:
119:
116:
113:
110:
107:
104:
101:
98:
95:
92:
89:
86:
83:
80:
77:
74:
71:
53:C implementation
731:
730:
726:
725:
724:
722:
721:
720:
706:
705:
679:
660:
655:
654:
651:
648:
645:
642:
639:
636:
633:
630:
627:
624:
621:
618:
615:
612:
609:
606:
603:
600:
597:
594:
591:
588:
585:
582:
579:
576:
573:
570:
567:
564:
561:
558:
555:
552:
549:
546:
543:
540:
537:
534:
531:
528:
525:
522:
519:
516:
513:
510:
507:
504:
501:
498:
495:
492:
489:
486:
483:
480:
477:
474:
471:
468:
465:
462:
459:
456:
453:
450:
447:
444:
441:
438:
435:
432:
429:
426:
423:
420:
417:
414:
411:
408:
405:
402:
399:
396:
393:
390:
387:
384:
381:
378:
375:
372:
369:
366:
363:
360:
357:
354:
351:
348:
345:
342:
339:
336:
333:
330:
327:
324:
321:
318:
315:
312:
309:
306:
303:
300:
297:
294:
291:
288:
285:
282:
279:
276:
273:
270:
267:
264:
261:
258:
255:
252:
249:
246:
243:
240:
237:
234:
231:
228:
225:
222:
219:
216:
213:
210:
207:
204:
201:
198:
195:
192:
189:
186:
183:
180:
177:
174:
171:
168:
165:
162:
159:
156:
153:
150:
147:
144:
141:
138:
135:
132:
129:
126:
123:
120:
117:
114:
111:
108:
105:
102:
99:
96:
93:
90:
87:
84:
81:
78:
75:
72:
70:#define LOG_N 4
69:
55:
12:
11:
5:
729:
727:
719:
718:
708:
707:
704:
703:
690:
678:
677:External links
675:
674:
673:
659:
656:
68:
54:
51:
50:
49:
46:
13:
10:
9:
6:
4:
3:
2:
728:
717:
714:
713:
711:
702:
698:
694:
691:
688:
684:
681:
680:
676:
671:
670:
665:
662:
661:
657:
66:
64:
60:
52:
47:
44:
43:
42:
40:
36:
32:
31:
26:
22:
21:binary search
18:
667:
454:#define N 10
57:The uniform
56:
35:lookup table
33:. It uses a
28:
25:Donald Knuth
16:
15:
41:) on which
658:References
547:make_delta
88:make_delta
625:unisearch
226:unisearch
160:<<=
710:Category
687:Pascal
643:return
613:"
601:printf
367:return
331:return
73:static
699:, by
664:Knuth
433:delta
412:delta
352:delta
295:while
265:delta
208:delta
202:while
193:power
169:delta
157:power
151:power
109:power
79:delta
583:<
466:void
460:main
421:else
394:<
379:else
343:else
184:half
145:half
85:void
695:in
685:in
640:));
565:int
559:for
475:int
457:int
391:key
316:key
280:int
256:int
247:key
244:int
232:int
223:int
142:int
121:int
106:int
94:int
76:int
39:MIX
712::
697:Go
666:.
610:\n
592:++
586:20
556:);
544:};
541:19
535:17
529:15
523:14
430:+=
409:-=
385:if
370:-1
355:==
346:if
319:==
310:if
217:);
211:!=
136:do
65:.
652:}
649:;
646:0
637:i
634:,
631:a
628:(
622:,
619:i
616:,
604:(
598:)
595:i
589:;
580:i
577:;
574:0
571:=
568:i
562:(
553:N
550:(
538:,
532:,
526:,
520:,
517:9
514:,
511:7
508:,
505:6
502:,
499:5
496:,
493:3
490:,
487:1
484:{
481:=
478:a
472:{
469:)
463:(
448:}
445:}
442:}
439:}
436:;
427:i
424:{
418:}
415:;
406:i
403:{
400:)
397:a
388:(
382:{
376:}
373:;
364:{
361:)
358:0
349:(
340:}
337:;
334:i
328:{
325:)
322:a
313:(
307:{
304:)
301:1
298:(
292:;
289:0
286:=
283:d
274:;
271:1
268:-
262:=
259:i
253:{
250:)
241:,
238:a
235:*
229:(
220:}
214:0
205:(
199:}
196:;
190:/
187:)
181:+
178:N
175:(
172:=
166:;
163:1
154:;
148:=
139:{
133:;
130:0
127:=
124:i
118:;
115:1
112:=
103:{
100:)
97:N
91:(
82:;
63:C
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.