wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Technical MCQs

Total questions: 35

Worksheet time: 26mins

Name
Class
Date
1.

The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is

a)

O(n)

b)

O(logn)

c)

O(log*n)

d)

O(1)

2.

Let A be a square matrix of size n x n. Consider the following program. What is the expected output?

C = 100

for i = 1 to n do

for j = 1 to n do

{

Temp = A[i][j] + C

A[i][j] = A[j][i]

A[j][i] = Temp - C

}

for i = 1 to n do

for j = 1 to n do

Output(A[i][j]);

a)

The matrix A itself

b)

Transpose of matrix A

c)

Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A

d)

None of the above

3.

Consider an array consisting of -€“ve and +ve numbers. What would be the worst time comparisons an algorithm can take in order to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve on the other ?

a)

N-1

b)

N

c)

N+1

d)

(N*(N-1))/2

4.

Consider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that a node of doubly linked list has previous pointer as prev and next pointer as next.

void fun(struct node **head_ref)

{

struct node *temp = NULL;

struct node *current = *head_ref;


while (current != NULL)

{

temp = current->prev;

current->prev = current->next;

current->next = temp;

current = current->prev;

}


if(temp != NULL )

*head_ref = temp->prev;

}

Assume that reference of head of following doubly linked list is passed to above function 1 2 3 4 5 6. What should be the modified linked list after the function call?

a)

2 <--> 1 <--> 4 <--> 3 <--> 6 <-->5

b)

5 <--> 4 <--> 3 <--> 2 <--> 1 <-->6

c)

6 <--> 5 <--> 4 <--> 3 <--> 2 <--> 1

d)

6 <--> 5 <--> 4 <--> 3 <--> 1 <--> 2

5.

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

a)

Insertion Sort

b)

Quick Sort

c)

Heap Sort

d)

Merge Sort

6.

What is the output of following function for start pointing to first node of following linked list? 1->2->3->4->5->6

void fun(struct node* start)

{

if(start == NULL)

return;

printf("%d ", start->data);

if(start->next != NULL )

fun(start->next->next);

printf("%d ", start->data);

}

a)

1 4 6 6 4 1

b)

1 3 5 1 3 5

c)

1 2 3 5

d)

1 3 5 5 3 1

7.

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

a)

log 2 n

b)

n/2

c)

log 2 n – 1

d)

n

8.

Consider the following pseudocode that uses a stack

declare a stack of characters

while ( there are more characters in the word to read )

{

read a character

push the character on the stack

}

while ( the stack is not empty )

{

pop a character off the stack

write the character to the screen

}

What is output for input "codelab"?

a)

codelabcodelab

b)

baledoc

c)

codelab

d)

baledocbaledoc

9.

The following postfix expression with single digit operands is evaluated using a stack:

8 2 3 ^ / 2 3 * + 5 1 * -

Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:

a)

6, 1

b)

5, 7

c)

3, 2

d)

1, 5

10.

To evaluate an expression without any embedded function calls:

a)

One stack is enough

b)

Two stacks are needed

c)

As many stacks as the height of the expression tree are needed

d)

A Turing machine is needed in the general case

11.

How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.

a)

1

b)

2

c)

3

d)

4

12.

The maximum number of binary trees that can be formed with three unlabeled nodes is:

a)

1

b)

5

c)

4

d)

3

13.

The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:

a)

n/2

b)

(n-1)/3

c)

(n-1)/2

d)

(2n+1)/3

14.

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:

a)

2^h -1

b)

2^(h-1) – 1

c)

2^(h+1) -1

d)

2*(h+1)

15.

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

a)

7 5 1 0 3 2 4 6 8 9

b)

0 1 2 3 4 5 6 7 8 9

c)

0 2 4 3 1 6 5 9 8 7

d)

9 8 6 4 2 3 0 1 5 7

16.

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?

a)

2

b)

3

c)

4

d)

6

17.

Which of the following traversals is sufficient to construct BST from given traversals 1) Inorder 2) Preorder 3) Postorder

a)

Any one of the given three traversals is sufficient

b)

Either 2 or 3 is sufficient

c)

2 and 3

d)

1 and 3

18.

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

a)

10, 20, 15, 23, 25, 35, 42, 39, 30

b)

15, 10, 25, 23, 20, 42, 35, 39, 30

c)

15, 20, 10, 23, 25, 42, 35, 39, 30

d)

15, 10, 23, 25, 20, 35, 42, 39, 30

