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
Serjik [45]
3 years ago
9

3. (20 points) Write a C++ recursive function that finds the maximum value in an array (or vector) of integers without using any

loops. (a) Test your function using different input arrays. Include the code. i. ii. (b) Write a recurrence relation that represents your algorithm. i. T(n) = T(n-1) + O(1) (c) Solve the recurrence relation and obtain the running time of the algorithm in Big-O notation.
Computers and Technology
1 answer:
Luden [163]3 years ago
5 0

Answer:

Following are the code to this question:

In option (i):

#include <iostream>//defining header file

using namespace std;

int findMax(int B[], int x)//defining recursive method findMax

{

if (x == 1)//defining condition when value of n==1

return B[0];//return array first element

return max(B[x-1], findMax(B, x-1)); // calling recursive method inside max method and return value

}

int main() //defining main method  

{

int B[] = {12, 24, 55, 60, 50, 30, 29};//defining array B

int x= 7;//defining integer variable and assign a value

cout << "Maximum element value of the array is: "<<findMax(B, x)<<endl;//calling method findMax and print value

return 0;

}

Output:

Maximum element value of the array is: 60

In option (ii):

\Rightarrow \ T(n) = 1 + T(n-1)\\\Rightarrow  1 + 1 + T(n-2)\\ \Rightarrow  1 + 1 + 1 + ... n \ times \\\Rightarrow  O(n) \\

Explanation:

In the above-given program a recursive method "findMax" is defined, which accepts an array "B" and an integer variable "n" in its parameter, inside the method a conditional statement is used that, checks value of x equal to 1.

  • If the above condition is true it will return the first element of the array and find the max number.
  • Inside the main method, an array B is declared that assigns some values and an integer variable is declared, that also assigns some values, in the last step print method is used that pass value in method and prints its return value.
  • In the option (ii) we calculate the Big-O notation algorithm value.
You might be interested in
Is there a way I can put an already made sound that i created over an already made video
lys-0071 [83]
If you're using an apple product to do video editing, then iMovie is probably the best way to do that.

If you're on Windows and you're looking for a free video editing website, I'd suggest WeVideo. Although WeVideo does add watermarks to your videos, editing is pretty easy when using it.
6 0
3 years ago
TASK 1. JUMBLE ME! Direction: Arrange the jumbled letters to form a word. 1. PEREAM 2. RRENT CU 3. METREMO H 4. TORSISER 5. TANC
ivanzaharov [21]

The Rearrangement of the words are:

  1. Ear map
  2. Rent cup
  3. METREON
  4. Sister or
  5. Sister Cane

<h3>What is arrangement of words?</h3>

A sorting method is known to be the orders of entries that are based on each word or phrase found in a heading, e.g. spaces, etc.

The Rearrangement of the words are:

  1. Ear map
  2. Rent cup
  3. METREON
  4. Sister or
  5. Sister Cane

Learn more about Arrangement from

brainly.com/question/984329

#SPJ1

6 0
1 year ago
Consider a single CPU system with an active process A. Explain what happens in the following circumstances including any interru
Anika [276]

Answer:

The answer to this question as follows:

Explanation:

In option a, When we use fork, a new mechanism, that uses fork() method, which is in the parental process, to replicate all sites. It has been installed in a space-differentiating operating system.

In option b, It is the present system cycle that scan and wait for any of the system processor to be installed.

In option c,  The time delay happens when A operates. It is a global that make issues, which are cleared and slowed down when an interrupt happens. In this process, there are not any distractions. It splits into slowly as it heads into the ISR. It helps to understand the code easily.

5 0
3 years ago
What is the most important external issue when using social media in emergency management?
DerKrebs [107]
Th e most important external issue when using social media in emergency management is the disaster response. Disseminating information through social media is very effective especially when there are calamities and a disaster respond from both private and public sector is very urgent.
8 0
3 years ago
How many lines are on a standard sheet of typing paper?
kotegsom [21]
60 lines on the paper
3 0
3 years ago
Other questions:
  • .The process of capturing the requirements includes all ofthe following with the exception of:
    10·1 answer
  • Explain what the 35ppm specification means
    13·1 answer
  • Dr. Laos gets a referral for a 6 month old who has become listless and stopped eating lately. Her pediatrician wanted her to be
    15·1 answer
  • In which situation will file compression be required to complete the task
    15·1 answer
  • NEED HELP PLEASEE!!!
    9·1 answer
  • Consider the following protocol for concurrency control. The database system assigns each transaction a unique and strictly incr
    6·1 answer
  • Lucy has to move data from column A to column N in a worksheet. Which keys should she select to move data in the same worksheet?
    9·2 answers
  • Something I should look for when trying to decide if a source is credible is the publication's ....
    10·1 answer
  • Website managers use____ every day.
    10·2 answers
  • Difference between copy command and cut command
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!