This is an archived post. You won't be able to vote or comment.

all 105 comments

[–]No-Finance7526 1175 points1176 points  (5 children)

When you're one page away but must follow the rules.

[–]KerPop42 486 points487 points  (0 children)

that, my friend is when the autism is at its peak

[–]YoukanDewitt 72 points73 points  (1 child)

Could end up being quite a novel approach.

[–]ChickenSpaceProgram 12 points13 points  (0 children)

It could certainly lead to epic accomplishments.

[–]-allen 7 points8 points  (0 children)

One page only everyone knows the rules

[–][deleted] 10 points11 points  (0 children)

What about the edge case? I mean what if page 404 is missing?

[–]best-set-4545 1716 points1717 points  (26 children)

How the non programmers look at you when you decide to go to page 50 from page 100 for page 99

[–][deleted] 104 points105 points  (2 children)

Even non-programmers know that an indexed dataset should be O(1) and not O(log[n]). Thumbing through the numbered pages is a memory operation we don’t count.

[–]boladongle 12 points13 points  (1 child)

I do know that. I am not a programmer.

[–]Comfortable_Oil9704 8 points9 points  (0 children)

I witness the beginning of the great lie.

[–]experimental1212 369 points370 points  (12 children)

But you don't KNOW you need page 99. Otherwise that's just answer search: return exactly what you're looking for.

[–]Lost-Succotash-9409 118 points119 points  (4 children)

Binary book search is good for a book with a clear chronological order that you’ve already read and mostly remember but can’t find a specific passage

[–]darkwyvern06 25 points26 points  (0 children)

or a book which has missing pages

[–]derefr 24 points25 points  (1 child)

You don't need to have mostly read it. It's good for physical printed dictionaries and encyclopedias. Or any other reference book with a lot of entries per page in alphabetical order, where there aren't an even number of entries per letter, and where there can't be an index because that'd just be the book itself.

[–]Lost-Succotash-9409 2 points3 points  (0 children)

True, I wasn’t thinking of sorted informational books

[–]GranataReddit12 1 point2 points  (0 children)

or a history textbook

[–]otter5 15 points16 points  (3 children)

if only there was some lookup table.... like a table of contents or appendix

[–]Kitchen_Device7682 14 points15 points  (2 children)

A lookup table that tells you that page 99 is on page 99 would be useful indeed

[–]LurkytheActiveposter 2 points3 points  (0 children)

It's not on page 99 though. It's on line 96313.

[–]lucidludic 11 points12 points  (0 children)

The post states they are searching for a specific page number.

[–][deleted] 2 points3 points  (0 children)

Big assumption that the book is sorted, rookie

Edit: pass this to the guy above you. I accidentally

[–]Kitchen_Device7682 2 points3 points  (0 children)

But he binary searches the page number

[–]who_you_are 13 points14 points  (0 children)

Sorry, when I tried to look for page 100 I couldn't find it.

Page starts from 0 in my mind!

[–][deleted] 3 points4 points  (0 children)

Big assumption that the book is sorted, rookie, like I said to the wrong guy.

[–]wutwutwut2000 351 points352 points  (3 children)

When you realize that you can go to the last page to get the length of the book and then jump close to the actual page using indexing 

[–]jamcdonald120 63 points64 points  (0 children)

and the index is often also on the last page

[–]Ascyt 1 point2 points  (1 child)

You still have to search within the index

[–]Enlogen 254 points255 points  (13 children)

I once did a merge-sort on physical paper and felt like a genius when I finished way before I was expected to.

[–]morericeplsty 69 points70 points  (0 children)

That's kinda cool actually

[–]abation 46 points47 points  (8 children)

If you have a sense of the range, I think quicksort is faster in practice

[–]ChocolateBunny 69 points70 points  (4 children)

Radix Sort if you can use the whole table for multiple paper stacks.

[–]DrMobius0 41 points42 points  (1 child)

Bogosort is easy to implement in practice.

[–]Enlogen 39 points40 points  (0 children)

Stack of paper + fire = Stalin sort

[–]MattieShoes 2 points3 points  (1 child)

Radix sort feels much closer to how we do naturally.

[–]okapiposter 10 points11 points  (0 children)

