Written homework #6
Due: 10/16/2009
1) At Hogwarts a new
shipment of n goblins has
arrived. To be of any use, a goblin must
be completely truthful (never lies).
Unfortunately, not all of the n
goblins in the shipment are truth tellers.
Only some are truth-tellers, and some are deceivers. It is your task to design an algorithm to
separate the truth-teller goblins from the deceiver goblins. To do this, you have one tool available: You may combine any two goblins and have them
state whether the other goblin is a truth-teller or a deceiver. A truth-teller will always say correctly what
the other goblin is, but a deceiver may lie (but also may sometimes tell the
truth to REALLY confuse you). For any
two goblins that you test, the following can be concluded from the goblin
responses:
Goblin A says Goblin
B says Conclusion
B is a truth-teller A
is a truth-teller both are
truth-tellers or both are deceivers
B is a truth-teller A
is a deceiver at least one is
a deceiver
B is a deceiver A
is a truth-teller at least one is a
deceiver
B is a deceiver A
is a deceiver at least one is
a deceiver
·
Show that if more than n/2 goblins are deceivers,
it is impossible to determine which goblins are the truth-tellers using only
the pairwise testing strategy.
·
Consider the problem of identifying 1 truth-teller
goblin. Show that if we assume that more
than n/2 of the goblins are truth-tellers, then the problem of finding a single
truth-teller from n goblins can be reduced to a problem of about half the size
using n/2 goblin comparisons.
·
Use a recurrence equation to show that if at least
half of the goblins are truth-tellers, then the truth-tellers can all be
identified within O(n) goblin comparisons.
2) You are given k lists of items with each list being sorted. Let n be the total number of items in all of the lists. Design an O(n log k) algorithm to merge all of the lists into one single sorted list.
3) Finish the implementation of the minheap started in class. In particular:
- implement the extract-min function
- add an 'initialize-heap( itemlist )' that takes as input an array of n items and turns those items into a valid heap. Make your algorithm run in O(n) time. You may follow the textbook's method of doing this. I suggest you read the book to understand the idea behind the approach, but try to write the code yourself from scratch. If you simply translate the book's code into your program, you will learn very little about what is really going on.
4) In the worst case, what is the lower bound on the number of comparison needed to sort a 9 item list? Provide a comparison based sorting algorithm to sort a 9 item list. How many comparisons does your algorithm make in the worst case?
5) In the worst case, what is the lower bound on the number of comparisons needed to sort a 50 item list? ? Provide a comparison based sorting algorithm to sort a 50 item list. How many comparisons does your algorithm make in the worst case?