19.

Given an undirected graph G with V vertices and E edges, the sum of the degrees of all vertices is

a)

E

b)

2E

c)

V

d)

2V

20.

How many undirected graphs (not necessarily connected) can be constructed out of a given set V = {v1, v2, ... vn} of n vertices?

a)

n(n-1)/2

b)

2n

c)

n!

d)

2n(n-1)/2

21.

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

a)

-2

b)

-1

c)

1

d)

2

22.

A process executes the code

fork();

fork();

fork();

The total number of child processes created is

a)

3

b)

4

c)

7

d)

8

23.

Consider three CPU-intensive processes, which require 10, 20 and 30 time units and arrive at times 0, 2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.

a)

1

b)

2

c)

3

d)

4

24.

Which of the following process scheduling algorithm may lead to starvation

a)

FIFO

b)

Round Robin

c)

Shortest Job Next

d)

None of the above

25.

If the quantum time of round robin algorithm is very large, then it is equivalent to:

a)

First in first out

b)

Shortest Job Next

c)

Priority scheduling

d)

None of the above

26.

Consider the 3 processes, P1, P2 and P3 shown in the table.

Process Arrival time Time Units Required

P1 0 5

P2 1 7

P3 3 4

The completion order of the 3 processes under the policies FCFS and RR2 (round robin scheduling with CPU quantum of 2 time units) are

a)

FCFS: P1, P2, P3

RR2: P1, P2, P3

b)

FCFS: P1, P3, P2

RR2: P1, P3, P2

c)

FCFS: P1, P2, P3

RR2: P1, P3, P2

d)

FCFS: P1, P3, P2

RR2: P1, P2, P3

27.

Consider the following table of arrival time and burst time for three processes P0, P1 and P2.

Process Arrival time Burst Time

P0 0 ms 9 ms

P1 1 ms 4 ms

P2 2 ms 9 ms

The pre-emptive shortest job first scheduling algorithm is used. Scheduling is carried out only at arrival or completion of processes. What is the average waiting time for the three processes?

a)

5.0 ms

b)

4.33 ms

c)

6.33 ms

d)

7.33 ms

28.

Which of the following statements are true?

I. Shortest remaining time first scheduling may cause starvation

II. Preemptive scheduling may cause starvation

III. Round robin is better than FCFS in terms of response time

a)

I only

b)

I and III only

c)

II and III only

d)

I, II and III

29.

In the process state transition diagram for a uniprocessor system, assume that there are always some processes in the ready state: Now consider the following statements: I. If a process makes a transition D, it would result in

another process making transition A immediately.

II. A process P2 in blocked state can make transition E

while another process P1 is in running state.

III. The OS uses preemptive scheduling.

IV. The OS uses non-preemptive scheduling.

Which of the above statements are TRUE?

a)

I and II

b)

I and III

c)

II and III

d)

II and IV

30.

Which of the following page replacement algorithms suffers from Belady’s anomaly?

a)

FIFO

b)

LRU

c)

Optimal Page Replacement

d)

Both LRU and FIFO

31.

Page fault occurs when

a)

When a requested page is in memory

b)

When a requested page is not in memory

c)

When a page is corrupted

d)

When an exception is thrown

32.

An operating system uses the Banker’s algorithm for deadlock avoidance when managing the allocation of three resource types X, Y, and Z to three processes P0, P1, and P2. The table given presents the current system state. Here, the Allocation matrix shows the current number of resources of each type allocated to each process and the Max matrix shows the maximum number of resources of each type required by each process during its execution. There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system is currently in a safe state. Consider the following independent requests for additional resources in the current state:

REQ1: P0 requests 0 units of X,

0 units of Y and 2 units of Z

REQ2: P1 requests 2 units of X,

0 units of Y and 0 units of Z

Which one of the following is TRUE?

a)

Only REQ1 can be permitted.

b)

Only REQ2 can be permitted.

c)

Both REQ1 and REQ2 can be permitted.

d)

Neither REQ1 nor REQ2 can be permitted

33.

A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that deadlocks never arise is _________.

a)

6

b)

7

c)

8

d)

9

34.

Which of the following is major part of time taken when accessing data on the disk?

a)

Settle time

b)

Rotational latency

c)

Seek time

d)

Waiting time

35.

Put the following disk scheduling policies results in minimum amount of head movement.

a)

FCFS

b)

Circular SCAN

c)

Elevator/SCAN

d)

LOOK