Question 1 (1 point) Given the following 2 functions - what is the value of call
ID: 3736858 • Letter: Q
Question
Question 1 (1 point)
Given the following 2 functions - what is the value of calling fb(4,2)?
function fa(x, y){
if (y == 0) return 0;
return (x + fa(x, y-1));
}
function fb(x, y) {
if (y == 0) return 1;
return fa(x, fb(x, y-1));
}
Question 1 options:
Save
Question 2 (1 point)
What is the value of f5(3,4,5) for the following function;
function f5(n, a, b){
if (n <= 0) return 0;
return f5(n-1, a, b+n) + n + a + b + f5(n-1, b, a+n);
}
Question 2 options:
Save
Question 3 (1 point)
What is the return value of f2(17) ?
function f2(n) {
if (n == 0) return "";
return n % 2 + " " + f2(parseInt(n/2));
}
Question 3 options:
1)
2)
3)
4)
5)
6)
7)
Save
Question 4 (1 point)
Given the following 2 functions - what is the value of calling fb(3,3)?
function fa(x, y){
if (y == 0) return 0;
return (x + fa(x, y-1));
}
function fb(x, y) {
if (y == 0) return 1;
return fa(x, fb(x, y-1));
}
Question 4 options:
Save
Question 5 (1 point)
What is the value of f5(3,5,6) for the following function;
function f5(n, a, b){
if (n <= 0) return 0;
return f5(n-1, a, b+n) + n + a + b + f5(n-1, b, a+n);
}
Question 5 options:
Save
Question 6 (1 point)
What is the return value of f2(25) ?
function f2(n) {
if (n == 0) return "";
return n % 2 + " " + f2(parseInt(n/2));
}
Question 6 options:
1)
2)
3)
4)
5)
6)
Save
Question 7 (1 point)
What is the output of the following function if called with the argument doFun2(7)?
function doFun2(n) {
// Enqueue is equivalent to push, Dequeue is equivalent to shift
var q = [];
q.push(0); q.push(1);
for (var i = 0; i < n; i++ ){
var a = q.shift();
var b = q.shift();
q.push(b);
q.push(a + b);
}
return q.pop();
}
Question 7 options:
Save
Question 8 (1 point)
What is the output of the following function with the input "( ( ( ) )"
function g(s) {
var a = s.split("");
var b = [];
for (var i = 0; i < a.length; i++) {
if (a[i] == '(') {b.push('*');}
if (a[i] == ')') {if (b.length > 0) b.pop();}
}
return b.length;
}
Question 8 options:
Save
Question 9 (1 point)
Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node x from the list?
Question 9 options:
1)
2)
3)
4)
Save
Question 10 (1 point)
What will be the output of the following code?
var a = ["1", "2"];
document.getElementById("demo").innerHTML = a;
Question 10 options:
Explanation / Answer
Question 1 is 16
Explanation
Following are sequence of calls with x and y
In Fb: 4 2
In Fb: 4 1
In Fa: 4 1
In Fa: 4 4
In Fa: 4 3
In Fa: 4 2
In Fa: 4 1
Question 2 is 100
Explanation
Following is the sequence of n, a and b values
3 4 5
2 4 8
1 4 10
1 8 6
2 5 7
1 5 9
1 7 7
Question 3 is 1 0 0 0 1
Because it is a program to convert decimal to binary
Question 4 is 27
Explanation
The sequence of values of x and y for functions called
In Fb: 3 3
In Fb: 3 2
In Fb: 3 1
In Fa: 3 1
In Fa: 3 3
In Fa: 3 2
In Fa: 3 1
In Fa: 3 9
In Fa: 3 8
In Fa: 3 7
In Fa: 3 6
In Fa: 3 5
In Fa: 3 4
In Fa: 3 3
In Fa: 3 2
In Fa: 3 1