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
On early computers, every byte of data read or written was handled by the CPU (i.e., there was no DMA). What implications does t
grandymaker [24]

Answer:

Multiprogramming will be extremely difficult to be achieved.

Explanation:

If every byte of data read or written is handled by the CPU the implications this will have for multiprogramming are not going to be satisfactory.

This is because, unlike before, after the successful completion of the input and output process, the CPU of a computer is not entirely free to work on other instructions or processes.

5 0
3 years ago
(Java) Can anyone help me with this ?? The skeleton of the code must be same as the image.
Kay [80]
Is that a essay ur supposed to write

6 0
3 years ago
Please answer the following will mark brainiest except the first 3 rest all
ollegr [7]

Answer:

1) Standalone machine

2) Local

3) Either Wide area network(WAN) or a web

Done your first 3

6 0
3 years ago
In HTML, what is an element?
klio [65]

An element is what makes up the HTML long story short.

8 0
3 years ago
Read 2 more answers
Prolog uses ____. Select one: a. lowercase for variable names, and uppercase for constants and functions b. uppercase for variab
Afina-wow [57]

Answer:

b) uppercase for variable names, and lowercase for constants and functions  

Explanation:

Given

Programming language: prolog

Required

The case type for variables, constants and functions

In prolog,

Variable names begin with uppercase

e.g. Name, NAME

While constants and functions begin with lowercase

e.g. name, addnumbers()

<em>Hence, (b) is correct</em>

6 0
3 years ago
Other questions:
  • Which type of lenses shrinks the image in front of it rather than magnifying it? A)Telephoto B)Optical zoom C)Digital zoom D)Wid
    10·1 answer
  • / List the seven basic internal components found in a computer tower.
    5·2 answers
  • A ___________ organizes related commands together, under a tab.
    15·1 answer
  • You are reviewing the style sheet code written by a colleague and notice several rules that are enclosed between the /* and */ c
    12·1 answer
  • Which of the following is not true about designing classes? In order for class information to be printed instead of a memory add
    12·1 answer
  • Write an expression that will print "in high school" if the value of user_grade is between 9 and 12 (inclusive). Sample output w
    12·1 answer
  • #include #include int main( ) { int value = 10; int pid; value += 5; pid = fork( ); if (pid &gt; 0 ) { value += 20; } printf(val
    10·1 answer
  • Which of the following would you not see on a windows 10 start menu?
    6·1 answer
  • What is the google search operator that limits results to a specific domain?
    8·1 answer
  • If Tamya makes $1000.00 gross monthly income and her total payroll deductions are $294.00, what is her net income?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!