SlideShare a Scribd company logo
1 of 12
To get more info, Please
Visit : – https://www.programmingexamhelp.com/
E-Mail : – support@programmingexamhelp.com
Contact Us : – +1678 648 4277
PROGRAMMINGEXAMHELP.COM
Problems:
1. Subproblem definition
• Describe the 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 <
• 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
programmingexamhelp.com
• 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
• work(x), or if work(x) = O(W) for all x ∈ X, then |X| · O(W) x∈X
• work(x) measures nonrecursive work in relation; treat recursions as taking O(1) time
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.
programmingexamhelp.com
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
nonnegative 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.
programmingexamhelp.com
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.
programmingexamhelp.com
Solutions:
programmingexamhelp.com
Solution: 1.
Subproblems
• Let L(i) be the cash payout of playing the lottery on day i ∈ {1, . . . , n}
• Need to keep track of most recent two plays (or equivalently, restrictions on future plays)
• x(i, j): maximum lottery winnings playing on suffix of days from i to n, assuming play on day i
and next allowable play is on day i + j
• for i ∈ {1, . . . , n} and j ∈ {1, . . . , 6} 2. Relate
• Tiffany will play again on some day in future. Guess!
• It is never optimal to go 11 days without playing the lottery, as playing on the 6th day would be
valid and strictly increase winnings
• The next play can be on day i + k for k ∈ {j, . . . , 11}
• If next play on i + k for k ∈ {1, . . . , 6}, next allowable play is on day i + 7
• If next play on i + k for k ∈ {7, . . . , 11}, next allowable play is on day i + k + 1
• x(i, j) = L(i) + max{x(i + k, max{1, 7 k}) | k ∈ {i, . . . , 11} and i + k ≤ n} 3.
3. Topo
• Subproblems x(i, j) only depend on strictly larger i, so acyclic 4.
Base
• x(n, j) = L(i) for all j ∈ {1, . . . , 6} 5. Original
• Solve subproblems via recursive top down or iterative bottom up
• Guess first play (within first seven days)
• Solution to original problem is max{x(i, 1) | i ∈ {1, . . . , 7}}
• (Can store parent pointers to reconstruct days played) 6. Time
• # subproblems: 6n
• work per subproblem: O(1)
• work for original: O(1)
• O(n) running time
programmingexamhelp.com
Solution 2:
1. Subproblems
• Let A, B, and C be the relevant length-n DNA sequences from Alice, Bob, and Charlie.
• Want to match some characters of A and B to all characters of C
• x(i, j, ki, kj ): true if can match a length-ki subsequence of suffix A[i :] and a length-kj characters
from prefix B[j :] to all characters in suffix C[(n ki kj ) :] (the suffix containing the last ki + kj
characters), and false otherwise.
programmingexamhelp.com
• for i, j ∈ {0, . . . , n} and ki, kj ∈ {0, . . . , n/2} (assume n is even) 2. Relate
• Must match character C[i]; if A[i] = C[i] or B[i] = C[i] recurse on remainder
• Alternatively, do not use either A[i] or B[i]
3. Topo
• Subproblem x(i, j, ki, kj ) only depends on strictly smaller i + j, so acyclic 4. Base
• x(n, n, 0, 0) is true (all matched!)
• x(n, j, ki, kj ) false if ki > 0 (no more characters in A)
• x(i, n, ki, kj ) false if kj > 0 (no more characters in B)
5. Original
• Solve subproblems via recursive top down or iterative bottom up
• Solution to original problem is x(n, n, n/2, n/2) 4
6. Time
• # subproblems: O(n4)
• work per subproblem: O(1)
• O(n4) running time
programmingexamhelp.com
Solution: 3. Subproblems
• x(i, j, s0 ): maximum volume of food possible purchasing a suffix of plates pi to pn1, using at
most j calories, ordering exactly s0 sweet plates
• for i ∈ {0, . . . , n}, j ∈ {0, . . . , k}, s0 ∈ {0, . . . , s} 2. Relate
• Either order plate pi or not. Guess!
• If order pi, get vi in volume but use ci calories
• If pi is sweet, need to order one fewer sweet plate
3. Topo
• Subproblems x(i, j, s0 ) only depend on strictly larger i, so acyclic
4. Base
• x(n, j, 0) = 0 and any j (no more plates to eat)
programmingexamhelp.com
• x(n, j, s0 ) = ∞ for s0 > 0 and any j (no more plates, but still need to eat sweet)
5. Original
• Solution given by x(0, k, s) 6. Time
• # subproblems: O(nks)
• work per subproblem: O(1)
• O(nks) running time
programmingexamhelp.com
Solution 4:
1. Subproblems
• x(i, j): min cost of catching monsters mi to mn starting at location mj for j ≤ i 2. Relate
• If at location of monster, catch it for free!
• Otherwise, either acquire monster mi by purchasing or ride-sharing to location. Guess!
• If purchase spend ci dollars, else need to ride share to mi from mj
3. Topo
• Subproblems x(i, j) only depend on strictly larger i + j so acyclic
4. Base
• x(n + 1, j) = 0 for any j (no cost to collect no monsters)
5. Original
programmingexamhelp.com
• Solution is given by x(1, 1)
6. Time
• # subproblems: O(n2)
• work per subproblem: O(1)
• O(n2) running time

