1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex
3 years ago
12

A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S. For example, if S is 5,15,-30,10,-5,

40,10 then 5,15,-30 is a contiguous subsequence but 5,15,40 is not.
1. Give a linear-time algorithm for the following task:
Input: A list of numbers, A(1), . . . , A(n).
Output: The contiguous subsequence of maximum sum (a subsequence of length zero has sum zero).
For the preceding example, the answer would be 10,-5,40,10 with a sum of 55.
Computers and Technology
1 answer:
Sindrei [870]3 years ago
4 0

Answer:

We made use of the dynamic programming method to solve a linear-time algorithm which is given below in the explanation section.

Explanation:

Solution

(1) By making use of the  dynamic programming, we can solve the problem in linear time.

Now,

We consider a linear number of sub-problems, each of which can be solved using previously solved sub-problems in constant time, this giving a running time of O(n)

Let G[t] represent the sum of a maximum sum contiguous sub-sequence ending exactly at index t

Thus, given that:

G[t+1] = max{G[t] + A[t+1] ,A[t+1] } (for all   1<=t<= n-1)

Then,

G[0] = A[0].

Using the above recurrence relation, we can compute the sum of the optimal sub sequence for array A, which would just be the maximum over G[i] for 0 <= i<= n-1.

However, we are required to output the starting and ending indices of an optimal sub-sequence, we would use another array V where V[i] would store the starting index for a maximum sum contiguous sub sequence ending at index i.

Now the algorithm would be:

Create arrays G and V each of size n.

G[0] = A[0];

V[0] = 0;

max = G[0];

max_start = 0, max_end = 0;

For i going from 1 to n-1:

// We know that G[i] = max { G[i-1] + A[i], A[i] .

If ( G[i-1] > 0)

G[i] = G[i-1] + A[i];

V[i] = V[i-1];

Else

G[i] = A[i];

V[i] = i;

If ( G[i] > max)

max_start = V[i];

max_end = i;

max = G[i];

EndFor.

Output max_start and max_end.

The above algorithm takes O(n) time .

You might be interested in
Write any two reasons why files are stored in folders​
iogann1982 [59]

Answer:

Explanation:

The answer is The tree structure suggests the main benefit of folders: to organize your files. You can create folders to store and organize your pictures, your documents, your videos, and so on. Folders are also used to separate the files created by different users.

4 0
3 years ago
Read 2 more answers
Does anyone have 2.19.4 Guess a number 2.0 code for codehs?
lubasha [3.4K]

Answer:

I'm trying to create a program that will ask the user for an exam score in the range 0 to 100. ... I want to take the python course but I have not class code, anyone can help?

Explanation:

3 0
3 years ago
What is a generic phone
Zina [86]

Explanation:

Generic Android Device means the Android devices which does not any specific brand name or they can not be related to any specific class or brand. For ex: Samsung developed Epic 4g Touch Android device but they later removed lot of fancy features and stuffs from it launched with Galaxy S.

3 0
3 years ago
Read 2 more answers
Write a program to calculate the volume of a cube which contains 27 number of small identical cubes on the basis of the length o
Brrunno [24]

Answer:

<em>This program is written in python programming language.</em>

<em>The program is self explanatory; hence, no comments was used; However, see explanation section for line by line explanation.</em>

<em>Program starts here</em>

length = float(input("Length of small cube: "))

volume = 27 * length**3

print("Volume: "+(str(volume)))

Explanation:

The first line of the program prompts the user for the length of the small cube;

length = float(input("Length of small cube: "))

The volume of the 27 identical cubes is calculated on the next line;

volume = 27 * length**3

Lastly, the calculated volume of the 27 cubes is printed

print("Volume: "+(str(volume)))

4 0
3 years ago
Please tell fast plzzzzzzzzzz​
Svetlanka [38]

Answer:

<!DOCTYPE html>

the declaration ye

Explanation:

probably it ye

3 0
3 years ago
Other questions:
  • What is the accounting equation?
    12·1 answer
  • If you have a rubric, “your teacher can prove you knew what you were supposed to do.” T/F
    10·2 answers
  • Which step comes between identifying i need and generating ideas in a technological design process
    10·1 answer
  • You are required to justify the need to implement a collapsed core network. Which justification below makes sense for a collapse
    7·1 answer
  • To activate Spelling and Grammar check using the ribbon, navigate first to the _____ tab
    14·2 answers
  • What is the meaning of the concept (atomically)
    11·1 answer
  • Which command is used to copy entire folder structures between volumes or across a network while maintaining all NTFS file permi
    10·1 answer
  • Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to points Distance. The calculation is:
    12·1 answer
  • What information most likely presents a security risk on your personal
    6·1 answer
  • Please help me to creat flow chart tq​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!