Question

DETAILED PSEUDOCODE WITH EXPLANATION OR FLOWGORITHM NEEDED. (It's all I'm familiar with at this time) Design...

DETAILED PSEUDOCODE WITH EXPLANATION OR FLOWGORITHM NEEDED. (It's all I'm familiar with at this time)

Design a function that accepts an array and the array's size as arguments, and returns the largest value in the array. The method should use recursion to find the largest element.

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

/*
   Function that accepts an array and the array's size as arguments, and returns the largest value in the array.
   Pre-condition : array must be atleast of size 1
   Post-condition : returns the largest element of the array
   array : array of number which starts from 0,1,..,size-1
   size : number of elements in the array
*/

function getLargest(number array[], number size)
   // base condition : if size of array is 1, return it
   if(size ==1 ) then
       return array[0]; // since array index starts from 0, we access the element using size-1
   end if;
  
   // recursive condition
   // get the largest element of the array from 0,1,..,size-1
   int largest = getLargest(array,size-1); // return the largest element from the sub-array from [0,size-1)
  
   // if the largest element obtained from the array from [0,size-1) is less than element at array[size-1]
   // then return the element at array[size-1]
   if(largest < array[size-1]) then
       return array[size-1];
   else // else return largest
       return largest;
      
end getLargest ;

Add a comment
Know the answer?
Add Answer to:
DETAILED PSEUDOCODE WITH EXPLANATION OR FLOWGORITHM NEEDED. (It's all I'm familiar with at this time) Design...
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
  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a...

    C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional...

  • Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function...

    Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function SumKSmallest(A[0..n – 1), k) that returns the sum of the k smallest elements in an unsorted integer array A of size n. For example, given the array A=[6,-6,3,2,1,2,0,4,3,5] and k=3, the function should return -5. a. [3 marks) Write an algorithm in pseudocode for SumKSmallest using the brute force paradigm. Indicate and justify (within a few sentences) the time complexity of your algorithm. b....

  • In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays...

    In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain...

  • C# QUESTION Requirements Your task is to write a program that will print out all the s of the com...

    C# QUESTION Requirements Your task is to write a program that will print out all the s of the command line arguments to a program For example, given the arguments 'gaz, wx,and 'edc, your program should output wsxaazea Your implementation is expected to use Heap's algorithm according to the following pseudocode: procedure generatelk: integer, A: array of any): if k 1 then output A) else // Generate permutations with kth unaltered //Initially k length(A) // Generate permutations for kth swapped...

  • Can someone please help, third time I'm asking. I need a basic javascript with no push...

    Can someone please help, third time I'm asking. I need a basic javascript with no push or splice command. Please don't post a picture of the code,because my vision is poor and I won't be able to see it. Also, I need breakdown of what's in HTMLand what' s in javascript. All requirements are below. Thanks for your help. This is a 2 part assignment, but both parts can be completed in one program. Also, please follow ALL Required Programming...

  • HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge...

    HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge sort (on arrays). Create a public non-final class named Mergesort that extends Merge. Implement a public static method int[] mergesort(int[] values) that returns the input array of ints sorted in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. If the passed array is null you should return null. If the...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Public class Permutations { // Helper method for outputting an array. private static v...

    public class Permutations { // Helper method for outputting an array. private static void PrintArray(string[] array) { foreach (string element in array) { Console.Write($"{element} "); } Console.WriteLine(); } // Helper method for invoking Generate. private static void Generate(string[] array) { Generate(array.Length, array); } public static void Main(string[] args) { } } procedure generate(k : integer, A : array of any): if k = 1 then output(A) else // Generate permutations with kth unaltered // Initially k == length(A) generate(k -...

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