More Related Content

Similar to Programming Exam Help

Problem Set 4 Due in class on Tuesday July 28. Solutions.docx
Problem Set 4   Due in class on Tuesday July 28.  Solutions.docxProblem Set 4   Due in class on Tuesday July 28.  Solutions.docx
Problem Set 4 Due in class on Tuesday July 28. Solutions.docxwkyra78
 
Mathematical Statistics Homework Help
Mathematical Statistics Homework HelpMathematical Statistics Homework Help
Mathematical Statistics Homework HelpExcel Homework Help
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpExcel Homework Help
 
Erlang Concurrency
Erlang ConcurrencyErlang Concurrency
Erlang ConcurrencyBarry Ezell
 
Pwl rewal-slideshare
Pwl rewal-slidesharePwl rewal-slideshare
Pwl rewal-slidesharepalvaro
 
Undecidability in partially observable deterministic games
Undecidability in partially observable deterministic gamesUndecidability in partially observable deterministic games
Undecidability in partially observable deterministic gamesOlivier Teytaud
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mcaEdhole.com
 
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!Bertram Ludäscher
 

Similar to Programming Exam Help (20)

Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Probability Homework Help
Probability Homework HelpProbability Homework Help
Probability Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Problem Set 4 Due in class on Tuesday July 28. Solutions.docx
Problem Set 4   Due in class on Tuesday July 28.  Solutions.docxProblem Set 4   Due in class on Tuesday July 28.  Solutions.docx
Problem Set 4 Due in class on Tuesday July 28. Solutions.docx
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 
Mathematical Statistics Homework Help
Mathematical Statistics Homework HelpMathematical Statistics Homework Help
Mathematical Statistics Homework Help
 
Mathematical Statistics Homework Help
Mathematical Statistics Homework HelpMathematical Statistics Homework Help
Mathematical Statistics Homework Help
 
Pre cal drill
Pre cal drillPre cal drill
Pre cal drill
 
Statistics Coursework Help
Statistics Coursework HelpStatistics Coursework Help
Statistics Coursework Help
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Statistics Coursework Help
Statistics Coursework HelpStatistics Coursework Help
Statistics Coursework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Erlang Concurrency
Erlang ConcurrencyErlang Concurrency
Erlang Concurrency
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
Pwl rewal-slideshare
Pwl rewal-slidesharePwl rewal-slideshare
Pwl rewal-slideshare
 
Undecidability in partially observable deterministic games
Undecidability in partially observable deterministic gamesUndecidability in partially observable deterministic games
Undecidability in partially observable deterministic games
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mca
 
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!
Games, Queries, and Argumentation Frameworks: Time for a Family Reunion!
 

More from Programming Exam Help (19)

Best Algorithms Design Exam Help
Best Algorithms Design Exam Help Best Algorithms Design Exam Help
Best Algorithms Design Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Computer Science Exam Help
Computer Science Exam HelpComputer Science Exam Help
Computer Science Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Algorithm Exam Help
Algorithm Exam Help Algorithm Exam Help
Algorithm Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
 

Recently uploaded

The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 

Recently uploaded (20)

The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 

