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
This isn't a homework question but rather a technological problem. I connected my device to the motherboard but it will not dete
Helen [10]
Re start the computer again
5 0
3 years ago
Read 2 more answers
What is analog computer? where is it used​
hichkok12 [17]

Explanation:

analogue computer is in computer which is used to process analogue data.

Analogue computer were widely used in scientific and industrial application

3 0
2 years ago
Read 2 more answers
What does amelia heart and the wright brothers have in common
expeople1 [14]

Answer:

they are stepbro and step sis and they fucx

Explanation:

7 0
2 years ago
Which tool should you use to modify firewall rules on a windows server?
vovikov84 [41]

Click Tools and select Windows Firewall with Advanced Security. Review the current configuration settings by selecting Windows Firewall Properties from the MMC landing page. You can access and modify the settings for each of the three firewall profiles, Domain, Private, and Public, as well as IPSec settings.

3 0
3 years ago
(Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number o
Gnoma [55]
It would be a table program. you can add a table and put your data into the table
6 0
3 years ago
Other questions:
  • In this problem we consider sending real-time voice from Host A to Host B over a packet-switched network (VoIP). Host A converts
    12·1 answer
  • You can type notes of what to cover when presenting the show in the______ pane.
    15·1 answer
  • How do you insert a new row into a worksheet
    5·1 answer
  • After you have created at least four slides, a scroll bar containing scroll arrows and scroll boxes will appear on the right edg
    9·1 answer
  • 2. You have noticed over the past several days that your computer is running more slowly
    6·2 answers
  • Describe at least two other companies that are direct or indirect competitors to your company. Explain how you will differentiat
    15·1 answer
  • An IT professional with a customer-service
    13·1 answer
  • write a pay-raise program that requests a person's first name, last name, and current annual salary, and then displays the perso
    6·1 answer
  • How do I modify objects in power point 2016 for an assignment
    11·1 answer
  • A student wants an algorithm to find the hardest spelling word in a list of vocabulary. They define hardest by the longest word.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!