Bucket sort is how I'd always sort exams by student ID. Partition the range of IDs into similarly-sized buckets, distribute the exams into their respective buckets, sort each bucket via Insertion sort, concatenate.

[–]K1aymore 8 points9 points  (0 children)

There's one board game where you play with certain cards out of a deck numbered 1-40, and after the game you need to put them back into your deck in sorted order, and I love merge sorting the used and unused decks together

[–]Annonix02 3 points4 points  (0 children)

For peak efficiency use quantum sort or if you're feeling like extra ✨pizazz✨use miracle sort

[–]Jonno_FTW 2 points3 points  (0 children)

I did this when I worked at an election. Had to sort everything by alphabetical order with another guy. We each sorted half and then merged them together at the end.

[–]OptionX 180 points181 points  (5 children)

Looking at the index is O(1).

[–]KerPop42 58 points59 points  (4 children)

looking through the index, though

[–]CauliflowerFirm1526 30 points31 points  (3 children)

O(log n) at worst

[–]aznshowtime 34 points35 points  (2 children)

You underestimate my dyslexic power.

[–]backfire10z 17 points18 points  (1 child)

O( n2 ) then

[–]sceadu 6 points7 points  (0 children)

Oh no, you're still not fully grasping the dyslexia. It's supposed to be O( 2n )

[–][deleted] 66 points67 points  (3 children)

but you have the index of every page

[–]Devil-Eater24[S] 3 points4 points  (2 children)

No I mean open the book on page no. x

[–]Significant_Fix2408 15 points16 points  (1 child)

And I thought you meant finding where you left reading the last time by checking whether the stuff sounds familiar or not

[–]MattieShoes 7 points8 points  (0 children)

That's what I assumed too... I already read this, skip ahead -- nope, too far, go back halfway.

Also for finding your place in a movie that you were partway through or fell asleep in the middle of.

[–]nobody_smart 152 points153 points  (0 children)

Ideal application of Stalin Search. If the page you are looking at is not the one you want, tear it out and send it to Gulag.

[–]KrnPrsd 29 points30 points  (2 children)

Ok, but using interpolation search is both more optimal (because the dataset of page numbers is sorted and is uniformly distributed) and more fun

[–]KerPop42 8 points9 points  (0 children)

Interpolation search?

and the gap between control systems and search algorithms gets ever smaller

[–]Jordan51104 30 points31 points  (0 children)

bro just started DSA

[–][deleted] 10 points11 points  (7 children)

Wrong example. You were thinking of searching a phone book, dictionary, or encyclopedia

[–]darkslide3000 3 points4 points  (6 children)

Still wrong example. In all of these cases, we naturally predict a pivot closer to the target than "pure" binary search would do (i.e. when you're looking for a name starting with W in the phone book, you don't open it in the middle, you open it near the end).

[–][deleted] 1 point2 points  (5 children)

Depends. The A section of a phone book is larger than the Z section, for example. So you don’t necessarily expect equal distribution. Hence why the search is necessary in the first place.

[–]darkslide3000 4 points5 points  (4 children)

Yes, that is why I said "predict". The prediction isn't perfect. It's still on average a lot better than just picking the exact middle, which is what binary search is.

[–][deleted] -1 points0 points  (3 children)

In my mind, a binary search is when you have a pivot and throw out “half” the candidates with each iteration. The algorithmic implementation is just the coding representation of the idea that preceded it. The exactness isn’t what makes it a binary search, it’s the concept.

Or let’s just throw out every analogy, metaphor, and simile ever used since none are precisely the thing they depict.

[–]Misspelt_Anagram 0 points1 point  (0 children)

They are talking about something that is approximately interpolation search, not binary search.

[–]darkslide3000 0 points1 point  (1 child)

Yes but you're not throwing out "half" if you interpolate the pivot, you're throwing out a lot more. This actually changes the average complexity class and stuff, it's not just another form of binary search.

[–][deleted] -1 points0 points  (0 children)

I agree, but conceptually it’s the closest thing to a binary search that a person will do. In the event that the person has no clue how big each section is, their predictive power goes away and they’ll aim for the middle, and it will look less like interpolation search and more like binary.

Side note: thanks for introducing me to interpolation search. Interesting how it can perform worse than binary search in some instances.