Programming Exam Help

  • 1. To get more info, Please Visit : – https://www.programmingexamhelp.com/ E-Mail : – support@programmingexamhelp.com Contact Us : – +1678 648 4277 PROGRAMMINGEXAMHELP.COM
  • 2. Problems: 1. Subproblem definition • Describe the 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 < • 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 programmingexamhelp.com
  • 3. • 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 • work(x), or if work(x) = O(W) for all x ∈ X, then |X| · O(W) x∈X • work(x) measures nonrecursive work in relation; treat recursions as taking O(1) time 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. programmingexamhelp.com
  • 4. 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 nonnegative 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. programmingexamhelp.com
  • 5. 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. programmingexamhelp.com
  • 6. Solutions: programmingexamhelp.com Solution: 1. Subproblems • Let L(i) be the cash payout of playing the lottery on day i ∈ {1, . . . , n} • Need to keep track of most recent two plays (or equivalently, restrictions on future plays) • x(i, j): maximum lottery winnings playing on suffix of days from i to n, assuming play on day i and next allowable play is on day i + j • for i ∈ {1, . . . , n} and j ∈ {1, . . . , 6} 2. Relate • Tiffany will play again on some day in future. Guess! • It is never optimal to go 11 days without playing the lottery, as playing on the 6th day would be valid and strictly increase winnings • The next play can be on day i + k for k ∈ {j, . . . , 11} • If next play on i + k for k ∈ {1, . . . , 6}, next allowable play is on day i + 7 • If next play on i + k for k ∈ {7, . . . , 11}, next allowable play is on day i + k + 1 • x(i, j) = L(i) + max{x(i + k, max{1, 7 k}) | k ∈ {i, . . . , 11} and i + k ≤ n} 3.
  • 7. 3. Topo • Subproblems x(i, j) only depend on strictly larger i, so acyclic 4. Base • x(n, j) = L(i) for all j ∈ {1, . . . , 6} 5. Original • Solve subproblems via recursive top down or iterative bottom up • Guess first play (within first seven days) • Solution to original problem is max{x(i, 1) | i ∈ {1, . . . , 7}} • (Can store parent pointers to reconstruct days played) 6. Time • # subproblems: 6n • work per subproblem: O(1) • work for original: O(1) • O(n) running time programmingexamhelp.com
  • 8. Solution 2: 1. Subproblems • Let A, B, and C be the relevant length-n DNA sequences from Alice, Bob, and Charlie. • Want to match some characters of A and B to all characters of C • x(i, j, ki, kj ): true if can match a length-ki subsequence of suffix A[i :] and a length-kj characters from prefix B[j :] to all characters in suffix C[(n ki kj ) :] (the suffix containing the last ki + kj characters), and false otherwise. programmingexamhelp.com • for i, j ∈ {0, . . . , n} and ki, kj ∈ {0, . . . , n/2} (assume n is even) 2. Relate • Must match character C[i]; if A[i] = C[i] or B[i] = C[i] recurse on remainder • Alternatively, do not use either A[i] or B[i]
  • 9. 3. Topo • Subproblem x(i, j, ki, kj ) only depends on strictly smaller i + j, so acyclic 4. Base • x(n, n, 0, 0) is true (all matched!) • x(n, j, ki, kj ) false if ki > 0 (no more characters in A) • x(i, n, ki, kj ) false if kj > 0 (no more characters in B) 5. Original • Solve subproblems via recursive top down or iterative bottom up • Solution to original problem is x(n, n, n/2, n/2) 4 6. Time • # subproblems: O(n4) • work per subproblem: O(1) • O(n4) running time programmingexamhelp.com
  • 10. Solution: 3. Subproblems • x(i, j, s0 ): maximum volume of food possible purchasing a suffix of plates pi to pn1, using at most j calories, ordering exactly s0 sweet plates • for i ∈ {0, . . . , n}, j ∈ {0, . . . , k}, s0 ∈ {0, . . . , s} 2. Relate • Either order plate pi or not. Guess! • If order pi, get vi in volume but use ci calories • If pi is sweet, need to order one fewer sweet plate 3. Topo • Subproblems x(i, j, s0 ) only depend on strictly larger i, so acyclic 4. Base • x(n, j, 0) = 0 and any j (no more plates to eat) programmingexamhelp.com
  • 11. • x(n, j, s0 ) = ∞ for s0 > 0 and any j (no more plates, but still need to eat sweet) 5. Original • Solution given by x(0, k, s) 6. Time • # subproblems: O(nks) • work per subproblem: O(1) • O(nks) running time programmingexamhelp.com Solution 4: 1. Subproblems • x(i, j): min cost of catching monsters mi to mn starting at location mj for j ≤ i 2. Relate • If at location of monster, catch it for free! • Otherwise, either acquire monster mi by purchasing or ride-sharing to location. Guess! • If purchase spend ci dollars, else need to ride share to mi from mj
  • 12. 3. Topo • Subproblems x(i, j) only depend on strictly larger i + j so acyclic 4. Base • x(n + 1, j) = 0 for any j (no cost to collect no monsters) 5. Original programmingexamhelp.com • Solution is given by x(1, 1) 6. Time • # subproblems: O(n2) • work per subproblem: O(1) • O(n2) running time