1 / 27

Solved Problems

Solved Problems. Problem 0.

cira
Télécharger la présentation

Solved Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Solved Problems

  2. 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.

  3. Problem 0. • Write a pseudocode HIRE-ASSISTANT to expreess this strategy for hiring OA. Solution:

  4. 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

  5. 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.

  6. 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.

  7. Problem 1. Exercise 2.3.7 p. 37

  8. Problem 2. Exercise 4.1.6 p. 67 Show that the solution to is O(n log n). Solution:

  9. Problem 2a. Exercise 4.1.6 p. 67 Solve the recurrence by making a change of variables.

  10. Problem 2a. Exercise 4.1.6 p. 67

  11. Problem 2b. Exercise 4.1.6 p. 67 Solve the recurrence by making a change of variables. Solution:

  12. Problem 3. Polynomial Multiplication

  13. Problem 3. Polynomial Multiplication (cont.)

  14. Problem 3. Polynomial Multiplication (cont.)

  15. Problem 5. Analysis of d-ary heaps

  16. Problem 5. Analysis of d-ary heaps(cont.) • How would you represent a d-ary heap in an array? Solution:

  17. Problem 5. Analysis of d-ary heaps(cont.)

  18. Problem 5. Analysis of d-ary heaps(cont.)

  19. Problem 5. Analysis of d-ary heaps(cont.)

  20. Problem 5. Analysis of d-ary heaps(cont.)

  21. Problem 5. Analysis of d-ary heaps(cont.)

  22. Problem 5. Analysis of d-ary heaps(cont.)

  23. Problem 5. Analysis of d-ary heaps(cont.)

  24. Problem 6. Prob. 9.1 p.194

  25. Problem 7.

  26. Problem 7.

  27. Problem 6.

More Related