Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Data Structures Quiz

Total questions: 50

Worksheet time: 3600secs

Name
Class
Date
1.

Dynamic memory allocation in C is done using which function?

a)

malloc

b)

calloc

c)

free

d)

both a and b

2.

In C, which operator is used to access the address of a variable?

(a)  

3.

What is the time complexity of accessing an element in an array?

a)

O(1)

b)

O(n)

c)

O(n^2)

d)

O(log n)

4.

Which of the following is a hashing technique?

a)

Linear Probing

b)

Open Addressing

c)

Both a and b

d)

None

5.

What data structure is often used for managing memory allocation?

a)

Stack

b)

Queue

c)

Array

d)

Linked List

6.

What is the primary difference between a structure and a union in C?

a)

Structure has shared memory

b)

Union has shared memory

c)

Both are identical

d)

None of the above

7.

The process of accessing elements in a specific order in a data structure is called?

a)

Sorting

b)

Traversing

c)

Searching

d)

Deleting

8.

Which data structure allows multiple pointers to refer to the same node?

a)

Stack

b)

Circular Queue

c)

Linked List

d)

Array

9.

What type of queue has a front and rear pointer that wrap around?

a)

Circular Queue

b)

Double-ended Queue

c)

Simple Queue

d)

Priority Queue

10.

What is the time complexity of inserting an element in a linked list at the beginning?

a)

O(1)

b)

O(n)

c)

O(n^2)

d)

O(log n)

11.

Fill in the blank: A (a)   traversal visits each node in a binary tree starting from the left, root, then right.

12.

Which type of list is optimal for bidirectional traversal?

a)

Singly Linked List

b)

Doubly Linked List

c)

Circular Queue

d)

Stack

13.

Fill in the blank: A (a)   is a collection of nodes and edges.

14.

In a binary search tree, elements to the left of the root are always?

a)

Greater than root

b)

Smaller than root

c)

Equal to root

d)

Not defined

15.

What is the purpose of hashing in data structures?

a)

Searching

b)

Sorting

c)

Memory Allocation

d)

None of the above

16.

Fill in the blank: Hash functions aim to distribute data across an array known as a (a)   .

17.

What is the key property of an optimal binary search tree?

a)

Minimizes average access time

b)

Uses linked lists

c)

Always balanced

d)

None

18.

In stack implementation, which operation checks if the stack is empty?

a)

isEmpty()

b)

isFull()

c)

push()

d)

pop()

19.

Which of the following is used for postfix expression evaluation?

a)

Queue

b)

Stack

c)

Array

d)

Linked List

20.

In a circular queue, what happens when rear meets front?

a)

Queue is empty

b)

Queue is full

c)

Circular loop

d)

Queue resets

21.

The minimum element in a max-heap is found at?

a)

Root

b)

Leaf

c)

Random node

d)

Depends on structure

22.

What is the output of the following code? int arr[] = {1, 2, 3, 4}; printf("%d", arr[2]);

(a)  

23.

Fill in the blank to allocate dynamic memory: int *arr = (a)   (5 * sizeof(int));

24.

What will be the output of this code? int x = 5, y = 10; int *p = &x, *q = &y; *p = *q; printf("%d", x);

(a)  

25.

Predict the output for the following queue operations: enqueue(10), enqueue(20), dequeue(), enqueue(30);

(a)  

26.

Fill in the blank to create a node in a singly linked list: struct Node *newNode = (a)   (sizeof(struct Node));

27.

What will the following code output for linked list traversal? struct Node { int data; struct Node* next; }; // assume linked list has 1 -> 2 -> 3 printf("%d", head->next->data);

(a)  

28.

Given a binary tree with in-order traversal of 2, 4, 5, what is the output of pre-order traversal?

4 lines
29.

Fill in the blanks for binary tree node structure: struct TreeNode { int data; struct TreeNode* _____; struct TreeNode* _____; };

(a)  

30.

What does this code output for a binary tree? struct Node* root; root->left = newNode(2); root->right = newNode(3); printf("%d", root->right->data);

(a)  

31.

What will be the output of the following hashing code? int hash = key % 10; printf("%d", hash); // Assuming key is 15

(a)  

32.

Fill in the blank to insert in a priority queue: priorityQueue.push(____); // assuming min-heap priority queue

4 lines
33.

What is the output if we perform extract-min on a min-heap with elements 3, 5, 7?

(a)  

34.

What is the output for this recursive function? void print(int n) { if (n <= 0) return; printf("%d ", n); print(n - 1); } print(3);

(a)  

35.

Fill in the blank to complete the linked list insertion: newNode->next = _____;

4 lines
36.

Predict the output of the following stack operations: push(1), push(2), pop(), push(3);

(a)  

37.

#include<stdio.h>

struct Ournode{ char x,y,z; };

int main(){

struct Ournode p = {'1', '0', 'a'+2};

struct Ournode q = &p;

printf ("%c, %c", ((char*)q+1), ((char)q+2));

return 0; }

a)

0, c

b)

0, a+2

c)

‘0’, ‘a+2’

d)

‘0’, ‘c’

38.

Consider the binary tree given : and find the level order

a)

5,3,8,1,4,9,7

b)

5,3,8,1,4,7,9

c)

1,3,4,5,7,8,9

d)

1,4,3,5,8,7,9

39.

Given the following preorder and inorder traversals of a binary tree:

Preorder: M, N, O, P, Q, R, S, T

Inorder: O, P, Q, R, N, T, M, S

Reconstruct the binary tree and determine the number of values after the root node.

a)

1

b)

2

c)

5

d)

4

40.

You have a hash table with 8 slots and the following hash function: ℎ(K)=(3K+7)mod 8 If you want to search for the key 5, what is the index where it will be located in the hash table?

a)

5

b)

6

c)

8

d)

7

41.

Why is a circular queue preferred in certain applications over a regular queue?

a)

Circular queues have better memory utilization than regular queues.

b)

Circular queues avoid the issue of front and rear pointers reaching the end, making them more efficient for continuous data streams.

c)

Regular queues have faster insertion and deletion operations compared to circular queues.

d)

Circular queues are only used in specialized applications and are not generally preferred.

42.

Convert the Postfix Expression xy+z* into Prefix

a)

+xy*z

b)

+*xyz

c)

*z+xy

d)

*+xyz

43.

Convert the Postfix Expression xy+z* into Prefix

a)

+xy*z

b)

+*xyz

c)

*z+xy

d)

*+xyz

44.

What is the range of floating point number in C ?

a)

1.7 e -38 to 1.7 e +38

b)

3.4 e -38 to 3.4 e +38

c)

1.7 e -308 to 1.7 e +308

d)

3.4 e -308 to 3.4 e +308

45.

How do you search in O(1)?

(a)  

46.

Which of the following is the sequence obtained from a breadth-first search (Breadth First Search)?

a)

ACFDEB

b)

AFBCDE

c)

DCBEF

d)

DBFEC

47.

How does Depth First Search work?

a)

Root, Left, Right

b)

Left, Root, Right

c)

Pre-order

d)

In-order

48.

Which of the following data structures is used to implement recursion?

a)

Linked List

b)

Array

c)

Stack

d)

Queue

49.

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)

right Transpose of the matrix A

c)

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

d)

None of the above

50.

Consider the following program in C language:

#include<stdio.h> main() { int i; int *pi = &i; scanf("%d", pi); printf("%d\n", i+5); }

a)

Compilation fails

b)

Execution results in a run-time error

c)

On execution, the value printed is 5 more than the address of variable i

d)

On execution, the value printed is 5 more than the integer value entered