The document provides information about getting help with programming homework assignments. It lists contact details for the programming homework help service, including a phone number, email address, and website URL. It then provides sample problems and solutions for dynamic programming algorithms. The problems cover topics like campaign strategy optimization, assigning animals to cages, counting paths in a graph, pizza partitioning, and stock price analysis. The solutions describe the subproblems, recursive relationships, base cases, and running times for dynamic programming algorithms to solve each problem in linear or quadratic time.
I am Dennis L. I am a Programming Exam Expert at programmingexamhelp.com. I hold a Ph.D. in Computer Science from, City University of New York. I have been helping students with their exams for the past 9 years. You can hire me to take your exam in Programming.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Programming Exam.
I am Irene. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the California Institute of Technology. I have been helping students with their homework for the past 6 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Homework.
I am Charles B. I am an Algorithm Exam Expert at programmingexamhelp.com. I hold a Ph.D. in Programming from Texas University, USA. I have been helping students with their exams for the past 15 years. You can hire me to take your exam in Algorithm.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Exam.
it contains the detail information about Dynamic programming, Knapsack problem, Forward / backward knapsack, Optimal Binary Search Tree (OBST), Traveling sales person problem(TSP) using dynamic programming
I am Dennis L. I am a Programming Exam Expert at programmingexamhelp.com. I hold a Ph.D. in Computer Science from, City University of New York. I have been helping students with their exams for the past 9 years. You can hire me to take your exam in Programming.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Programming Exam.
I am Irene. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the California Institute of Technology. I have been helping students with their homework for the past 6 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Homework.
I am Charles B. I am an Algorithm Exam Expert at programmingexamhelp.com. I hold a Ph.D. in Programming from Texas University, USA. I have been helping students with their exams for the past 15 years. You can hire me to take your exam in Algorithm.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Exam.
it contains the detail information about Dynamic programming, Knapsack problem, Forward / backward knapsack, Optimal Binary Search Tree (OBST), Traveling sales person problem(TSP) using dynamic programming
I am Craig D. I am a Stochastic Processes Assignment Expert at statisticsassignmenthelp.com. I hold a Master's in Statistics, from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve assignments related to Stochastic Processes.
Visit statisticsassignmenthelp.com or email info@statisticsassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Stochastic Processes Assignments.
Analysis and design of algorithms part 4Deepak John
Complexity Theory - Introduction. P and NP. NP-Complete problems. Approximation algorithms. Bin packing, Graph coloring. Traveling salesperson Problem.
Graphs of the Sine and Cosine Functions LectureFroyd Wess
More: www.PinoyBIX.org
Lesson Objectives
Able to plot the different Trigonometric Graphs
Graph of Sine Function (y = f(x) = sinx)
Graph of Cosine Function (y = f(x) = cosx)
Define the Maximum and Minimum value in a graph
Generalized Trigonometric Functions
Graphs of y = sinbx
Graphs of y = sin(bx + c)
Could find the Period of Trigonometric Functions
Could find the Amplitude of Trigonometric Functions
Variations in the Trigonometric Functions
I am Luther H. I am a Stochastic Process Exam Helper at statisticsexamhelp.com. I hold a Masters' Degree in Statistics, from the University of Illinois, USA. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in Stochastic Process.
Visit statisticsexamhelp.com or email support@statisticsexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Stochastic Process Exam.
What is an Algorithm
Time Complexity
Space Complexity
Asymptotic Notations
Recursive Analysis
Selection Sort
Insertion Sort
Recurrences
Substitution Method
Master Tree Method
Recursion Tree Method
I am Frank G. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold in Programming from, the University of Waterloo, Canada. I have been helping students with their homework for the past 12 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Algorithm homework.
I am Joanna R. I am an Algorithm Exam Expert at programmingexamhelp.com. I hold a Bachelor of Information Technology from, the California Institute of Technology, United States. I have been helping students with their exams for the past 9 years. You can hire me to take your exam in Algorithm.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Exam.
Explore the world of C programming assignments with expert guidance and practical tips. Dive into a range of C assignment solutions designed for varying complexity levels. Get insights from industry experts passionate about sharing their C programming knowledge. Discover time-saving techniques to boost productivity and meet assignment deadlines. Access 24/7 customer support and budget-friendly pricing options.
Ready to excel in C programming assignments? Head over to https://www.programminghomeworkhelp.com/c-assignment/ to embark on a journey toward academic excellence. Don't let C assignments hold you back. Join us on the path to success today!
Welcome to Programming Homework Help
Python Question Assistance
Making Python Learning Easier
Introducing Python Question Assistance
Are you struggling with Python programming questions? Look no further! ProgrammingHomeworkHelp.com is here to provide comprehensive and reliable Python question assistance. Whether you're a beginner or an experienced programmer, we have the expertise to help you overcome any coding challenge.
Why Choose ProgrammingHomeworkHelp.com?
Expert Python Programmers: Our team consists of experienced Python programmers who are well-versed in the language and its various concepts. They possess the knowledge and skills to tackle any Python question effectively.
Customized Solutions: We understand that each Python question is unique, and we tailor our solutions accordingly. Our experts analyze the problem, devise a strategic approach, and provide you with personalized, step-by-step solutions.
Timely Delivery: We value your time and ensure prompt delivery of solutions. No matter how challenging the question is, our experts work diligently to meet your deadlines.
24/7 Availability: We are available round the clock to assist you with your Python questions. Whether it's day or night, our dedicated team is ready to provide guidance and support whenever you need it.
Our Python Question Assistance Services Include:
Code Debugging: If you're encountering errors or bugs in your Python code, our experts can help you identify and fix them. We'll guide you through the debugging process, explaining the errors and providing solutions.
Code Optimization: Want to improve the efficiency and performance of your Python code? Our programmers can review your code and suggest optimizations to enhance its speed and effectiveness.
Algorithm Design: If you're stuck on designing the right algorithm for a Python question, our experts can guide you through the process. We'll help you understand the problem requirements and devise an efficient algorithmic solution.
How to Get Started:
Visit our website, https://www.programminghomeworkhelp.com/
Submit your Python question along with any additional instructions or requirements.
Receive a quote for the assistance required.
Make a secure payment.
Sit back and relax while our experts work on your Python question.
Don't let Python questions become obstacles in your learning journey. Programming Homework Help is your go-to destination for reliable and comprehensive Python question assistance. Our team of experts is committed to helping you succeed in your programming endeavors. Visit our website today and experience hassle-free Python learning like never before!
I am Craig D. I am a Stochastic Processes Assignment Expert at statisticsassignmenthelp.com. I hold a Master's in Statistics, from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve assignments related to Stochastic Processes.
Visit statisticsassignmenthelp.com or email info@statisticsassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Stochastic Processes Assignments.
Analysis and design of algorithms part 4Deepak John
Complexity Theory - Introduction. P and NP. NP-Complete problems. Approximation algorithms. Bin packing, Graph coloring. Traveling salesperson Problem.
Graphs of the Sine and Cosine Functions LectureFroyd Wess
More: www.PinoyBIX.org
Lesson Objectives
Able to plot the different Trigonometric Graphs
Graph of Sine Function (y = f(x) = sinx)
Graph of Cosine Function (y = f(x) = cosx)
Define the Maximum and Minimum value in a graph
Generalized Trigonometric Functions
Graphs of y = sinbx
Graphs of y = sin(bx + c)
Could find the Period of Trigonometric Functions
Could find the Amplitude of Trigonometric Functions
Variations in the Trigonometric Functions
I am Luther H. I am a Stochastic Process Exam Helper at statisticsexamhelp.com. I hold a Masters' Degree in Statistics, from the University of Illinois, USA. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in Stochastic Process.
Visit statisticsexamhelp.com or email support@statisticsexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Stochastic Process Exam.
What is an Algorithm
Time Complexity
Space Complexity
Asymptotic Notations
Recursive Analysis
Selection Sort
Insertion Sort
Recurrences
Substitution Method
Master Tree Method
Recursion Tree Method
I am Frank G. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold in Programming from, the University of Waterloo, Canada. I have been helping students with their homework for the past 12 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Algorithm homework.
I am Joanna R. I am an Algorithm Exam Expert at programmingexamhelp.com. I hold a Bachelor of Information Technology from, the California Institute of Technology, United States. I have been helping students with their exams for the past 9 years. You can hire me to take your exam in Algorithm.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Exam.
Explore the world of C programming assignments with expert guidance and practical tips. Dive into a range of C assignment solutions designed for varying complexity levels. Get insights from industry experts passionate about sharing their C programming knowledge. Discover time-saving techniques to boost productivity and meet assignment deadlines. Access 24/7 customer support and budget-friendly pricing options.
Ready to excel in C programming assignments? Head over to https://www.programminghomeworkhelp.com/c-assignment/ to embark on a journey toward academic excellence. Don't let C assignments hold you back. Join us on the path to success today!
Welcome to Programming Homework Help
Python Question Assistance
Making Python Learning Easier
Introducing Python Question Assistance
Are you struggling with Python programming questions? Look no further! ProgrammingHomeworkHelp.com is here to provide comprehensive and reliable Python question assistance. Whether you're a beginner or an experienced programmer, we have the expertise to help you overcome any coding challenge.
Why Choose ProgrammingHomeworkHelp.com?
Expert Python Programmers: Our team consists of experienced Python programmers who are well-versed in the language and its various concepts. They possess the knowledge and skills to tackle any Python question effectively.
Customized Solutions: We understand that each Python question is unique, and we tailor our solutions accordingly. Our experts analyze the problem, devise a strategic approach, and provide you with personalized, step-by-step solutions.
Timely Delivery: We value your time and ensure prompt delivery of solutions. No matter how challenging the question is, our experts work diligently to meet your deadlines.
24/7 Availability: We are available round the clock to assist you with your Python questions. Whether it's day or night, our dedicated team is ready to provide guidance and support whenever you need it.
Our Python Question Assistance Services Include:
Code Debugging: If you're encountering errors or bugs in your Python code, our experts can help you identify and fix them. We'll guide you through the debugging process, explaining the errors and providing solutions.
Code Optimization: Want to improve the efficiency and performance of your Python code? Our programmers can review your code and suggest optimizations to enhance its speed and effectiveness.
Algorithm Design: If you're stuck on designing the right algorithm for a Python question, our experts can guide you through the process. We'll help you understand the problem requirements and devise an efficient algorithmic solution.
How to Get Started:
Visit our website, https://www.programminghomeworkhelp.com/
Submit your Python question along with any additional instructions or requirements.
Receive a quote for the assistance required.
Make a secure payment.
Sit back and relax while our experts work on your Python question.
Don't let Python questions become obstacles in your learning journey. Programming Homework Help is your go-to destination for reliable and comprehensive Python question assistance. Our team of experts is committed to helping you succeed in your programming endeavors. Visit our website today and experience hassle-free Python learning like never before!
I am Britney P. I love exploring new topics. Academic writing seemed an interesting option for me. After working for many years with progamminghomeworkhelp.com, I have assisted many students with their Design and Analysis of Algorithms Assignments. I can proudly say, each student I have served is happy with the quality of the solution that I have provided. I have acquired my bachelor's from Sunway University, Malaysia.
My name is Cecily Kent. I have been associated with programminghomeworkhelp.com for the past 8 years and have been assisting the programming students with their Algorithm Homework.
I have a PhD. in Programming from, the University of Melbourne, Australia.
I am Andrew O. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Southampton, UK. I have been helping students with their homework for the past 11 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Homework.
I am Joe L. I am an Algorithms Design Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the University of Chicago, USA. I have been helping students with their assignments for the past 10 years. I solve assignments related to Algorithms Design.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Design Assignment.
I am Anne L. I am an Algorithms Design Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Auburn University, USA. I have been helping students with their homework for the past 8 years. I solve homework related to Algorithms Design.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Design Homework.
I am Andrew O. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their assignments for the past 12 years. I solve assignment related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm assignment.
I am Simon M. I am a C Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, from Glasgow University, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
I am Vincent S. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Minnesota, USA. I have been helping students with their homework for the past 9 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Elijah L. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Bachelor’s Degree in Programming, Leeds University, UK. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Travis W. I am a Computer Science Assignment Expert at programminghomeworkhelp.com. I hold a Master's in Computer Science, Leeds University. I have been helping students with their homework for the past 9 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
I am Charles B. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Texas University, USA. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Christopher Hemmingway. I am a Computer Science Assignment Expert at programminghomeworkhelp.com. I hold a Master's in Computer Science, Princeton University, Princeton. I have been helping students with their homework for the past 10 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
I am Blake H. I am a Software Construction Assignment Expert at programminghomeworkhelp.com. I hold a PhD. in Programming, Curtin University, Australia. I have been helping students with their homework for the past 10 years. I solve assignments related to Software Construction.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Software Construction Assignments.
I am Bernard. I am a C Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Leeds, UK. I have been helping students with their homework for the past 9 years. I solve assignments related to C Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C Programming Assignments.
I am Gill H. I am a Programming Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the University of Texas, USA. I have been helping students with their homework for the past 10 years. I solve assignments related to Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Programming Homework.
I am Susan C. I am a C Homework Help Expert at programminghomeworkhelp.com. I hold a PhD. in Programming, Leeds University UK. I have been helping students with their homework for the past 12 years. I solve assignments related to C Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with C Programming assignments.
I am Bernard. I am a C Programming Assignment Help Expert at programminghomeworkhelp.com. I hold a Ph.D. in Computer Science from, University of Leeds, UK. I have been helping students with their homework for the past 12 years. I solve assignments related to C Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with C Programming assignments.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Digital Tools and AI for Teaching Learning and Research
Best Algorithms Assignment Help
1. For any Assignment related queries, Call us at : - +1 678 648 4277
You can mail us at : - support@programminghomeworkhelp.com or
reach us at : - https://www.programminghomeworkhelp.com/
2. Problem 7-1. Effective Campaigning
Representative Zena Torr is facing off against Senator Kong Grossman in a heated
presidential primary: a sequence of n head-to-head state contests, one per day for n days.
Each state contest i ∈ {1, . . . , n} has a known positive integer delegate count di, and a
projected delegate count zi < di that Rep. Torr would win if she took no further action.
There are total delegates and Rep. Torr needs at least delegates to win.
Unfortunately, Rep. Torr is projected to lose the race, since
so she needs to take action. Rep. Torr has a limited but effective election team which can
campaign in at most one state per day. If the team campaigns on day i, they will win all di
delegates in state i, but they will not be able to campaign at all for two days after day i, as
it will take time to relocate. Describe an O(n)-time algorithm to determine whether it is
possible for Rep. Torr to win the primary contest by campaigning effectively.
Solution:
1. Subproblems
• x(i): max delegates Torr can win in states i to n, where campaign on day i is possible
• for i ∈ {1, . . . , n + 1}
programminghomeworkhelp.com
3. 2. Relate
• Will either campaign or not on day i. Guess!
• If campaign, get di delegates, but cannot campaign during next two days
• Otherwise, no restriction, but only get zi delegates
• x(i) = max{di + zi+1 + zi+2 + x(i + 3), zi + x(i + 1)}
3. Topo
• x(i) only depends on subproblems with strictly larger i, so acyclic
4. Base
• x(n + 1) = 0 (no more states to be won)
• x(n) = dn (campaign on last day, since dn > zn)
• x(n - 1) = max{dn-1 + zn, zn-1 + dn} (campaign on either of last two days)
5. Original
• Solve subproblems via recursive top down or iterative bottom up
• Return whether x(1) ≥ bD/2c + 1 (the maximum delegates she can achieve is at least as
large as the amount she needs to win)
programminghomeworkhelp.com
4. 6. Time
• # subproblems: n + 1
• Work per subproblem: O(1)
• O(n) running time
Rubric: (Same for all theory problems in PS7)
• S: 3 points for a correct subproblem description
• R: 3 points for a correct recursive relation
• T: 1 points for indication that relation is acyclic
• B: 1 point for correct base cases in terms of subproblems
• O: 1 point for correct original solution in terms of subproblems
• T: 2 points for correct analysis of running time
• 4 points if a correct dynamic program is efficient (meets requested bound)
• Partial credit may be awarded
Problem 7-2. Caged Cats
Ting Kiger is an eccentric personality who owns n pet tigers and n2 cages.
programminghomeworkhelp.com
5. • Each tiger i has known positive integer age ai and size si (no two have the same age or
size).
• Each cage j has known positive integer capacity cj and distance dj from Ting’s bedroom
(no two have the same capacity or distance).
Ting needs to assign each tiger its own cage.
• Ting favors older tigers and wants them to sleep closer to his bedroom, i.e., any two
tigers x and y with ages ax < ay must be assigned to cages X and Y respectively such that
dY < dX.
• A tiger i assigned to cage cj will experience positive discomfort si - cj if si > cj , but will
not experience any discomfort if
Describe an O(n3)-time algorithm to assign tigers to cages that favors older tigers and
minimizes the total discomfort experienced by the tigers.
Solution: The “favors older tigers” condition ensures that the tigers sorted decreasing by
age will be matched with a subsequence of the cages sorted increasing by distance from
Ting’s bedroom. So first sort the tigers into sequence T decreasing by age in O(n log n)
time and the cages into sequence C increasing by distance in O(n2 log n) time (e.g., via
merge sort). Now, we use dynamic programming to find an optimal matching from T with
a subsequence of C.
programminghomeworkhelp.com
6. 1. Subproblems
• x(i, j) : min total discomfort possible, matching tigers T[i :] to a subsequence of C[j :]
for i ∈ {0, . . . , n} and j ∈ {0, . . . , n2}
2. Relate
• Can either match tiger T[i] with cage C[j] or not. Guess!
• If matched, incur discomfort of match (if any).
• In either case, won’t match C[j] with any tiger in T[i + 1 :] so recurse on remainder
• Let d(i, j) be the discomfort of matching tiger T[i] with cage C[j]
• i.e., d(i, j) = si - cj if si > cj and zero otherwise
• x(i, j) = min{d(i, j) + x(i + 1, j + 1), x(i, j + 1)}
3. Topo
• x(i, j) only depends on subproblems with strictly larger j, so acyclic
4. Base
• x(n, j) = 0 (all tigers are matched, so no discomfort)
• x(i, n2) = ∞ for i > 0 (no more cages and cannot have homeless tigers)
programminghomeworkhelp.com
7. programminghomeworkhelp.com
5. Original
• Solve subproblems via recursive top down or iterative bottom up
• x(0, 0) is the minimum total discomfort matching all tigers to cages
• Store parent pointers to reconstruct the optimal assignment
6. Time
• # subproblems: (n + 1)(n2 + 1) = O(n3)
• Work per subproblem: O(1)
• O(n3) running time
Problem 7-3. Odd Paths
Given a weighted directed acyclic graph G = (V, E,w) with integer weights and two
vertices s,t ∈ V , describe a linear-time algorithm to determine the number of paths
from s to t having odd weight. When solving this problem, you may assume that a
single machine word is large enough to hold any integer computed during your
algorithm.
Solution: The number of paths from s to t having odd weight, depends on the number of
paths to each of t’s incoming neighbers: paths of odd weight if the incoming edge is
8. even, and paths of even weight if the incoming edge is odd. So we make two types of
subproblem per vertex representing the number of even weight and odd weight paths to
the vertex.
1. Subproblems
• x(v, i): the number of paths from s to v, having even weight if i = 0 and odd weight if i =
1
• for all v ∈ V and i ∈ {0, 1}
2. Relate
• In a DAG, the number of even or odd paths to v is the sum of the relevant paths to its
incoming vertices
• Let p(i) be the parity of integer i, i.e., p(i) = 0 if i is even and p(i) = 1 if i is odd P
• x(v, i) = {x(u, p(w(u, v) + i)) | u ∈ Adj-(v)}
3. Topo
• x(v, i) depends only on subproblems x(u, j) for vertices u that appear earlier in the
topological order of G, so acyclic
programminghomeworkhelp.com
9. 4. Base
• x(s, 0) = 1 (since zero edges is even)
• x(s, 1) = 0 (no odd length paths to s from s)
• x(v, 0) = x(v, 1) = 0 for any other v where Adj-(v) = ∅
5. Original
• x(t, 1), the number of odd paths from s to vertex t
6. Time
• # subproblems: 2|V |
• Work per subproblem: O(deg-v))
O(2 ∑vЄV deg –(v)) = O(|V | + |E|) running time (linear in the size of the graph)
Problem 7-4. Pizza Partitioning
Liza Pover and her little brother Lie Pover want to share a round pizza pie that has been
cut into 2n equal sector slices along rays from the center at angles αi = iπ/n for i ∈ {0, 1, . .
. , 2n}, where α0 = α2n. Each slice i between angles αi and αi+1 has a known integer
programminghomeworkhelp.com
10. tastiness ti (which might be negative). To be “fair” to her little brother, Liza decides to eat
slices in the following way:
• They will each take turns choosing slices of pizza to eat: Liza starts as the chooser.
• If there is only one slice remaining, the chooser eats that slice, and eating stops.
• Otherwise the chooser does the following:
– Angle αi is proper if there is at least one uneaten slice on either side of the line passing
through the center of the pizza at angle αi.
– The chooser picks any number i ∈ {1, . . . , 2n} where αi is proper, and eats all uneaten
slices counter-clockwise around the pizza from angle αi to angle αi + π.
– Once the chooser has eaten, the other sibling becomes the chooser, and eating
continues.
Liza wants to maximize the total tastiness of slices she will eat. Describe an O(n3)-time
algorithm to find the maximum total tastiness Liza can guarantee herself via this selection
process.
programminghomeworkhelp.com
11. Solution: As the siblings eat pizza, the uneaten slices are always cyclically consecutive
(since removal of a half plane is a convex operation). So we choose consecutive cyclic
subarrays as our subproblems. Each sibling wants to maximize tastiness, we make
different subproblems based on which sibling is currently the chooser.
While making choices, it will be useful to know the tastiness of any subarray. Let v(i, j)
be the tastiness of the j slices counter-clockwise from angle αi, i.e., v(i, j) = ∑j-1
k=0 ((i+k)
mood 2n) , where indices are taken modulo 2n, for i ∈ {0, . . . , 2n - 1} and j ∈ {0, . . . ,
n}. There are O(n2) such v(i, j) and each can be computed na¨ıvely in O(n) time, O(n3)
time in total. Note that these can also be computed in O(n2) time via dynamic
programming, but the na¨ıve method is sufficient for the requested time bound.)
12. 1. Subproblems
• x(i, j, p) : the maximum tastiness Liza can acheive with the j slices counter-clockwise
from αi remaining, when either: Liza is the chooser when p = 1, or Lie is the chooser
when p = 2
• for i ∈ {0, . . . , 2n - 1}, j ∈ {0, . . . , n}, p ∈ {1, 2}
• (we can only have at most n slices after first choice, so we don’t compute for j > n2.
Relate
• Liza tries to maximize, while Lie may try to minimize (so in worst case he does)
• Chooser can choose any proper angle and then choose a side. Guess!
• Angle αi+k is proper for any k ∈ {1, . . . , j - 1}
• Chooser eats either: k slices between αi and αi+k or j -k slices between αi+k and αi+j
• Liza does not gain or lose tastiness when Lie eats
• x(i, j, 1) = max {max
{v(i, k) + x(i + k, j -k, 2),
}k∈ {1, . . . , j - 1}
}
v(i + k, j - k) + x(i, k, 2)
• x(i, j, 2) = min {min
{
x(i + k, j - k, 1),
}
k ∈ {1, . . . , j - 1}
}
programminghomeworkhelp.com
x(i, k, 1)
13. 3. Topo
• x(i, j, p) only depends on subproblems with strictly smaller j, so acyclic
4. Base
• x(i, 1, 1) = ti (Liza eats last slice)
• x(i, 1, 2) = 0 (Lie eats last slice)
• for all i ∈ {1, . . . , 2n}
5. Original
• Liza first chooses which half to eat
• Max is sum of tastiness on a half and tastiness achieved letting Lie choose on other half
• max{x(i, n, 2) + v(((i + n) mod 2n), n) | i ∈ {0, . . . , 2n - 1}}
6. Time
• Work for compute all v(i, j): O(n3)
• # subproblems: 2(2n)(n + 1) = O(n2)
• Work per subproblem: O(n)
• Work to compute original: O(n) • O(n3) running time
programminghomeworkhelp.com
14. Problem 7-5. Shorting Stocks
Bordan Jelfort is a short seller at a financial trading firm. He has collected stock price
information from s different companies C = (c0, . . . , cs-1) for n consecutive days. Stock
price information for a company ci is a chronological sequence Pi = (p0, . . . , pnk-1) of nk
prices, where each price is a positive integer and prices {pkj , . . . , pkj+k-1} all occur on
day j for j ∈ {0, . . . , n - 1}. The shorting value of a company is the length of the longest
chronological subsequence of strictly decreasing prices for that company that doesn’t skip
days: if the sequence contains two prices on different days i and j with i < j, then the
sequence must also contain at least one price from every day in {i, . . . , j}.
(a) Describe an O(snk2)-time algorithm to determine which company ci has the highest
shorting value, and return a longest subsequence S of decreasing subsequences of prices
from Pi that doesn’t skip days.
Solution: We will compute the shorting value of each company via dynamic programming
(assuming P = Pi), and then return the longest in O(s) time.
1. Subproblems
• x(j): the longest decreasing subsequence of prices that doesn’t skip days in P[j :] that
includes price P[j]
programminghomeworkhelp.com
15. • for j ∈ {0, . . . , nk - 1}
2. Relate
• Next in sequence has price at later time in same day or the next day. Guess!
• At price index j, there are (k - 1) - (j mod k) prices left in same day
• Then there are k prices in the following day (if it exists)
• So last next price index is f(j) = min{j + (k - 1) - (j mod k) + k, nk - 1}
• x(j) = 1 + max{x(d) | d ∈ {j + 1, . . . , f(j)} and P[j] > P[d]} ∪ {0}
3. Topo
• x(j) only depends on subproblems with strictly larger j, so acyclic
4. Base
• Relation includes base case when minimization contains only 0
• Can also say: x(nk - 1) = 1 (only one item left)
5. Original
programminghomeworkhelp.com
16. • Solve subproblems via recursive top down or iterative bottom up
• Shorting value is max max nk-1 x(j)
• Store parent pointers to reconstruct S
j=0
6. Time
• # subproblems: nk
• Work per subproblem: O(k)
• Work for original: O(nk)
• O(nk2) running time
(b) Write a Python function short company(C, P, n, k) that implements your algorithm
from part (a) using the template code provided. You can download the code template and
some test cases from the website.
Solution:
1 # iterative bottom-up
2 def short_company(C, P, n, k):
3 S = [ ]
programminghomeworkhelp.com
17. 4 for i in range(len(C)):
5 p = P[i]
6 x = [1 for _ in range(n*k)] # subproblem memo
7 r = [None for _ in range(n*k)] # parent pointer memo
8 best = 0
9 for j in range(n*k - 1, -1, -1): # compute memos
10 f = min(j + (k - 1) - (j % k) + k, n*k - 1)
11 for d in range(j + 1, f + 1):
12 if (p[j] > p[d]) and (1 + x[d] > x [ j ]):
13 x[j] = 1 + x[d]
14 r[j] = d
15 if x[best] < x[ j ]:
16 best = j
17 if x[best] > len(S): # reconstruct from parent pointers
18 c, S = C[i], []
19 while best != None:
20 S.append(p[best])
21 best = r[best]
22 S = tuple(S)
23 return (c, S)
programminghomeworkhelp.com
18. 1 # recursive top-down
2 def short_company(C, P, n, k):
3 S = []
4 for i in range(len(C)):
5 p = P[i]
6 memo = [None for _ in range(n*k)] # memo for subproblems and parents
7 def dp(j): # recursive function
8 if memo[j] is None:
9 F = min(j + (k - 1) - (j % k) + k, n*k - 1)
10 x, r = 1, None
11 for d in range(j + 1, f + 1):
12 x_, _ = dp(d)
13 if (p[j] > p[d]) and (1 + x_ > x):
14 x, r = 1 + x_, d
15 memo[j] = (x, r)
16 return memo[j]
17 best, opt = 0, 0
18 for j in range(n*k):
19 x, _ = dp(j)
20 if x > opt:
programminghomeworkhelp.com
19. 20 best, opt = j, x
21 if opt > len(S): # reconstruct from parent pointers
22 c, S = C[i], []
23 while best != None:
24 S.append(p[best])
25 _, best = dp(best)
26 S = tuple(S)
27 return (c, S)
programminghomeworkhelp.com