Problem Set 4
Problem Set 4
Problem Set 4 Points: 20 Date: March 28, 2022 Due: April 4, 2022
Lab
Question 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 points
This question concerns question 7-2 (Quicksort with equal element values). Please read the
question carefully.
(a) (2 points) Implement the PARTITION' function as described in part(b) of the question.
(b) (2 points) Implement RANDOMIZED-QUICKSORT' as described in part(c) of the question.
Question 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 points
At an unnamed university, there are k hostels and n students. You are in charge of assigning
hostels to the students. The problem is that there are m pairs of students do not like one
another one and have requested you to not assign them the same hostel. This is in general a
very hard problem to solve efficiently and belongs to a class of problems called NP-hard. After
many sleepless nights, you have devised a simple strategy: you will randomly (and independently)
assign students to hostels (completely ignoring their requests). Your task is to empirically find
out that on average what fraction of the constraints will be satisfied? You may assume that your
hostels do not have any upper limit on the number of students that can be housed.
Theory
Question 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 points
Textbook questions:
(a) (1 point) Exercise 7.2.3
(b) (1 point) Exercise 7.2-4
(c) (1 point) Exercise 7.2-5
(d) (3 points) Problem 7.2 parts (a), (d)
Question 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 points
This question concerns the hostel assignment problem that you did in the lab. Calculate the
expectation value of the constraints that you satisfy through your random assignment. How does
your calculation match with your empircal result?