wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Data Structures

Total questions: 40

Worksheet time: 29mins

Name
Class
Date
1.

Consider an empty stack. The order of performing the operations is: push(21), push(52), push(16), pop(), pop(), push(25), push(22), push(60), pop(), pop(), push(15), pop().

a)

21, 25, 22, 15

b)

21, 52, 16

c)

21, 25

d)

25, 21

2.

What does the following code depict?

#define Size 5 //Maximum possible size of a stack

struct stack{

     int data[SIZE];

     int TOP;

}

 void fun(){

     if(ptr -> TOP == SIZE-1)

         return;

}

a)

Overflow

b)

Underflow

c)

Enqueue

d)

Dequeue

3.

What is the output of the below code?

#include <stdio.h>  

int main()  

{  

     int arr[5]={10,20,30,40,50};  

    printf("%d", arr[5]);  

   return 0;  

}  

a)

10

b)

Garbage value

c)

50

d)

None of the above

4.

Which data structure is required to convert the infix to prefix notation?

a)

Linked list

b)

Binary tree

c)

Stack

d)

Queue

5.

Which of the following is the prefix form of A+B*C?

a)

A+(BC*)

b)

+AB*C

c)

ABC+*

d)

+A*BC

6.

What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1?

(a)  

7.

If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the removal?

a)

1234

b)

4321

c)

3241

d)

None of the above

8.

Which one of the following is the overflow condition if linear queue is implemented using an array with a size MAX_SIZE?

a)

rear = front

b)

rear = front+1

c)

rear=MAX_SIZE -1

d)

rear = MAX_SIZE

9.

In the linked list implementation of queue, where will the new element be inserted?

a)

At the middle position of the linked list

b)

At the head position of the linked list

c)

At the tail position of the linked list

d)

None of the above

Hide Answer

10.

What would be the output after performing the following operations in a Deque?

Insertfront(10);  

Insertfront(20);  

Insertrear(30);  

Insertrear(40);  

Deletefront();  

Insertfront(50);  

Deleterear();  

Display();  

a)

10, 20, 30

b)

50, 10, 30

c)

40, 20, 30

d)

None of the above

11.

Consider the following code

struct node  {  

   int data;  

    struct node *next;  

} node ptr;  

Which one of the following is the correct option to create a new node?

a)

ptr= (node*)malloc(sizeof(node*))

b)

ptr=(node)malloc(sizeof(node))

c)

ptr=(node*)malloc(sizeof(node))

d)

None of the above

12.

Identify the data structures which allows deletions from both the ends of the list but insertion at only one end

a)

Input restricted dequeue

b)

Output restricted dequeue

c)

Priority Queue

d)

Stack

13.

In Circular Queue the value of REAR will be?

a)

rear = rear+1

b)

rear=(rear+1)/MAX

c)

rear=(rear+1)%MAX

d)

rear=(rear-1)%MAX

14.

Evaluate Postfix expression from given infix expression.

A + B (C + D) / F + D E

a)

AB+CD*F/+D*E

b)

ABCD+*F/+DE*+

c)

ABCD+*/F+DE*

d)

AB+CD*F/+DE*

15.

Consider the following recursive implementation to find the nth fibonacci number:

Which of the following lines should be inserted to complete the above code?

a)

fibo(n-1)

b)

fibo(n-1) + fibo(n-2)

c)

fibo(n*1) + fibo(n*2)

d)

fibo(n/1) + fibo(n/2)

16.

A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations Insertion and Deletion can be performed in constant time?

a)

rear node

b)

front node

c)

not possible with one pointer

d)

node next to front

17.

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

18.

A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full” is

a)

(top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)

b)

top1 + top2 = MAXSIZE

c)

(top1= MAXSIZE/2) or (top2 = MAXSIZE)

d)

top1= top2 -1

19.

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

20.

program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

a)

An array of 100 numbers

b)

An array of 50 numbers

c)

An array of 500 numbers

d)

A dynamically allocated array of 550 numbers

21.

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

a)

Transpose of matrix A

b)

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

c)

The matrix A itself

d)

None of the above

22.

Which of the following algorithm cannot be desiged without recursion −

a)

Tower of Hanoi

b)

Fibonacci Series

c)

Tree Traversal

d)

None of the above

23.

Items in a priority queue are entered in a _____________ order

a)

random

b)

order of priority

c)

as and when they come

d)

LIFO

24.

A graph in which all vertices have equal degree is known as ______

a)

Full Binary Tree

b)

Binary Search Tree

c)

Threaded Tree

d)

Complete Binary Tree

25.

Minimum number of fields in each node of a doubly linked list is ______

a)

1

b)

2

c)

3

d)

4

26.

A tree with n vertices has _____ no. of edges

a)

n-1

b)

n-2

c)

2n

d)

logn

27.

The maximum no. of nodes at any level is

a)

n

b)

2^n

c)

n+1

d)

2n

28.

For the Binary tree shown in Fig, the in-order traversal sequence is:

a)

ABCDEFGHIJK

b)

HIDEBFCGJKA

c)

HDIBEAFCJGK

d)

HDBEIAFJCKG

29.

For the Binary Tree shown in fig, the pre-order traversal sequence is:

a)

ABCDEFGHIJK

b)

HIDEFGCABJK

c)

HDEFIGCKJAB

d)

ABDHIECFGJK

30.

For the Binary Tree shown in fig, the post-order traversal sequence is:

a)

ABCDEFGHIJK

b)

HIDEBFJKGCA

c)

HDEFIGCKJAB

d)

ABDHIECFGJK

31.

If this tree is used for sorting, the new number 8 should be placed as the

a)

left child of the node labelled 30

b)

right child of the node labelled 5

c)

right child of the node labelled 30

d)

left child of the node labelled 10

32.

The set of all edges generated by DFS tree starting at node B is:

a)

BADCGFE

b)

AD

c)

BACDEFG

d)

Cannot generated

33.

Graph traversal is different from a tree traversal, because:

a)

trees are not connected

b)

graphs may have loops

c)

trees have root

d)

None of these

34.

Graphs are represented using ............

a)

Adjacency tree

b)

Adjacency graph

c)

Adjacency linked list

d)

Adjacency queue

35.

What is the number of vertices of degree 2 in a path graph having n vertices,here n>2.

a)

n-2

b)

n

c)

2

d)

0

36.

A file is a collection of

a)

Information

b)

Data

c)

Records

d)

Related Records

37.

Which among one of is not a file operation?

a)

Creation

b)

Updation

c)

Retrival

d)

Security

38.

Which are the following are true with respect to Indexed Sequential File?

a)

Fast data retrieval

b)

Records are of fixed length

c)

Index table stores the address of the records in the file

d)

All the above

39.

B-tree structure has the following advantages?

a)

B-trees improve the performance of a wide range of queries

b)

B-trees provide fast and efficient algorithms to insert, update, and delete records that maintain

the key order.

c)

B-trees perform well for small as well as large tables

d)

All the above

40.

(a)   is used to compute the address of a record by using a hash function on the search key

value.