Question

Sum of A1l Integers in a List (SUM) Input A list of integers Ala.. b] Output : s-Σ-, A[i] Let S(Ala...b]) represent the output of the SUM problem on input Ala..b 4 points) 5. Statetwo different elf-reductions for the SUM problem. Usethe self-reduction examples from lecture as a guide. (4 points) 6. Give recursive algorithms based on your divide and conquer self-reductions to solve the SUM problem. (2 points) 7. What are the worst case runtimes of the solutions you have generated. (Just state the runtimes. You do not need to show your work.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1



FindMaxSumSubArray(arr[],low,high){

     //The array is empty
     if (low > high)
        return 0;
     //only one element is present in the array
     if (low == high)
        return max(0, arr[low]);
      
     //finding the middle element of the array
     mid = (low + high) / 2;
  
     // find maximum sum crossing to left
     leftMax = sum = 0;
     for (i = mid; i ≥ low; i--) {
        sum += arr[i];
        if (sum > leftMax)
            leftMax = sum;
     }
  
     //find maximum sum crossing to right
     rightMax = sum = 0;
     for (i = mid+1; i ≤ high; i++) {
        sum += arr[i];
        if (sum > rightMax)
            rightMax = sum;
     }
   
     // Return the maximum of leftMax, rightMax and their sum
     return Math.max(leftMax + rightMax,
     Math.max(FindMaxSumSubArray(low, mid), FindMaxSumSubArray(mid+1, high)));
}

The worst case time complexity of the algorithm is O(n log n).

Add a comment
Know the answer?
Add Answer to:
Sum of A1l Integers in a List (SUM) Input A list of integers Ala.. b] Output...
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
  • For [Select], there are three choices: worse than, the same as, better than Answer the following...

    For [Select], there are three choices: worse than, the same as, better than Answer the following questions about the computational properties of divide-and-conquer sorting algorithms, based on tight big-Oh characterizations of the asymptotic growth rate of the functions for the running time or space size, depending on the question. Assume that the input sequence is given as a list, and the output sequence is also a list. Also assume a general implementation of the sorting algorithms, as opposed to an...

  • Consider the following problem: Input: a list of n-1 integers and these integers are in the...

    Consider the following problem: Input: a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers from 1 to n is missing in the list. Output: find the missing integer Let the input array be [2, 4, 1, 6, 3, 7, 8]. Elements in this list are in the range of 1 to 8. There are no duplicates, and 5 is missing. Your algorithm needs...

  • Q1. Write an algorithm (pseudocode or flowchart) for the following problem. Input: Eight integers Output: the...

    Q1. Write an algorithm (pseudocode or flowchart) for the following problem. Input: Eight integers Output: the sum of even numbers only. Example: Let the eight integers are 2, 9, 3, 20,5,17, 10, 6 then S = 2+20+10+6 = 38

  • Algorithm MyAlgorithm (A,B) Input: Arrays A and B each storing n >= 1 integers. Output: What...

    Algorithm MyAlgorithm (A,B) Input: Arrays A and B each storing n >= 1 integers. Output: What is the output? (Refer to part b below) Start: count = 0 C = 10 for i = 0 to C do { sum = 0 for j = 0 to n-1 do { sum = sum + A[0] for k = 1 to j do sum = sum + A[k] } if B[i] == sum then count = count + 1 } return...

  • Let T(n) denote the worst case running time of an algorithm when its input has size...

    Let T(n) denote the worst case running time of an algorithm when its input has size n. In divide and conquer algorithms, T(n) is often expressed using a recursion. Hence, expressing T(n) in terms of the big-Oh notation requires a bit of work. There are many ways of determining the growth rate of T(n). In class, I’ve shown you how to do it by drawing the recursion tree. Here are the steps: (1) draw the recursion tree out, (2) determine...

  • a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n...

    a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...

  • urgent L. Consider the following pseudocode for finding binomial coefficients: Binom(n, r) Input: integers n and r Output: n choose r if r-0 or r-n thern return 1 end else return Binom(n-1, r-1) B...

    urgent L. Consider the following pseudocode for finding binomial coefficients: Binom(n, r) Input: integers n and r Output: n choose r if r-0 or r-n thern return 1 end else return Binom(n-1, r-1) Binom(n-1, r); end running time of this algorithm. Prove your bound for the upper bound. (5 points) Rewrite the above algorithm so that it is efficient. (You have 2 choices!) Analyze the worst case time of your new algorithm. (5 points) Find the edit distance between "SPOKE...

  • Adder Design FAO FA1 B A Cin B Coub die los - S doo Problem 4.1...

    Adder Design FAO FA1 B A Cin B Coub die los - S doo Problem 4.1 (17 points) Design a fast 4 bit ripple-carry adder using the two full adder cells shown in Figure 4 and CMOS inverters. Label the inputs A[3:0), B(3:0), Cin and the outputs S(3:0) and Cout. Assume the delay through an inverter tiny = 4ps, the delay from any input to the full adder carry output is tc. = 7ps and to the sum output is...

  • For the remainder of this problem, the signals (t) and y(t) denote the input and output, respecti...

    For the remainder of this problem, the signals (t) and y(t) denote the input and output, respectively, of a stable LTI system whose (double-sided) frequency response is known to be w-4m 27T 4m H(w) = rect ( 2π with rect(t) denoting the unit-pulse function i.e., rect(t) 1 for lt| < 1/2 and is zero otherwise. Hint: Use sketches as a guide for answering each question most efficiently. (c) (15 points) Determine y(t) for all t given the applied input is...

  • Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement...

    Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...

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