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]
4 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]4 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
Please help I’ll give you 10 points
Doss [256]
The origin its the same as in math

3 0
3 years ago
Read 2 more answers
How do i know if i got flash installed onchrome
Elodia [21]
It should be in your extensions where the 3 little dots are look for extensions then look thru them if you have a chromebook you call look thru all the apps in a litte circle on the very bottom lefthand side
5 0
3 years ago
Sandra wants to have her new technology up and running as soon as possible. She is looking for a tool that she can
Dvinal [7]

I would say Microsoft Excel but I am not sure and ms excel is the best way to organize large amounts of data into orderly, logical spreadsheets and charts.

3 0
3 years ago
If you’re storing some personal information like Debit/Credit card numbers or Passwords etc, on different sites for running you’
Nadusha1986 [10]

Answer:

hacker can steal your data in many ways.

Explanation:

if you allow cookie site for fake websites. It can absolutely be possible.

5 0
4 years ago
Full form of DVX please answer fast ​
statuscvo [17]

Answer:

Devastating Vocal Xcellence

Explanation:

5 0
3 years ago
Other questions:
  • Complete each statement by choosing the correct answer from the drop-down menu.
    10·1 answer
  • Please what's the answer to this
    14·1 answer
  • What is media consumption ?
    12·2 answers
  • You want to centrally back up the files users store in the Documents folder in their user profiles, but you don’t want users to
    7·1 answer
  • Which term is used to describe bitmap images
    8·2 answers
  • Direct Mapped Cache. Memory is byte addressable. Fill in the missing fields based upon the properties of a direct-mapped cache.
    6·1 answer
  • How can you prevent your VMs receiving DHCP server messages from unauthorized virtual machine pretending to be DHCP servers?
    13·1 answer
  • g Given the information below, answer each part of the question: Page Size: 4 KB a. How many bits are in the Page Offset
    11·1 answer
  • The ______________<br> holds data only while the computer is on.
    7·1 answer
  • How to get the whole number of a fraction in python
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!