0% found this document useful (0 votes)
21 views3 pages

MIT Quiz Feb

The document is a review for Quiz 3 of the Introduction to Algorithms course at MIT, covering topics such as dynamic programming and recursive frameworks. It outlines the scope of the quiz, including material from previous quizzes and specific problem sets, and provides a structured approach to solving recursive problems. Additionally, it presents four adapted problems that require algorithmic solutions with specified time complexities.

Uploaded by

shiva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

MIT Quiz Feb

The document is a review for Quiz 3 of the Introduction to Algorithms course at MIT, covering topics such as dynamic programming and recursive frameworks. It outlines the scope of the quiz, including material from previous quizzes and specific problem sets, and provides a structured approach to solving recursive problems. Additionally, it presents four adapted problems that require algorithmic solutions with specified time complexities.

Uploaded by

shiva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Algorithms: 6.

006
Massachusetts Institute of Technology
Instructors: Erik Demaine, Jason Ku, and Justin Solomon Quiz 3 Review

Quiz 3 Review

Scope
• Quiz 1 & Quiz 2 material fair game but explicitly not emphasized
• 4 lectures on dynamic programming, L15-L18, 2 Problem Sets, PS7-PS8
• Recursive framework (SRTBOT)
• Dynamic Programming: subproblem dependencies overlap, forming a DAG

Recursive Framework (SRT BOT)


1. Subproblem definition
• Describe meaning of subproblem in words, in terms of parameters x ∈ X
• Often subsets of input: prefixes, suffixes, contiguous substrings of a sequence
• Often multiply possible subsets across multiple inputs
• Often “remember” information by maintaining some auxiliary state (expansion)
• Often expand based on state of integers in problem space (pseudopolynomial?)
2. Relate recursively
• Relate subproblem solutions recursively x(i) = f (x(j), . . .) for one or more j < i
• Identify question about subproblem solution whose answer would let you reduce to
smaller subproblem(s), then locally brute-force all possible answers to the question
3. Topological order
• Argue relation is acyclic (defines “smaller” subproblems), subproblems form a DAG
4. Base cases
• State solutions for all (reachable) independent subproblems where relation breaks down
5. Original problem
• Show how to compute solution to original problem from solutions to subproblem(s)
• Possibly use parent pointers to recover actual solution, not just objective function
6. Time analysis
P
• x∈X work(x), or if work(x) = O(W ) for all x ∈ X, then |X| · O(W )
• work(x) measures nonrecursive work in relation; treat recursions as taking O(1) time
Quiz 3 Review 2

Problem 1. Future Investing (adapted from S18 PS9)


Tiffany Bannen stumbles upon a lottery chart dropped by a time traveler from the future, which
lists winning lottery numbers and positive integer cash payouts for the next n days. Tiffany wants
to use this information to make money, but is worried if she plays winning numbers every day,
lottery organizers will get suspicious. As such, she decides to play the lottery infrequently: at
most twice in any seven day period. Describe a O(n)-time algorithm to determine the maximum
amount of lottery winnings Tiff can win in the next n days by playing the lottery infrequently.
Problem 2. Oh Charlie, Where Art Thou? (adapted from S18 PS9)
A wealthy family, Alice, Bob, and their young son Charlie are sailing around the world when they
encounter a massive storm. Charlie is thrown overboard, presumed drowned. Twenty years later,
a man comes to Alice and Bob claiming to be Charlie. Alice and Bob are excited, but skeptical.
Alice and Bob order a DNA matching test from the genetic testing company 46AndThee. Given
three length-n DNA sequences from Alice, Bob, and Charlie, the testing center will determine
ancestry as follows: if Charlie’s DNA can be partitioned into two (not necessarily contiguous)
subsequences of equal length, where one is a subsequence of Alice’s DNA, and the other is a
subsequence of Bob’s DNA, the Charlie is their son. For example, suppose Alice’s DNA is AATT
and Bob’s DNA is CCGG. If Charlie’s DNA were CATG, he would be matched as their son, since
CATG can be partitioned into disjoint subsequences CG and AT which are subsequences of Alice
and Bob’s DNA respectively. However, Charlie would be found to be an imposter if his DNA were
AGTC. Describe an O(n4 )-time algorithm to determine whether Charlie is a fraud.
Problem 3. Sweet Tapas (adapted from S18 Final)
Obert Ratkins is having dinner at an upscale tapas bar, where he will order many small plates.
There are n plates of food on the menu, where information for plate i is given by a triple of non-
negative integers (vi , ci , si ): the plate’s volume vi , calories ci , and sweetness si ∈ {0, 1} (the plate
is sweet if si = 1 and not sweet if si = 0). Obert is on a diet: he wants to eat no more than k
calories during his meal, but wants to fill his stomach as much as possible. He also wants to order
exactly s < n sweet plates, without purchasing the same dish twice. Describe an O(nks)-time
algorithm to find the maximum volume of food Obert can eat given his diet.
Problem 4. Gokemon Po (adapted from S18 Final)
Kash Etchum wants to play Gokemon Po, a new augmented reality game. The goal is to catch
a set of n monsters who reside at specific locations in her town. Monsters must be obtained in a
specific order: before Kash can obtain monster mi , she must have already obtained all monsters
mj for j < i. To obtain monster mi , Kash may either purchase the monster in-game for positive
integer ci dollars, or she may catch mi for free from that monster’s location. If Kash is not at the
monster’s location, she will have to pay a ride share service to drive her there. The minimum
possible cost to transport from the location of monster mi to the location of monster mj via ride
sharing is denoted by the positive integer s(i, j). Given the price lists of in-game purchases and
ride sharing trips between all pairs of monsters, describe an O(n2 )-time algorithm to determine the
minimum amount of money Kash must spend in order to catch all n monsters, assuming that she
starts at the location of monster m1 .
MIT OpenCourseWare
https://ocw.mit.edu

6.006 Introduction to Algorithms


Spring 2020

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms

You might also like