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
Does anybody know how to unlock websites from school computer
Grace [21]

Answer:

yes go to settings then apps

Explanation:

that's how I did mines

8 0
2 years ago
Obtain the 10’s complement of the following six-digit decimal numbers:<br><br> 123900<br><br> 980657
zysi [14]

Answer:

876100

019343

Explanation:

10s complement of a decimal number is obtained by the following process:

- Obtain 9s complement ( Subtract each digit by 9)

- Add 1 to the result

1) 123900

9s complement => (9-1)(9-2)(9-3)(9-9)(9-0)(9-0)

= 876099

Adding 1 , 10s complement of 123900 = 876100

2) 980657

9s complement = (9-9)(9-8)(9-0)(9-6)(9-5)(9-7)

= 019342

Adding 1 , 10s complement of 980657 = 019343

7 0
3 years ago
I don't know what to do for these two questions
Rainbow [258]
我沒有看到問題?如果您可以在此問題上發布問題,那將非常有幫助!
6 0
2 years ago
Newt Corporation, headquartered in Los Angeles, is a nationwide provider of educational services to post-graduate students. Due
zysi [14]

Answer:

Option B i.e., Circuit level gateways only enable data to be inserted into a network which is the product of system requests within the network.

Explanation:

In the above question, some details are missing in the question that is options.

Option B is valid because Circuit level gateways are not the transmission inspection, always require information into such a server resulting through system appeal inside the server through maintaining a record for connections that are sent into the server and only enabling information in this is in answer to such queries.

Other options are incorrect because they are not true according to the following scenario.

5 0
3 years ago
What part of a resource record tells a server how long the record should remain in the cache?
V125BC [204]
Time-to-live or TTL <span>tells a server how long the record should remain in the cache.
TTL is a mechanism that limits the lifetime of data in a network or a computer and prevents data packets from circulating indefinitely.
</span><span>It also improves the caching and privacy of networks and computers.</span>
8 0
3 years ago
Other questions:
  • A user saves a password on a website the user logs into from a desktop. Under which circumstances will the password be saved on
    14·1 answer
  • Which certification can help enhance your job prospects in the role of a computer programmer?
    6·2 answers
  • Which of the following is not a common network architecture type?
    9·1 answer
  • When preparing a document flowchart, the names of organizational departments or job functions should appear in theA) column head
    6·1 answer
  • What activities are the most likely to infect your computer vith a virus? Check all that apply.
    10·1 answer
  • Determine the exact output of the code $str = "The quick brown fox jumps over the the lazy dog"; echo strpos($str, 'fox');
    6·1 answer
  • People who enjoy working with their hands might enjoy a career as a/an
    9·1 answer
  • A computer equipped with fingerprint recognition software, which denies access to a computer to anyone whose fingerprint is not
    15·1 answer
  • Samantha is part of a project management team working on the initiation phase of a project. What is her team expected to do in t
    5·2 answers
  • Pls paanswer asap......​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!