Question

Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1 ) return b; else return

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a Recurrence Relation (b) = P(n-2) + (1) T(n)= n =10(n) Here aan b space com complexity = Number of Times Recursive calls mad

Add a comment
Know the answer?
Add Answer to:
Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a...

    Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a and b are integers while (a>0) B- a/2 A a-2 end while return b; i. What is the time complexity of the IterativeFunction pseudocode shown above? ii. What is the space complexity of the IterativeFunction pseudocode shown above? 2. What is the time complexity of the following algorithm (Note that n(n+1) 2,2 n(n+1)(2n+1) 2 and ): Provide both T(n) and order, e(f(n)). int A=0;...

  • Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function...

    Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function SumKSmallest(A[0..n – 1), k) that returns the sum of the k smallest elements in an unsorted integer array A of size n. For example, given the array A=[6,-6,3,2,1,2,0,4,3,5] and k=3, the function should return -5. a. [3 marks) Write an algorithm in pseudocode for SumKSmallest using the brute force paradigm. Indicate and justify (within a few sentences) the time complexity of your algorithm. b....

  • a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n...

    a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...

  • The following pseudocode describes the algorithm for a sort of n decimal integers of d digits...

    The following pseudocode describes the algorithm for a sort of n decimal integers of d digits each: radixNumberSort(theArray: ItemArray, n: integer, d: integer): void for (j = d down to 1) { Initialize 10 groups to empty Initialize a counter for each groups to 0 for (i = 0 through n – 1) { K = jth digit of theArray[i] Place theArray[i] at the end of group k Increase kth counter by 1 } Replace the items in theArray with...

  • [10 marks] consider the following pseudocode: p := 0 x := 2fori:= 2ton p := (p...

    [10 marks] consider the following pseudocode: p := 0 x := 2fori:= 2ton p := (p + i ) * x a) How many addition(s) and multiplication(s) are performed by the above pseudocode?b) Express the time-complexity of the pseudocode using the big-Θ notation.) Trace the algorithm, below, then answer (c) and (d):   Procedure xyz(n: integer) s := 0, for i:= 1 to n, for j:= 1to i, s:= s+ j*(i− j+ 1) return s c) What is the time-complexity for...

  • A) Write the pseudocode for an algorithm using dynamic programming to solve the activity-selection problem based...

    A) Write the pseudocode for an algorithm using dynamic programming to solve the activity-selection problem based on this recurrence: c[i, j] = 0 if Si; = Ø max {c[i, k] + c[k,j] + 1} if Sij +0 ak eSij B) Analyze the running time (the time complexity) of your algorithm and compare it to the iterative greedy algorithm.

  • When asked to describe an algorithm you are expected to give a clear pseudo-code description of...

    When asked to describe an algorithm you are expected to give a clear pseudo-code description of the algorithm 1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...

  • Question 2 Consider the following algorithm Fun that takes array A and key Kas Fun(AO,...,n -...

    Question 2 Consider the following algorithm Fun that takes array A and key Kas Fun(AO,...,n - 1], K) count = 0 for i = 0 ton - 1 do for j = i +1 to n - 1 do if A[i] + A[j] == K then count = count +1 end if end for end for return count What is the best case time complexity of the above algorithm?! (log(n)) O(1) (n) (na) Previous o H H 9

  • Convert the following pseudocode to Java. Use the same variable names as those in the pseudocode....

    Convert the following pseudocode to Java. Use the same variable names as those in the pseudocode. You may assume that the incoming array contains int values and that a swap method exists elsewhere. The variables low and high represent indices in the array. In a comment before the sort method, list which sorting algorithm is used here and what its runtime complexity is in Big-O notation. This is the only comment required for this code. SUBROUTINE sort(ARRAY a[0..n], low, high)...

  • Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i =...

    Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i = 1; n; i++) jsjtA[i]; for (i = 1; n; i++) return j+ int anysqual (int n, int A) index i,j,k.m; for ( iSn i++) for G-1:jSnj++) for (k = 1; k n: k++) for (m t= 1; m n: m++) return 1 return 0 Note: The array parameter A[ I[1 in any equal is an n x n two-dimensional array. For example when n...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT