Consider the following pseudocode: f(int n, int d) { println(space(d) + "n=" + n + " begins"); if (n > 1) { f(n/2, d+1); println(space(d+1) + "hi"); f(n/2, d+1); } println(space(d) + "n=" + n + " ends"); } where println(s) prints the string s on its own line, space(d) is a string of d spaces, and the + in the println means string concatenation. For example, if n=4 and d=2, the commands println(space(d) + "n=" + n + " begins"); println(space(d+1) + "hi"); will print __n=4 begins ___hi (where the space character is replaced by just so you can see it.) (a) Write down the output printed by f(4, 0). [5 marks] (b) Let T(n) be the number of lines printed by f(n,0). Write down a recurrence formula for T(n), including the base case. You can assume n is a power of 2. [5 marks] (c) Solve the recurrence to find out how many lines are printed by f(n,0), as a function of n. (You must not use the Master Theorem.) [20 marks]
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
for java 5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what will be printed on the screen. (a) for(int a-0; a<5; a++) for (int b-0 b
2. Consider the following functions. For each of them, determine how many times is ‘hey’ printed in terms of the input n. You should first write down a recurrence and then solve it using the recursion tree method. That means you should write down the first few levels of the recursion tree, specify the pattern, and then solve. (a) def fun(n) { if (n > 1) { print( ‘hi’ ‘hi’ ‘hi’ ) fun(n/4) fun(n/4) fun(n/4) }} (b) def fun(n) {...
Strange Sort In a dumpster outside MEB, I found a scrap of paper with this Java implementation of a sorting algorithm on it: // This will get me the Turing Award for sure!! public static void sort (int[] A) { sort (A, O, A.length); // Sorts the subarray Allo .. hi-1] into ascending order private static void sort (int[] a, int lo, int hi) { int size = hi - lo; if (size == 2) { if (A[lo] > A[10+1])...
(5 x 2 = 10 pts) Consider the following functions. For each of them, determine how many times is ‘hi' printed in terms of the input n (i.e in Asymptotic Notation of n). You should first write down a recurrence and then solve it using the recursion tree method. That means you should write down the first few levels of the recursion tree, specify the pattern, and then solve. (a) 1 2 3 def fun(n) { if (n > 1)...
PROBLEM 1 (24 points): For each of the recursive functions below and on the next page, give a correct recurrence relation expressing its runtime and then a tight runtime bound for the recurrence relation. Functions that take parameters lo and hi: n=hi-lo+1 RECURRENCE RELATION: int foo(int a[], int lo, int hi) { int x, i, j, m; X = 0; if(lo==hi) return a[10]; for(i=lo; i<=hi; i++) { for(j=i+1; j<=hi; j++) { if(a[i] % 2) x += a[i]; else x -=...
PLEASE write in C Language, ( you can use array, recursive function, Pointers, Dynamic call by refernce, Structure) a) 70 marks] Write a program that Sorts a given integer array via Selection Sort obtained by rotation around 3. Searches for a key point in the rotated array in O(logn) time, where the rotation Rotates the sorted array around a random point, e.g., 1 2 345->34512 is point is known in advance. ts above by first finding the unknown rotation point...
I need help with the creation of the pre and post conditions for each function of my program. Please see below. #include <iostream> #include <string.h> using namespace std; #define TOTAL_COMMANDS 7 struct command { char name[1024]; // Store the name of the command int *paramsCount; // Stores the valid no. of params char error[4096]; // Stores the valid errors int differentParams; // Store no. of different ways to specify params int differentErrors; // Store no. of different ways to error...
1. Call a string of lettes ega if i can be produced by concatenating (running together) copies of the strings 'a, 'b','c' and 'ddd. For example, the string 'act' is legal because it can be produced by concatenating 'a', 'cc' and b', but the string 'ccca' is not legal. For each integer n 2 1, let tn be the number of legal strings with n letters. For example, 1-2 (a' and 'b' are the legal strings). (a) Write down t2...
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;...
1. Call a string of letters "legal if it can be produced by concatenating (running together) copies of the strings 'a', 'b', 'cc' and 'ddd'. For example, the string 'accb' is legal because it can be produced by concatenating 'a', 'cc' and 'b', but the string 'ccca' is not legal. For each integer n 21, let tn be the number of legal strings with n letters. For example, t1 2 (a and 'b' are the legal strings) (a) Write down...