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
BigorU [14]
2 years ago
11

Write two recursive versions of the function minInArray. The function will be given a sequence of elements and should return the

minimum value in that sequence. The two versions differ from one another in the technique we use to pass the sequence to the function. In version 1 – The prototype of the function should be: int minInArray1(int arr[], int arrSize) Here, the function is given arr, an array of integers, and its logical size, arrSize. The function should find the minimum value out of all the elements in positions: 0, 1, 2, …, arrSize-1. In version 2 – The prototype of the function should be: int minInArray2(int arr[], int low, int high) Here, the function is given arr, an array of integers, and two additional indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should find the minimum value out of all the elements in positions:
Computers and Technology
1 answer:
Viktor [21]2 years ago
7 0

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;//using namespace

int minInArray1(int arr[],int arrSize)//declaring method minInArray1

{

if(arrSize == 1)//use if block to check arrSize value is equal to 1  

{

return arr[0];//return first element of array

}

else //defining else block

{

int max= minInArray1(arr, arrSize-1);//use integer variable max to call method recursively  

if(arr[arrSize-1] < max)//use if block to check array value  

{

max = arr[arrSize-1];//use max to hold array value

}

return max;//return max variable value

}

}

int minInArray2(int arr[], int low, int high)//defining a method minInArray2  

{

if(low == high) //use if to check low and high variable value are equal

{

return arr[low];//return low variable value

}

else //defining else block

{

int minimum = minInArray2(arr, low+1, high);//defining integer variable minimum to call method minInArray2 recursively

if(arr[low] < minimum)

{

minimum = arr[low];//use minimum variable to hold array value

}

return minimum;//return minimum value

}

}

int main()//defining main method

{

int arr[10] = { 9, -2, 14, 12, 3, 6, 2, 1, -9, 15 };//defining an array arr

int r1, r2, r3, r4;//defining integer variable

r1 = minInArray1(arr, 10);//use r1 variable to call minInArray1 and hold its return value

r2 = minInArray2(arr, 0, 9);//use r1 variable to call minInArray2 and hold its return value

cout << r1 << " " << r2 << endl; //use print method to print r1 and r2 variable value

r3 = minInArray2(arr, 2, 5);//use r3 variable to call minInArray1 and hold its return value

r4 = minInArray1(arr + 2, 4); //use r4 variable to call minInArray2 and hold its return value

cout<<r3<< " " <<r4<<endl; //use print method to print r3 and r4 variable value

return 0;

}

Output:

please find the attached file.

Explanation:

In the given code two methods, "minInArray1 and minInArray2" is defined,  in the "minInArray1" it accepts two-variable "array and arrSize" as the parameter, and in the "minInArray2" method it accepts three integer variable "array, low, and high" as the parameter.

  • In the "minInArray1" method, and if the block it checks array size value equal to 1 if the condition is true it will return the first element of the array, and in the else block the max variable is defined, that calling method recursively
  • and store its value.
  • In the "minInArray2" method, an if the block it checks low and high variable value is equal. if the condition is true it will return a low array value. In the next step, the minimum value is defined, which checks the element of the array and uses a low array to store its value.
  • In the main method an array and four integer variable "r1, r2, r3, and r4" is defined, which calls two methods "minInArray1 and minInArray2" and use print method to print its value.
You might be interested in
The three basic processes of memory are ______.
marysya [2.9K]

Answer:

The correct answer is letter "C": encoding, storage, retrieval.

Explanation:

In psychology, the stages of memory are <em>encoding, storage, </em>and <em>retrieval</em>. Encoding refers to changing the information as it is received so it can be stored in the memory and imply inputs in three kinds: <em>visual (pictures), acoustic (sounds), </em>and<em> semantic (meaning)</em>. Storage is the stage in which the input is retained in the memory, where it is stored, and for how long. Finally, retrieval implies organizing information stored in the memory to recall it.

6 0
2 years ago
A large global retail corporation has experienced a security breach, which includes personal data of employees and customers.
sergeinik [125]

The act that  Accenture would offer as the best solution to ensure enhanced security in the future is Data Protection program.

<h3>What is Accenture  about?</h3>

In Keeping client data protected, Accenture’s Information Security Client is known to be well built up with Data Protection program that can help client teams with a good approach and the security controls, etc.

Therefore, The act that  Accenture would offer as the best solution to ensure enhanced security in the future is Data Protection program.

Learn more about Accenture from

brainly.com/question/25682883

#SPJ1

5 0
2 years ago
Complete the following sentences using each of the words provided ONCE only. KEYBOARD DESKTOP STORE PRINTER COMPUTER MOUSE MONIT
WARRIOR [948]

Answer:

Explanation:

Monitor is an electronic device that retrieves, and processes shows you what is going on in the computer.

Desktop is the first image you see on your screen when the computer is is used for telling the computer what to do.

keyboard

is used for typing documents. Printer is used for putting documents on paper. CD Bay you can insert a CD or Compact Disc. is is box inside and shaped

8 0
1 year ago
Which of the following best describes the safety of blogging
Pavlova-9 [17]
We need the options
3 0
3 years ago
How can people efficiently and effectively influence lots of people throughout the world
tatuchka [14]

Answer:

The word efficient denotes the ability to achieve a good goal toward a person, and effectiveness denotes reliable production or achievement.

Explanation:

Many people around the world can set efficient goals, that is, to influence or encourage other people to make good projects or changes in their lives, by example or simply teach them with patience and altruism.

In this way effectiveness will be seen, that is, the product or the achievement precisely when we observe how people undertake new projects in their lives

3 0
3 years ago
Other questions:
  • What is the size of the key space if all 8 characters are randomly chosen 8-bit ascii characters?
    6·1 answer
  • What software is typically used for larger systems?
    11·1 answer
  • When driving, your attention is __________.
    5·2 answers
  • A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servings in the bag and that a se
    10·1 answer
  • Bytes are typically represented with a lowercase b and bits with an uppercase B.<br> true or false
    7·1 answer
  • The World Wide Web Consortium enforced a stricter set of standards in a different version of Hypertext Markup Language (HTML) ca
    7·1 answer
  • How do you change the top and bottom margins of an entire document?
    7·2 answers
  • Could someone please help me with this?
    8·1 answer
  • Features of Python are *
    9·1 answer
  • Which is NOT true?<br> 9 + 4 = 17 - 4<br> 8 + 7 = 14 + 3<br> 11 = 19 - 8<br> 5 + 8 = 20 - 7
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!