Structure is an investment. Sorting a rack of order slips on…
Structure is an investment. Sorting a rack of order slips once cost 63 comparisons + 50 shifts = 113 operations. On the sorted rack, every later lookup takes 3 probes instead of the 14 an unsorted lookup took — a saving of 11 probes per lookup. After how many lookups has the sort paid for itself?
Read DetailsAn unsorted rack holds n slips, and n orders must be deliver…
An unsorted rack holds n slips, and n orders must be delivered. For each order the program runs a linear scan of the rack, checking slips one by one: for t in orders: # n orders scan(rack, t) # checks up to n slips Counting how often the innermost operation runs, the total running time is:
Read Details