ANS:-
CODING TO TRY..
// Using Recursive method to find maxium product
#include <iostream.h>
// Function to get the maximum of two and three integers
int max(int a, int b) { return (a > b)? a : b;}
int max(int a, int b, int c) { return max(a, max(b, c));}
// Returns maximum product obtainable from a rope of length n
int Maxproduct(int n)
{
// cases considered only for rope length greater than 2
if (n == 0 || n == 1) return 0;
// Make a cut at different places and take the maximum of all
int MaximumValue = 0;
for (int i = 1; i < n; i++)
MaximumValue = max(MaximumValue, i*(n-i), Maxproduct(n-i)*i);
// Return the maximum of all values
return MaximumValue;
}
/* Main Program */
int main()
{
cout << "Maximum Product is " << Maxproduct(10);
return 0;
}
Q(1) Given a rope of length n meters, cut the rope in different parts of integer...
5. (20 pts.) Copper Pipes Bubbles has a copper pipe of length n inches and an array of nonnegative integers that contains prices of all pieces of size smaller than n. He wants to find the maximum value he can make by cutting up the pipe and selling the pieces. For example, if length of the pipe is 8 and the values of different pieces are given as following, then the maximum obtainable value is 22 (by cutting in two...
need help in this algorithm question Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...
Suppose you are given n ropes of different lengths, you need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. You want to find the minimum cost way to do this. For example: Suppose you have three ropes with lengths 2, 5, and 8. If you chose first to connect the length 5 and 8 ropes, then connect the length 2 and 13 ropes, the total cost would be...
6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...
You are given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum 2 product you can get. (Example Input: 10, Output: 36, Explanation: 10 = 3 3 4 = 36). What is your answer for n = 82. Write a python code for this
1.Fix any tree T on 10 vertices. Draw the recursion tree of the algorithm Find-size-node when run on the input T with a being the root of T. Can you use this to give a bound on the running time of T? 2. Consider the following problem. Check-BST • Input: A binary tree T • Output: 1 if T is a binary search tree, and 0 otherwise. Give an efficient algorithm for this problem. 3.Give a recursive algorithm for the...
ALGORITHM PROBLEM: A) Significant Inversions: We are given a sequence of n arbitrary but distinct real numbers <a1 , a2 ,..., an>. We define a significant inversion to be a pair i < j such that ai > 2 aj . Design and analyze an O(n log n) time algorithm to count the number of significant inversions in the given sequence. [Hint: Use divide-&-conquer. Do the “combine” step carefully] B) The Maximum-Sum Monotone Sub-Array Problem: Input: An array A[1..n] of...
Need help with all 3 parts. Thanks Question 1 (Longest Common Subsequence) In the longest common sub- sequence algorithm we discussed in class, we formulated the recursive formula based on prefixes of the two inputs, i.e., X[1...) and Y [1..,]. 1. Rewrite the recursive formula using suffixes instead of prefixes, i.e., X[...m] and Y[j..n]. 2. Develop a bottom-up dynamic programming algorithm based on the recur- sive formula in (a). Describe the algorithm and write a pseudo code. 3. Use the...
Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231 Output: 0 This sequence also does not have a majority element (note that the element 1 appears twice and hence is not a majority element). Problem Introduction Majority rule is a decision rule that selects the alternative which has a majority, that is, more than half the votes. Given a sequence of elements (1.02....,On, you would like to check whether it contains an element...
Given the following algorithm: Algorithnm Input: a1, a2,...,an, a sequence of numbers n, the length of the sequence x, a number Output: ?? i:- 1 While (x2 # a, and i < n) i+1 End-while If (x- - a) Return(i) Return(-1) 3, -1, 2,9, 36,-7, 6,4 a) What is the correct output of the Algorithm with the following input: a1, a2,..an b) What is the asymptotic worst-case time complexity of the Algorithm? Algorithnm Input: a1, a2,...,an, a sequence of numbers...