Question

Write a binary recursivealgorithm that finds the maximum into an array. And apply it to the...

  1. Write a binary recursivealgorithm that finds the maximum into an array. And apply it to the following array:  8 |6 | 19 | 2 | 3 |2 |1

Show (1) the stack trace and (2) the recursive tree. You can draw them by hand on paper and attach them a picture your answers in the word document.

Homework Answers

Answer #1

Algorithm:

n=sizeof(array)

function find_max(array, n):

if(n==1):

return array[0];

else

return max(array[n-1], find_max(array, n-1));

The time complexity for this algorithm will be O(n). If you have any doubts, or if you want me to code the output, let me know in the comments and i will add that as well. If you have any doubts let me know.

Thank you :)

Know the answer?
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
Similar Questions
Write a recursive method that performs binary search on an array Arr and searches for a...
Write a recursive method that performs binary search on an array Arr and searches for a key k. Apply the recursive method to the following array: 13 | 20 | 22 | 26 | 30 | 41 | 50 | 60 While the key you are search for is 50. Show the stack trace.
Giving an array of integers A[1:8] ={5, 1, 3, 2, 7, 6, 8, 4}. Build a...
Giving an array of integers A[1:8] ={5, 1, 3, 2, 7, 6, 8, 4}. Build a MAX-HEAP on A. Show the steps using binary tree representation or array view. Use heap sort: show the array after the first, the second, and the third of heap sort
In heapsort we view an array as a binary tree using the following mapping: a[0] is...
In heapsort we view an array as a binary tree using the following mapping: a[0] is the root of the entire tree and for element a[i], its left child is a[2i+1] and its right child is a[2i+2]. Answer the following questions for an array of size n. ( Answers in some cases may be in terms of n.) a) What is the index of the parent a[i] for any i > 0? b) What is the biggest index for which...
‏What is the output of the Euler tour in the normal binary search tree if the...
‏What is the output of the Euler tour in the normal binary search tree if the key insert order is 5 , 2 , 8 , 5 , 9 , 5 , 1 , 3 , 4 , 2 , 8 ? All keys equal to the node should be the right subtree of that node. ____________________________________________________________ ‏Construct the binary max - heap for the keys given below. Once all the keys are inserted, perform the remove maximum operation, and...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
We are given the following CSP problem. The variables and domains are as follows. A: {4,...
We are given the following CSP problem. The variables and domains are as follows. A: {4, 5, 6, 7, 8} B: {10, 20, 30, 40} C: {2, 3, 4} D: {28, 43, 56, 77, 94, 114} The constraints are: A + C is odd. A + D is a square of an integer. B + D < 60. Solve this problem using the following heuristics and algorithms. • Use backtracking search. • For variable ordering, use MRV. If there are...
The book is (Foundations of Financial Management 16th edition) Complete the following short answers that apply...
The book is (Foundations of Financial Management 16th edition) Complete the following short answers that apply the concepts in chapter 8. Please read the textbook and study the lecture to answer questions. You can submit the answers in a Word document to the course assignments.   1. Under what circumstances would it be advisable to borrow money to take a cash discount? 2. What is the prime interest rate? How does the average bank customer fare in regard to the prime...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
   vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14...
   vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list. What is the result to the linked list of       the following instructions? Assume that newNode          is a Node, already constructed. newNode.data = 1;                         newNode.next = head.next;                         head = newNode;       a. The value 1 is inserted into the linked list before 20       b. The...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT