Question

Write an algorithm that takes an array B and a number N as inputs. Suppose that...

Write an algorithm that takes an array B and a number N as inputs.

Suppose that the array B contains n distinct numbers. Compute the sum of the N largest numbers in the array B.

Example: if the array B= [4, 5, 8, 11, 3] and N = 3, then the algorithm should return 24 (11+8+5).

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

S01E pseudocode Go) algorithm : start If N>n Then print given length is greater than arrays length Else Sort the array in

Add a comment
Know the answer?
Add Answer to:
Write an algorithm that takes an array B and a number N as inputs. Suppose that...
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
  • Write a function called addNeighbors that takes an array of numbers and adds each number in...

    Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next to it. The array will always have an even number of numbers in it. In the end you should return an array of neighbors added up. Please use JavaScript Instructions from your teacher. Medium Question #4 Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next...

  • 2. Suppose that you are given an translating the algorithm for inputs of size 4 into...

    2. Suppose that you are given an translating the algorithm for inputs of size 4 into a decision tree, you find that the decision tree has no leaf corresponding to the permutation (3,1,2,4). Write down input of 4 distinct 2-digit numbers that will not be sorted correctly by the given algorithm algorithm for sorting all sets of distinct integers. After an 2. Suppose that you are given an translating the algorithm for inputs of size 4 into a decision tree,...

  • Write a program in C++ language that finds the largest number in an array of positive...

    Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in the...

  • Problem 3: (5 2 points) Design an algorithm that takes an array of positive integers A...

    Problem 3: (5 2 points) Design an algorithm that takes an array of positive integers A of length n and a positive integer T as an input and finds the largest N < T such that N can be written as a sum of some elements of A and returns such a representation of N. The complexity of the algorithms has to be O(nT). For example, for A 3,7, 10 and T 19, the output is 17 7+10, because we...

  • Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algo...

    need help in this algorithm question Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...

  • Modify the algorithm to solve the problem of finding the k-th largest number in array A

    Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1≤k≤n, without sorting the entire array. Partsof the algorithm are given below. Fill in the blanks.                 Select-k-th-largest(A: Array [1..n] of numbers)                 1               for _____________________                 2                                 ________________                 3                                 for _____________________                 4                                                   if _______________ then ___________                 5                                 if position ≠ i then                 6                                                   temp=A[i]                 7                                                   A[i]=A[position]                 8                                                   A[position]=temp

  • Help pls for assignment 2. Write an algorithm to display up to 10 user inputs 3....

    Help pls for assignment 2. Write an algorithm to display up to 10 user inputs 3. Write an algorithm to display print first 5 items in a collection. 4. Write an algorithm to read in 3 numbers. Display the largest number.

  • Suppose we have an array that contains tuples. These tuple contains three positive numbers. Implement an...

    Suppose we have an array that contains tuples. These tuple contains three positive numbers. Implement an algorithm that counts how many distinct tuple that an array has(contains same number in same order). ex) [(1, 2, 1), (2, 2, 2), (3, 8, 3), (1, 2, 1), (3, 4, 3)] gives 4. 1 The algorithm should be implemented in Python3. 2 The function must have average-case runtime of O(n). You can assume Simple Uniform Random Hashing. 3 Python built-in dictionary cannot be...

  • Write a simple algorithm to search for the number 99 in the sorted array, A[n]: 5,16,27,38,49,105,216,398,...

    Write a simple algorithm to search for the number 99 in the sorted array, A[n]: 5,16,27,38,49,105,216,398, where n=8. Implement a simple selection algorithm on A(n) and give the output sorted array for the array, A[10]: 33,99,108,54,13,1999,56,-35,88,-16. Find a close formula for the Fibonacci Sequence F(n), F(n)=F(n-1)+F(n-2) and F(0)=0, F(1)=1. Also describe an application example of the Fibonacci Sequence.

  • I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is...

    I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...

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
ADVERTISEMENT