Question

In: Computer Science

Write the recurrence for each of the following two problems. Try to come up with the...

Write the recurrence for each of the following two problems. Try to
come up with the solution using your understanding.
1) Maximal subarray problem
2) Weighted interval selection problem

Solutions

Expert Solution

1) Maximal subarray problem
It is the problem by which finding the adjacent subarray with the largest sum,within one dimensional array.
Properties of Maximal subarray problem are:

Property 1:
If an array includes all non-negative numbers,then the problem is trivial; a maximum subarray is the entire array.
Property 2:
If an array including all non-positive numbers, then a solution is any subarray of size 1 containing the maximal value of the array.
Property 3:
Different sub-arrays may have the same maximum sum.


Solution of recurrence in Maximal subarray problem
The algorithmic techniques used for this problem are
a) Divide and conquer solution: Divide: Firstly dividing the problem into some sub problem.
Conquer:Then the sub problem by calling recursively until sub problem solved.
Combine: The Sub problem solved so that to will get find the problem solution
DAC(a, i, j)
{
if(small(a, i, j))
return(Solution(a, i, j))
else
m = divide(a, i, j) // f1(n)
b = DAC(a, i, mid) // T(n/2)
c = DAC(a, mid+1, j) // T(n/2)
d = combine(b, c) // f2(n)
return(d)
}
b) Brute force Solution
The algorithm consists in checking, at all positions in the text between 0 and n-m, whether an occurrence of the pattern starts
there or not.There after it shifts the pattern by exactly one position to the right.
The brute-force method is then expressed by the algorithm
c ← first(P)
while c ≠ Λ do
if valid(P,c) then
output(P, c)
c ← next(P, c)
end while
Here the first procedure should return Λ if there are no candidates at all for instance P.

Qn 2) Weighted interval selection problem
If a list of jobs are given,each job has starting and finishing time,and profit associated with it,
here in order to find maximum profit subset of non overlapping jobs.
Consider the below job with starting time,finishing time and profit.
Input: Number of Jobs n = 4
Job Details {Start Time, Finish Time, Profit}
Job 1: {1, 2, 50}
Job 2: {3, 5, 20}
Job 3: {6, 19, 100}
Job 4: {2, 100, 200}
Output: The maximum profit is 250.

Solution of Weighted interval selection problem
1. Naive Recursive Solution
It is a closed form solution,by which sort the jobs in increasing order of their finish times and
use recursion in order to solve this problem.

1) Initially sort the jobs according to finish time.
2) Apply the recursive process.

findMaximumProfit(arr[], n)
{
a) if (n == 1) return arr[0];
b) Return the maximum of following two profits.
(i) Maximum profit by excluding current job, i.e.,
findMaximumProfit(arr, n-1)
(ii) Maximum profit by including the current job
}
2. Dynamic Programming
It is used for optimization over recursion. Wherever we see a recursive solution that has repeated calls
for same inputs, we can using Dynamic Programming. The idea is to simply store the results of subproblems,
so that we do not have to re-compute them when needed later.
It mainly reduces time complexities from exponential to polynomial. For example, if we write recursive solution for Fibonacci Numbers, we get exponential time complexity and if we storing the solutions of subproblems, time complexity reduces to linear.


Related Solutions

Write Java code for each of the following problem a. Two players, a and b, try...
Write Java code for each of the following problem a. Two players, a and b, try to guess the cost of an item. Whoever gets closest to the price without going over is the winner. Return the value of the best bid. If both players guessed too high, return -1. example: closestGuess(97, 91, 100) → 97 closestGuess(3, 51, 50) → 3 closestGuess(12, 11, 10) → -1 b. Given a non-empty string, return true if at least half of the characters...
For each of the following problems, write up your solutions using the 4-step problem solving procedure...
For each of the following problems, write up your solutions using the 4-step problem solving procedure (get started, plan, execute, evaluate) that is detailed in the problem set rubric. Please include sketches of the problem and words describing the steps, not just the math. 3. Design a current loop that, when rotated in a uniform magnetic field of strength 0.1 T, will produce an emf of ε=ε0 sinωt, where ε0 =110V and ω=120π rad/s.
Try to come up with an example of one occasion when you experienced consumer surplus and...
Try to come up with an example of one occasion when you experienced consumer surplus and one occasion when you experienced producer surplus (two different experiences because you cannot experience consumer and producer surplus at the same time). Explain in detail. How did your experiences affect you personally and how you felt when you purchased or sold the product. Also, explain what would happen to price, quantity, producer surplus, consumer surplus and deadweight loss when either a price floor, price...
Identify three problems in a business and come up with a possible solutions to that business...
Identify three problems in a business and come up with a possible solutions to that business problem that is Information Technology (IT)-related.   .
Come up with the best Genus species of bacteria for each case. Given the following description:...
Come up with the best Genus species of bacteria for each case. Given the following description: Gram (+) cocci arranged in grape-like clusters Non-spore former Produced the enzyme catalase Beta-Hemolytic Produces the enzyme coagulase Acid from mannitol Yellow-gold colony pigment Novobiocin sensitive Options are Micrococcus, Planococcus, or Staphyloccus. Explain the morphology, physiology and virulence factors.
Write functions for each of the following problems. Each problem should be solved by writing a...
Write functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. (a) Write a function that uses recursion to raise a number to a power. The function should take two arguments, the number to be raised to the power (floating point) and the power (a non-negative int). (10 Points) (b) Write a boolean function named isMember that takes two arguments: an array of...
To come up with a problem definition, write up some sample questions you would ask the...
To come up with a problem definition, write up some sample questions you would ask the president of Java Airlines to better help what they would like their software to do. Be Creative in your questions! Write up a mock Problem Definition Statement to summarize what you think the Java Airline software should be. Attention to detail will earn full marks on this assignment.
Recursion practice Write a Java program with functions for each of the following problems. Each problem...
Recursion practice Write a Java program with functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. All of your solutions should be in a single .java file. The main function of the file should demonstrate each of your solutions, by running several tests and producing the corresponding outputs. Write a recursive method to 1. calculate power of a give number 2. multiply...
You’ll need to come up with programs for the substantive audit procedures for each of the...
You’ll need to come up with programs for the substantive audit procedures for each of the functional balance sheet areas (indicated with an asterisk (*) below).   B series*                                  Cash Substantive Audit Documentation C series*                                  Accounts Receivable Substantive Audit Documentation D series*                                  Inventory Substantive Audit Documentation E series*                                  Prepaids Substantive Audit Documentation F series*                                   Property, Plant and Equipment Substantive Audit Documentation I series*                                   Other Assets Substantive Audit Documentation L series*                                  Current Liabilities Substantive Audit Documentation N series*                                  Notes Payable Substantive Audit...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to 10 digits. If the result of the addition is more than 10 digits long, then simply give the output message "Addition overflow" and not the result of the addition. Use arrays to store hexadecimal numerals as arrays of characters. Input Notes: The program reads two strings, each a sequence of hex digits (no lowercase, however) terminated by a "q". Example: 111q AAAq Output Notes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT