Here is class 12 computer science Unit 6 [Type B] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 6 and for all chapters here.Watch all tutorials for chapter 6.
Solution:
(c) compute(3) = compute(2) + 2*3-1
(b) def compute(N): if N == 1: return 1 else: return compute(N-1)+2*N-1
(D) 6
(a) 15 12 9 6 3 Finally (b) Infinite loop (c) 10 8 6 4 2 Finally (d) Infinite loop
def express(x, n): if n == 0: return 1 elif n%2 == 0: return express(xx, n/2) else: return express(x, n-1) express(2,5)
Nothing will be displayed on the output screen as absence of print() function. Hence, no output. Note: But beside this fact 32 will be finally result of the above code as the express() is called.
def check(n): if n<=1: return True elif n%2 == 0: return check(n/2) else: return check(n/1) What is the value returned by check(8)?
True
Yes, the last condition will make an infinite recursion to occur. If any number odd and greater than 1 is passed than the code will enter in infinite recursion. Hence, in the case of check(3) an infinite loop will occur.
def Fn(n): print(n, end=" ") if n<3: return n else: return Fn(n//2) - Fn(n//3) What will be the result produced by following function calls? (a) Fn(12) (b) Fn(10) (c) Fn(7)
Output: (a) 12 6 3 1 1 2 4 2 1 -3 (b) 10 5 2 1 3 1 1 1 (c) 7 3 1 1 2 -2
def recur(p): if p==0: print("##") else: recur(p) p=p-1 recur(5)
This code will act as infinite recursion as the p=p-1 will never going to run as of positioning.
#the corrected code will be def recur(p): if p==0: print("##") else: p=p-1 recur(p) recur(5)
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page