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
2 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]2 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
Rank these three account types in order of decreasing liquidity. Start by picking the most liquid account type first
Ghella [55]
As there are no options given, I will simply mention the three most liquid accounts in order:

<span>1. Checking Account
2. Savings Account
3. Money Market Deposit Account

Account liquidity refers to the ease and comfort with which you can take your money out of an account from a bank, there are various bank accounts which can be referred to as liquid assets.</span>
5 0
3 years ago
Read 2 more answers
Give 3 reasons why it is believed that smart phones precent us from communicating face to face.give three reasons why it is beli
gregori [183]

Answer:

yes

Explanation:

because the people will be lazy to go and talk to that person instead They will call each other and discuss

7 0
1 year ago
Which of the following costs should be considered when providing your own Web server instead of using a cloud service provider o
jenyasd209 [6]

Answer:

A hardware and software support technician

Explanation:

If you provide your own web server, you also need <em>hardware and software support technicians</em> who will configure, manage, maintain and handle failures.

<em>A Web development team</em> is needed either you own your server or you are on cloud.

<em>The flexible subscription fee that varies upon the resources used </em>is an option in cloud.

<em>The market</em> does not response directly to the decision of server hosting

8 0
2 years ago
What are the two ways to print a document?
guajiro [1.7K]

Answer:

ctrl+p or find the print button on the page

5 0
3 years ago
If a surface is. it is exactly vertical
Jobisdone [24]
What are the choices
8 0
3 years ago
Other questions:
  • To join two or more objects to make a larger whole is to _____________ them.
    8·2 answers
  • What type of organizational structure would you want to use for this company (by function, by process, by product, and so on)? E
    11·1 answer
  • In a computerized accounting system, each transaction that is analyzed must be entered by hand into the appropriate journal and
    12·2 answers
  • Why did artists use pinhole cameras during the renaissance?
    8·1 answer
  • What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = p
    7·1 answer
  • When you touch a hot stove, along which pathway will the impulses travel and what is the final destination in the cns?
    12·1 answer
  • If your TV was showing a flat black or blue screen, or had "snow", what steps would you take to fix it?
    13·1 answer
  • SOLVE IN C:
    10·1 answer
  • when inserting a bibliography one choose from multiple ______ of bibliographies.[insert Bibliography]
    12·1 answer
  • Escribe 10 ejemplos de lo que consideras un byte
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!