Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Binary Search implementation issues

Name: Anonymous 2016-09-29 23:22

When Jon Bentley assigned binary search as a problem in a course for professional programmers, he found that ninety percent failed to provide a correct solution after several hours of working on it,[44] and another study published in 1988 shows that accurate code for it is only found in five out of twenty textbooks.[45] Furthermore, Bentley's own implementation of binary search, published in his 1986 book Programming Pearls, contained an overflow error that remained undetected for over twenty years. The Java programming language library implementation of binary search had the same overflow bug for more than nine years.[46]

https://en.wikipedia.org/wiki/Binary_search_algorithm#Implementation_

Name: Anonymous 2016-09-30 1:04

So designing and writing provable correct software is hard. Thanks for the news.

Name: Anonymous 2016-09-30 1:35

Most programmers are brainlets.

Name: Anonymous 2016-09-30 2:09

perl -lne 's/[^01]//g; print if /[01]+/'

Name: Anonymous 2016-09-30 2:18

quite incredible!

even trying our best, it's this difficult to get simple things right.

I wonder if we now have tools that would help write small functions like this better?

Name: Anonymous 2016-09-30 4:17

Thats why unit testing was invented.
Also if i had to code when other people look at me, i'll probably write shit code. I can't work under stress.

Name: Cudder !cXCudderUE 2016-10-01 15:09

>>5
You have a tool, it's in your skull.

>>2
...but apparently most people don't make use of this tool.

>>6
Testing doesn't work when you don't even know what to test.

The underlying problem here is that people don't know how to use induction and handle the four cases in total: even-length array, not found; even-length array, found; odd-length array, not found; odd-length array, found.

Binary search sounds deceptively simple: cut the array into two halves, look at the "middle" element and continue with either half if it's not found, until you get down to 1 element. People execute this "algorithm" IRL without realising one key mistake in that description: there is no "middle" element if the length is even, and they're actually looking at an element in either the lower or upper half.

As for the overflow "bug"? It only happens with extremely large arrays. Maybe it was known that it would overflow, but was not a problem because searching an array of 2G elements binarily is just not something done often or even the best way to solve the problem. With 64-bit, the overflow becomes expoentially harder and so I would not consider it a "bug" at all, just an implementation limitation. No one is creating, much less searching arrays of 2^63 elements binarily.

Name: Anonymous 2016-10-01 17:29

Still i prefer C integer promotions over "Garbage-Collected Integers".

Name: Anonymous 2016-10-01 21:43

>>8
If you think the only alternatives are C retardation and ``"Garbage-Collected Integers"'' then you've been swindled by your school.

Then people wonder why someone from India who literally defecates on the street and learned Microsoft BASIC for MS-DOS without a computer knows more about computer science and is better qualified for a job than hipster ``goyim'' who read dumbed down books like SICP.

Name: Anonymous 2016-10-01 21:51

>>7
kill yourself

Name: Anonymous 2016-10-02 3:17

>>10
Check 'em!

Name: Anonymous 2016-10-02 9:36

>>9
Computer science isn't about programming or computers. It's totally legitimate for anybody to study computer science with or without the help of BASIC and MS-DOS. You don't even need to touch a computer to study computer science.

Name: Anonymous 2016-10-02 15:59

>>12
It's not science if you don't make empirical observations of real world behavior.

Name: Anonymous 2016-10-02 16:01

>>13
Computer Science is a religion?

Name: Anonymous 2016-10-02 22:11

>>12

In my dictionary, the preferred definition of science involves discovering
properties of the natural world. Engineering involves the application of those
properties to solve practical problems. By those definitions we are neither
scientists nor engineers. The principal objects of our study are manmade, not natural.
--William Allan Wulf, inventor of BLISS programming language, president of the National Academy of Engineering, Professor of Engineering and Applied Sciences

Name: Anonymous 2016-10-02 23:12

>>13
>>14
Computer science is not about computers nor is it a science. The name is actually a misnomer like "geometry"

Name: Anonymous 2016-10-03 1:02

>>15
science - discovering properties of the natural world.
engineering - the application of those properties to create new/desired natural &/or artificial properties

philosophy - the study of things which need not exist in physical forms. For instance, science is not an object that science can observe and study.

Computer Algorisophy

Name: Anonymous 2016-10-03 2:06

Computer Religion:
Have you Read your SICP today?
Designs Patterns you must follow or else

Primitive Computer Worship:
Retrocomputing

Computer Philosophy:
http://c2.com/cgi/wiki?WelcomeVisitors

Computer Art:
The Art of Computer Programming
Art of Assembly
Demoscene

Computer Science:
https://arxiv.org/archive/cs/

Name: Anonymous 2016-10-03 8:47

>>18
Computer Literature:
WEB
Inform

Computer Postmodernism:
Esolangs
Langsec

Name: Anonymous 2016-10-03 13:47

>>18
c2.com
Back to reddit.com/r/tvtropes, please!

Name: Anonymous 2016-10-03 17:02

>>20
epic meme!

>>22
epic dubs!

Name: Anonymous 2016-10-03 17:31

>>21
Thanks, buddy!

Don't change these.
Name: Email:
Entire Thread Thread List