Computational Fairy Tales by Jeremy Kubica
Author:Jeremy Kubica [Kubica, Jeremy]
Language: eng
Format: epub, pdf
Published: 2012-06-24T23:00:00+00:00
Before Insertion
During Insertion
After Insertion
“But—” started Peter. The librarian cut him off.
“I think what Peter wants to know is why you don’t take all the jackets off the rack and use something like merge sort,” said the librarian. “Other sorting algorithms can be faster.”
“Because jackets are heavy,” explained the tailor. “It’s a pain to take them off the rack. It would be tiring. But the jackets do slide easily down the rack.”
Peter looked confused. Why did it matter how hard it was to take things off the rack? This was an argument about computational complexity.
“I think the factor that you’re missing is: when most people use insertion sort, the insertions are expensive,” the librarian explained to Peter. “Consider an accountant who’s trying to sort a list of accounts in one of his books. Each line is one account—like entries in a computer’s array. You can’t just insert something and have the rest shift down automatically. That would take a most tedious form of magic. Every time the accountant wants to do an insertion, he has to manually shift down everything below that. A single insertion is an expensive O(N) operation. That’s a lot of erasing and rewriting.
“But, for a tailor, the insertion is a simple O(1) operation. He pushes the coats down,” added the librarian.
Peter nodded an acknowledgement. Inside he chafed at the technicalities of the physical world impacting the cost of different operations. The theoretical world was so much cleaner. However, he did agree with the librarian and the tailor; in this case, insertion sort seemed reasonable. He wondered what other real-world applications might challenge his computational assumptions.
Later that day, Peter tried using insertion sort on several carts’ worth of books. Unfortunately, the books didn’t move easily between the carts’ shelves, and Peter found himself spending the entire night shifting books between shelves. It took him an extra three hours to finish the sorting. He left the library at 2 a.m., angry at himself for not determining the cost of the insertion operation before he started sorting.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Evelina by Fanny Burney(27010)
Call Me by Your Name by André Aciman(20739)
The Secret History by Donna Tartt(19480)
Primed Son (Dark Siren Book 4) by Eden Ashley(19006)
Shot Through the Heart by Niki Burnham(17495)
All the Missing Girls by Megan Miranda(16747)
Who'd Have Thought by G Benson(16733)
Eleanor and Park by Rainbow Rowell(15686)
Ready Player One by Cline Ernest(15157)
Always and Forever, Lara Jean by Jenny Han(15074)
A Web of Lies 27 by Bella Forrest(13905)
Fallen Heir by Erin Watt(13530)
The Cruel Prince (The Folk of the Air Book 1) by Holly Black(12693)
Bull's Eye Sniper Chronicles Collection (The Second Cycle of the Betrayed Series) by McCray Carolyn(12542)
Crooked Kingdom: Book 2 (Six of Crows) by Bardugo Leigh(12458)
Shadow Children #03 - Among the Betrayed by Margaret Peterson Haddix(12028)
Twisted Palace by Erin Watt(11280)
Warriors (9781101621189) by Young Tom(10998)
Simon vs. the Homo Sapiens Agenda by Becky Albertalli(10641)