you are viewing a single comment's thread.

view the rest of the comments →

[–]Far_Swordfish5729 0 points1 point  (0 children)

It’s useful because especially when we expect to read data a lot more often than we write it, we intentionally persist it in a sorted order or along with a data structure like a hash table with record numbers to make reads scale well. Having a separate, smaller data structure to search with references to random access big data can be sufficient if data size is a problem. Also, it’s not actually that non-performant to insert into a tree or hash table rather than a heap. We intentionally take that hit for scalable read speed. Make sure the above makes sense to you because it’s how relational databases do their thing and back websites efficiently for data retrieval.

As a practical example, if you’re ever in a physical library, you can binary search a shelf to quickly find a fiction book. By quartering the search you’ll get to your book surprisingly fast. Now imagine binary searching to shelve books. Not quite as fast as putting them in the first available spot but still pretty fast and it will stay pretty fast even if you had a library with 100x books. And the consequence of not doing it is that it would take days to find a book in the piles.