E N D
Problem 0. We want to hire a new office assistant(OA) through an employment agency. The employment agency will send us one candidate each day. We will interview that person and then decide either hire that person or not. We must pay the employment agency a small fee to interview an applicant. To actually hire anapplicant more costly.We are committed to having, at all times, the best possible person for the job. Therefore , we decide that, after interviewing each applicant, if that applicant is better qualified than the current OA, we will fire the current OA and hire the new applicant. We are willingto pay the resulting price of this strategy but we wish to estimate what that price will be.
Problem 0. • Write a pseudocode HIRE-ASSISTANT to expreess this strategy for hiring OA. Solution:
Problem 0. b) When does the worst case occur? What is the total hiring cost? Solution: In the worst case we actually hire every candidate that we interview. This situation occurs if the candidates come in increasing order of quality, in which case we hire n times. The total hiring cost is where is the cost of interviewing a candidate and is the cost of hiring a candidate. Since is small as compared to
Problem 0. c) What is the expected number of times that we hire a new OA? Solution: Let X be the random variable whose value equals the number of times we hire a new OA. Let be the indicator variable associated with the ith candidate hired.
Problem 1. Exercise 2.3.7 p. 37 Describe a time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x.
Problem 2. Exercise 4.1.6 p. 67 Show that the solution to is O(n log n). Solution:
Problem 2a. Exercise 4.1.6 p. 67 Solve the recurrence by making a change of variables.
Problem 2b. Exercise 4.1.6 p. 67 Solve the recurrence by making a change of variables. Solution:
Problem 5. Analysis of d-ary heaps(cont.) • How would you represent a d-ary heap in an array? Solution: