Question

Design And analysis algorithm course .



Remarks: In all the algorithms, always explain their correctness and analyze their com- plexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit

Question 2: Give an algorithm that finds the maximum size subarray (the entries may not be contiguous) that forms an increasing sequence.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

P = array of length N
M = array of length N + 1

L = 0
for i in range 0 to N-1:
// Binary search for the largest positive j ≤ L
// such that X[M[j]] < X[i]
lo = 1
hi = L
while lo ≤ hi:
mid = ceil((lo+hi)/2)
if X[M[mid]] < X[i]:
lo = mid+1
else:
hi = mid-1

// After searching, lo is 1 greater than the
// length of the longest prefix of X[i]
newL = lo

// The predecessor of X[i] is the last index of
// the subsequence of length newL-1
P[i] = M[newL-1]
M[newL] = i

if newL > L:
// If we found a subsequence longer than any we've
// found yet, update L
L = newL

// Reconstruct the longest increasing subsequence
S = array of length L
k = M[L]
for i in range L-1 to 0:
S[i] = X[k]
k = P[k]

return S

Add a comment
Know the answer?
Add Answer to:
Design And analysis algorithm course . Remarks: In all the algorithms, always explain their correctness and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design And analysis algorithm course Remarks: In all the algorithms, always explain their correctness and analyze...

    Design And analysis algorithm course Remarks: In all the algorithms, always explain their correctness and analyze their com- plexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit Question 3: Given a gas station with two pumps, and a collection of cars 1, 2, n with filling time si for item i (on both pumps). Find a schedule that assigns cars to the two pumps, so that if the first...

  • Remarks: In all the algorithms, always explain their correctness and analyze their complexity. The complexity should...

    Remarks: In all the algorithms, always explain their correctness and analyze their complexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit. Say that we are given a rooted tree so that any element in the tree has a profit. An independent set in the tree is a collection of vertices no two of which are a parent and a child. The goal is to find an independent set of...

  • Remarks: In all algorithm, always prove why they work. ALWAYS, analyze the com- plexity of your a...

    Please explain Remarks: In all algorithm, always prove why they work. ALWAYS, analyze the com- plexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. In all data structures, try to minimize as much as possible the running time of any operation. . Question 4: 1. Say that we are given a mazimum flow in the network. Then the capacity of one of the...

  • Remarks: All the graphs here are without self loops and parallel edges, and anti-parallel edges. When...

    Remarks: All the graphs here are without self loops and parallel edges, and anti-parallel edges. When we speak of a flow network, we mean there are capacities c(e) ? 0 on the edges, the graph G is directed with a source s and a destination t. In all the algorithms, always explain their correctness and analyze their complexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit. • Question 3:...

  • Give an algorithm that finds the maximum size subarray that is increas- ing (the entries may...

    Give an algorithm that finds the maximum size subarray that is increas- ing (the entries may not be contiguous. It may be any set but you need to keep the order.). In the above array the maximum non contiguous increasing subset is 1, 2, 4, 6, 8, 9, 14, 16, 30 that forms an increasing sequence. There are no other array provided in this question, thank you

  • In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms....

    In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms. In all algorithms, always try to get the fastest possible. A matching M = {ei} is maximal if there is no other matching M' so that M ⊆ M' and M /= M' . Give an algorithm that finds a maximal matching M in polynomial time. The algorithm should be in pseudocode/plain English. Provide the complexity of the algorithm as well.

  • Question 3: Give an algorithm that finds the maximum size sub-array that is increasing (the entries...

    Question 3: Give an algorithm that finds the maximum size sub-array that is increasing (the entries may not be contiguous. It may be any set but you need to keep the order). In the array, A = [1, 7, 2, 5, 4, 6, 8, 9, 3, 14, 16, 11, 30], the maximum non contiguous increasing subset is 1, 2, 4, 6, 8, 9, 14, 16, 30 that forms an increasing sequence. Please explain the algorithm in words and state the...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

  • Create a cause and effect diagram for the following case: Case Study Eastern Gear,Inc.: Job Shop...

    Create a cause and effect diagram for the following case: Case Study Eastern Gear,Inc.: Job Shop Eastern Gear, Inc., in Philadelphia, Pennsylvania, is a manufacturer of custom-made gears ranging in weight from a few ounces to over 50 pounds. The gears are made of different metals, depending on the customer's requirements. Over the past year, 40 different types of steel and brass alloys have been used as raw materials. See Exhibit 1 for details. be necessary to stop production and...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT