wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

KLU- CLUSTER -4 DAY-6

Total questions: 30

Worksheet time: 30mins

Name
Class
Date
1.
following is C like pseudo-code of a function that takes a Queue as an argument, and uses a stack S to do processing.  void fun(Queue *Q) {     Stack S;  // Say it creates an empty stack S     while (!isEmpty(Q))     { push(&S, deQueue(Q));     }     while (!isEmpty(&S))     { enQueue(Q, pop(&S));     } } What does the above function do in general?
a)
Removes the last from Q
b)
Keeps the Q same as it was before the call
c)
Makes Q empty
d)
Reverses the Q
2.
Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are
a)
Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
b)
Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR
c)
Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
d)
Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
3.
Consider the following pseudo code. Assume that IntQueue is an integer queue. What does the function fun do?  void fun(int n) {     IntQueue q = new IntQueue();     q.enqueue(0);     q.enqueue(1);     for (int i = 0; i < n; i++)     {         int a = q.dequeue();         int b = q.dequeue();         q.enqueue(b);         q.enqueue(a + b);         print(a);     } }
a)
Prints numbers from 0 to n-1
b)
Prints numbers from n-1 to 0
c)
Prints first n Fibonacci numbers
d)
Prints first n Fibonacci numbers in reverse order.
4.
Let the following circular queue can accommodate maximum six elements with the following data.What will happen after ADD O operation takes place? front = 2 rear = 4 queue = _______; L, M, N, ___, ___
a)
front = 2 rear = 5 queue = ______; L, M, N, O, ___
b)
front = 3 rear = 5 queue = L, M, N, O, ___
c)
front = 3 rear = 4 queue = ______; L, M, N, O, ___
d)
front = 2 rear = 4 queue = L, M, N, O, ___
5.
Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are
a)
Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
b)
Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR
c)
Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
d)
Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
6.
Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter. MultiDequeue(Q){ m = k while (Q is not empty and m > 0) { Dequeue(Q) m = m - 1 } } What is the worst case time complexity of a sequence of n MultiDequeue() operations on an initially empty queue?
a)
Theta(n)
b)
Theta(n + k)
c)
Theta(nk)
d)
Theta(n^2)
7.
An implementation of a queue Q, using two stacks S1 and S2, is given below: void insert(Q, x) { push (S1, x); } void delete(Q){ if(stack-empty(S2)) then if(stack-empty(S1)) then { print(“Q is empty”); return; } else while (!(stack-empty(S1))){ x=pop(S1); push(S2,x); } x=pop(S2); } Let n insert and m (<=n) delete operations be performed in an arbitrary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following is true for all m and n?
a)
n+m <= x < 2n and 2m <= y <= n+m
b)
n+m <= x < 2n and 2m<= y <= 2n
c)
n+m <= x < 2n and 2m<= y <= 2n
d)
2m <= x <2n and 2m <= y <= 2n
8.
What will be the output of the following code snippet? #include <stdio.h> void solve() { printf("%d %d", (023), (23)); } int main() { solve(); return 0; }
a)
023 23
b)
23 23
c)
19 23
d)
23 18
9.
What will be the output of the following code snippet? #include <stdio.h> void swap(int a, int b) { a=(a+b)-(b=a); } void solve() { int a = 3, b = 5; swap(a, b); printf("%d %d", a, b); } int main() { solve(); return 0; }
a)
3 5
b)
5 3
c)
5 5
d)
3 3
10.
What will be the value of x in the following code snippet? #include <stdio.h> void solve() { int x = printf("Hello"); printf(" %d", x); } int main() { solve(); return 0; }
a)
10
b)
error
c)
garbage value
d)
5
11.
What will be the value of x in the following code snippet? #include "stdio.h" int main() { int x, y = 5, z = 5; x = y == z; printf("%d", x); return 0; }
a)
0
b)
1
c)
5
d)
compiler error
12.
What will be the value of x in the following code snippet? #include <stdio.h> // Assume base address of "CCCQuiz" to be 1000 int main() { printf(3 + "CCCQuiz"); return 0; }
a)
Compile time error
b)
1003
c)
Quiz
d)
CCCQuiz
13.
What will be the value of x in the following code snippet? #include <stdio.h> int main() { int i = 3; printf("%d", (++i)++); return 0; }
a)
Compile time error
b)
5
c)
4
d)
3
14.
What will be the value of x in the following code snippet? #include <stdio.h> #if X == 3 #define Y 3 #else #define Y 5 #endif int main() { printf("%d", Y); return 0; }
a)
Compile time error
b)
5
c)
3
d)
3 or 5 dependent on X
15.
struct { short s[5]; union { float y; long z; }u; } t; Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is
a)
22 bytes
b)
14 bytes
c)
18 bytes
d)
10 bytes
16.
In below program, what would you put in place of “?” to print “Quiz”? #include <stdio.h> int main() { char arr[] = "CCCSRMQuiz"; printf("%s", ?); return 0; }
a)
arr
b)
arr+3
c)
arr+6
d)
not possible
17.
The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
a)
AB+ CD*E - FG /**
b)
AB + CD* E - F **G /
c)
AB + CD* E - *F *G /
d)
AB + CDE * - * F *G /
18.
The postfix form of A*B+C/D is?
a)
*AB/CD+
b)
AB*CD/+
c)
A*BC+/D
d)
ABCD+/*
19.
The prefix form of A-B/ (C * D ⋀ E) is?
a)
-/*⋀ACBDE
b)
-ABCD*⋀DE
c)
-A/B*C⋀DE
d)
-A/BC*⋀DE
20.
The prefix form of an infix expression p + q - r * t is?
a)
+ pq - *rt
b)
- +pqr * t
c)
- +pq * rt
d)
- + * pqrt
21.
The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a)
600
b)
350
c)
650
d)
588
22.
Convert the following infix expressions into its equivalent postfix expressions (A + B ⋀D)/(E - F)+G
a)
(A B D ⋀ + E F - / G +)
b)
(A B D +⋀ E F - / G +)
c)
(A B D ⋀ + E F/- G +)
d)
None
23.
Convert the following Infix expression to Postfix form using a stack x + y * z + (p * q + r) * s, Follow usual precedence rule and assume that the expression is legal.
a)
xyz*+pq*r+s*+
b)
xyz*+pq*r+s+*
c)
xyz+*pq*r+s*+
d)
none
24.
Consider Stack is implemented using the array. #define MAX 10 struct STACK { int arr[MAX] int top = ___________; } What will be the initial value with which top is initialized.
a)
Garbage
b)
1
c)
-1
d)
0
25.
Assume that the operators +,-, X are left associative and ⋀ is right associative. The order of precedence (from highest to lowest) is ⋀, X, +, -. The postfix expression corresponding to the infix expression a + b X c – d ⋀ e ⋀ f is
a)
abc X+ def ⋀ ⋀ -
b)
abc X+ de⋀f⋀ -
c)
ab+c Xd – e ⋀f⋀
d)
-+aXbc⋀ ⋀def
26.
If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, in what order will they be removed?
a)
ABCD
b)
DCBA
c)
DCAB
d)
ABDC
27.
Consider the usual implementation of parentheses balancing program using stack. What is the maximum number of parentheses that will appear on stack at any instance of time during the analysis of ( ( ) ( ( ) ) ( ( ) ) )?
a)
1
b)
2
c)
3
d)
4
28.
Postfix Form of A+(B*C)
a)
ABC+*
b)
AB*C+
c)
ABC*+
d)
AB+C*
29.
7 5 2 + * 4 1 1 + / - is evaluated as-
a)
47
b)
24
c)
48
d)
35
30.
Result of the prefix expression * - + 4 3 5 / + 2 4 3 is
a)
1
b)
2
c)
4
d)
8