Question

Image for 3. Let X be a set of n elements to be maintained as a linked list: Assume that the cost of examining a particu

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Consider any order, and suppose that for some $i$, $P_i/C_i < P_{i+1}/C_{i+1}$ .

Suppose that we switch the elements $i$ and $i+1$. Say that we switched between $\ldots,A,B,\ldots$ and $\ldots,B,A\ldots$.

Let $\Delta$ be the difference in average search cost (new cost minus old cost). When looking for $A$, which happens with probability

$P_i$, we have to pay $C_{i+1}$ more. When looking for $B$, which happens with probability

$P_{i+1}$, we have to pay $C_i$ less. So $$ \Delta = P_i C_{i+1} - P_{i+1} C_i = (P_i/C_i - P_{i+1}/C_{i+1}) C_i C_{i+1} < 0.

In other words, the switch was beneficial. We conclude that the optimal arrangement is to store the elements in non-increasing order.

Add a comment
Know the answer?
Add Answer to:
3. Let X be a set of n elements to be maintained as a linked list:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT