WorksheetsData Structures Quiz
Total questions: 50
Worksheet time: 3600secs
Dynamic memory allocation in C is done using which function?
malloc
calloc
free
both a and b
In C, which operator is used to access the address of a variable?
(a)
What is the time complexity of accessing an element in an array?
O(1)
O(n)
O(n^2)
O(log n)
Which of the following is a hashing technique?
Linear Probing
Open Addressing
Both a and b
None
What data structure is often used for managing memory allocation?
Stack
Queue
Array
Linked List
What is the primary difference between a structure and a union in C?
Structure has shared memory
Union has shared memory
Both are identical
None of the above
The process of accessing elements in a specific order in a data structure is called?
Sorting
Traversing
Searching
Deleting
Which data structure allows multiple pointers to refer to the same node?
Stack
Circular Queue
Linked List
Array
What type of queue has a front and rear pointer that wrap around?
Circular Queue
Double-ended Queue
Simple Queue
Priority Queue
What is the time complexity of inserting an element in a linked list at the beginning?
O(1)
O(n)
O(n^2)
O(log n)
Fill in the blank: A (a) traversal visits each node in a binary tree starting from the left, root, then right.
Which type of list is optimal for bidirectional traversal?
Singly Linked List
Doubly Linked List
Circular Queue
Stack
Fill in the blank: A (a) is a collection of nodes and edges.
In a binary search tree, elements to the left of the root are always?
Greater than root
Smaller than root
Equal to root
Not defined
What is the purpose of hashing in data structures?
Searching
Sorting
Memory Allocation
None of the above
Fill in the blank: Hash functions aim to distribute data across an array known as a (a) .
What is the key property of an optimal binary search tree?
Minimizes average access time
Uses linked lists
Always balanced
None
In stack implementation, which operation checks if the stack is empty?
isEmpty()
isFull()
push()
pop()
Which of the following is used for postfix expression evaluation?
Queue
Stack
Array
Linked List
In a circular queue, what happens when rear meets front?
Queue is empty
Queue is full
Circular loop
Queue resets
The minimum element in a max-heap is found at?
Root
Leaf
Random node
Depends on structure
What is the output of the following code?
int arr[] = {1, 2, 3, 4};
printf("%d", arr[2]);
(a)
Fill in the blank to allocate dynamic memory: int *arr = (a) (5 * sizeof(int));
What will be the output of this code?
int x = 5, y = 10;
int *p = &x, *q = &y;
*p = *q;
printf("%d", x);
(a)
Predict the output for the following queue operations:
enqueue(10), enqueue(20), dequeue(), enqueue(30);
(a)
Fill in the blank to create a node in a singly linked list: struct Node *newNode = (a) (sizeof(struct Node));
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)
Given a binary tree with in-order traversal of 2, 4, 5, what is the output of pre-order traversal?
Fill in the blanks for binary tree node structure:
struct TreeNode {
int data;
struct TreeNode* _____;
struct TreeNode* _____;
};
(a)
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)
What will be the output of the following hashing code?
int hash = key % 10;
printf("%d", hash);
// Assuming key is 15
(a)
Fill in the blank to insert in a priority queue: priorityQueue.push(____); // assuming min-heap priority queue
What is the output if we perform extract-min on a min-heap with elements 3, 5, 7?
(a)
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)
Fill in the blank to complete the linked list insertion: newNode->next = _____;
Predict the output of the following stack operations:
push(1), push(2), pop(), push(3);
(a)
#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; }
0, c
0, a+2
‘0’, ‘a+2’
‘0’, ‘c’
Consider the binary tree given : and find the level order
5,3,8,1,4,9,7
5,3,8,1,4,7,9
1,3,4,5,7,8,9
1,4,3,5,8,7,9
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.
1
2
5
4
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?
5
6
8
7
Why is a circular queue preferred in certain applications over a regular queue?
Circular queues have better memory utilization than regular queues.
Circular queues avoid the issue of front and rear pointers reaching the end, making them more efficient for continuous data streams.
Regular queues have faster insertion and deletion operations compared to circular queues.
Circular queues are only used in specialized applications and are not generally preferred.
Convert the Postfix Expression xy+z* into Prefix
+xy*z
+*xyz
*z+xy
*+xyz
Convert the Postfix Expression xy+z* into Prefix
+xy*z
+*xyz
*z+xy
*+xyz
What is the range of floating point number in C ?
1.7 e -38 to 1.7 e +38
3.4 e -38 to 3.4 e +38
1.7 e -308 to 1.7 e +308
3.4 e -308 to 3.4 e +308
How do you search in O(1)?
(a)
Which of the following is the sequence obtained from a breadth-first search (Breadth First Search)?
ACFDEB
AFBCDE
DCBEF
DBFEC
How does Depth First Search work?
Root, Left, Right
Left, Root, Right
Pre-order
In-order
Which of the following data structures is used to implement recursion?
Linked List
Array
Stack
Queue
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]);
The matrix A itself
right Transpose of the matrix A
Adding 100 to upper diagonal elements and subtracting 100 from diagonal elements of A
None of the above
Consider the following program in C language:
#include<stdio.h> main() { int i; int *pi = &i; scanf("%d", pi); printf("%d\n", i+5); }
Compilation fails
Execution results in a run-time error
On execution, the value printed is 5 more than the address of variable i
On execution, the value printed is 5 more than the integer value entered