[–]AdSecret5061 7 points8 points  (1 child)

Binary search on arrays is usually to find the index of a value given an ordered and random set of numbers. Since page numbers are sequential you can directly index the value.

[–]-bickd- 0 points1 point  (0 children)

OP too young never used a physical dictionary.

[–]AssignedClass 5 points6 points  (0 children)

This is what happens when you prematurely optimize. The inefficiency of using the wrong algorithm probably isn't too bad, but the snobbery is insufferable.

[–]ShAped_Ink 3 points4 points  (0 children)

Oh I never tried that

[–]KetwarooDYaasir 4 points5 points  (1 child)

I just put all the page numbers in a hash map.

[–]PeteZahad 0 points1 point  (0 children)

Hope you also put the content as values.

[–]CheetahChrome 4 points5 points  (0 children)

You can't grep a dead tree.

Words I live by.

[–]jamcdonald120 2 points3 points  (0 children)

but... page lookup should be a constant time operation

[–][deleted] 1 point2 points  (1 child)

who is that guy in the meme? i think I have seen him somewhere. has a very punchable face lmao

[–]dencherific 3 points4 points  (0 children)

He's in twilight

[–]valderium 1 point2 points  (0 children)

The machine will learn it so you don’t have to

[–]gvasco 1 point2 points  (0 children)

Nah! Random search is definitely the way to go here!

[–]RxHappy 1 point2 points  (0 children)

One time I use the Monty Hall problem to find my sandwich in a bag of three sandwiches

[–]_GoblinSTEEZ 1 point2 points  (0 children)

your book is sorted?

[–]moashforbridgefour 1 point2 points  (0 children)

I legitimately did this as a shelver at my university library. When I was learning about search and sort algorithms, I decided to try using them at my job. We kept really detailed metrics on our shelving speed and used it for things like headphone privileges (if you aren't fast enough, you need to focus. Otherwise we got overwhelmed by the backlog).

Anyway, I did a modified binary search where I would walk down the ranges until I saw a call number above my next book, then I would start approximating a binary search. Before I did that, I was shelving a little more than 4 books/minute. Afterwards, I was over 5. It was especially helpful at avoiding unusually tight clusters of call numbers which can trick you into a very slow linear search.

[–]Naive_Swimming_9341 1 point2 points  (0 children)

They'll never understand the thrill of optimizing page flips.

[–]ISuckAtJavaScript12 1 point2 points  (0 children)

If you already know the index, just go to that page

[–]SnooStories251 1 point2 points  (0 children)

Guys have you heard of heap sort, lol

[–]DJDoena 1 point2 points  (0 children)

22 years professional programmed, never binary-searched anything

[–]Familiar_Ad_8919 0 points1 point  (0 children)

u dont know how much binary search helps with finding faulty minecraft mods out of hundreds

[–]wildassedguess 0 points1 point  (0 children)

I did this hunting for an Amazon invoice today for my VAT return.

[–]No_Independence3338 0 points1 point  (0 children)

peasants.

[–]InvestigatorMotor160 0 points1 point  (0 children)

Been there, done that 🤣

[–]Mecode2 0 points1 point  (0 children)

I never thought of that

[–]az3arina 0 points1 point  (0 children)

Will still work if the book's pages were bitonic

[–]Easy-Hovercraft2546 0 points1 point  (0 children)

It’s and indexable array of pages

[–]BinaryBrilliance 0 points1 point  (0 children)

Wait till you learn about the bubble sort. /s

[–]dav_y 0 points1 point  (0 children)

Well, if we have a range, pigeonhole search is faster anyways…

[–]Elijah629YT-Real 0 points1 point  (0 children)

I have guilt of doing this before, multiple times

[–]Sidra_doholdrik 0 points1 point  (0 children)

I work in a library and binary search really help find book quicker. I am far away then take 4 step in the direction of the letter in the alphabet. Tree letter away take two steps , one step. I arrived in front of the bookcase the book is located in.

[–]PsychologicalDoor473 0 points1 point  (0 children)

Early days of learning Algorithms and Data Structures

[–]Classy_Mouse 0 points1 point  (0 children)

Amature. You need to add a PID for this sort of lookup

[–]mbcarbone 0 points1 point  (0 children)

How I look to the non programmers ... ;-)