Assignment 4-1.pdf x Converting Decimal to Bin x Java Basic Op rced/227433-22635
ID: 3682443 • Letter: A
Question
Assignment 4-1.pdf x Converting Decimal to Bin x Java Basic Op rced/227433-22635.201620/Assignment9%204-1.pdf? &d2ISessionVal; MBO 2. Give the tracing of towers of Hanoi algorithm for 4 disks. 3. Proof by induction that the complexity of the following method is ologn). powerB(int x, int n) if (namo) return 1; return x; if (n is even) return powerB(x x, n/2); else return n/2) x; 4. write a recursive method that accepts a positive integer (in decima) au corresponding binary representation. For example, for input 10, it will display 101 5. (TextBook Q#3)Suppose that the ADT stack included the void method disp displays the entries in a stack. Implement this method for each of the follov implementations LinkedStack, as outlined in Listing 6-1. b) Array Stack, as outlined in Listing 6-2. c) VectorStack, as outlined in Listing 6-3. 6. Define a method getFrequency(anEntry) for the Linked List implementatio ADT. The method returns the number of occurrences of anEntry in the stacExplanation / Answer
Answer:
T(n)= T(n/2)+c
This will be the recurrence relation
because function n/2 and rest are constants..
so primarily dependent on n/2
Proof:
T(n) = T(n/2) + c
= 1 , T(2) = 0
1. Base Case : n = 2
T(2) = log2 = 1
2. Now assume T(n) = logn
3. Induction Step:
T(n + 1) = log(n +1)
= logn x log1 = logn
Now, T(n +1 ) = T(n +1/ 2)
= > T( n + 1) = 1/2 x T(n + 1 )
= 1/2 logn = logn
proved.