Font size
WorksheetsCodeMavarick
Total questions: 20
Worksheet time: 10mins
Question: What will be the output of the following code snippet?
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[5]);
5
0
Garbage Value
Compilation Error
What is the time complexity of accessing an element in an array by its index?
O(1)
O(n)
O(log n)
O(n^2)
What is the time complexity of the following code?
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
printf("Hello");
} }
O(n)
O(n log n)
O(n^2)
O(log n)
What does the following code do?
struct Node {
int data;
struct Node* next; };
struct Node* head = NULL;
head->data = 10;
Creates a node with data 10
Causes a segmentation fault
Initializes an empty linked list
Links two nodes
What is the time complexity of inserting a node at the end of a singly linked list with no tail pointer?
O(1)
O(n)
O(n log n)
O(n^2)
Spot the error:
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = 5;
newNode->next = newNode;
No error
Creates a circular reference
Missing free() call
Incorrect malloc syntax
How many moves are required to solve the Tower of Hanoi puzzle with 5 disks?
32
16
31
25
Find the error in this stack push operation:
void push(int stack[], int* top, int value) {
stack[++(*top)] = value;
}
No error
Missing bounds check
Incorrect increment syntax
Value not assigned correctly
What will this code output?
int arr[3] = {1, 2, 3};
for(int i = 0; i <= 3; i++) {
printf("%d ", arr[i]);
}
1 2 3
1 2 3 0
1 2 3 followed by garbage
Compilation error
Which line contains an error?
1: struct Node* head = NULL;
2: head = (struct Node*)malloc(sizeof(struct Node));
3: head->data = 10;
4: free(head->next);
Line 1
Line 2
Line 3
line 4
What happens when you execute this code?
int arr[3];
arr[3] = 10;
printf("%d", arr[0]);
Prints 10
Prints 0
Undefined behavior
Compilation error
What is the time complexity of reversing an array of size n using a two-pointer approach (swapping elements from both ends)?
O(1)
O(n)
O(n/2)
O(n^2)
Which of these has a tighter bound on its worst-case time complexity?
Linear search on an unsorted array: O(n)
Binary search on a sorted array: O(log n)
Bubble sort: O(n^2)
Accessing an array element: O(1)
In a singly linked list with n nodes, what is the minimum number of pointers that must be updated to delete the k-th node (1 ≤ k < n)?
0
1
2
3
If the Tower of Hanoi recursion is modified to move disks directly between source and destination (skipping the auxiliary peg), what happens?
It solves faster
It becomes impossible for n > 1
Time complexity drops to O(n)
Only even-numbered disks can be moved
Spot the error:
Memory leak
Infinite loop
Incorrect list construction
Null pointer dereference
Which of the following statements are true about this code when executed with n = 5?
int arr[5] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i <= n; i++) {
sum += arr[i];
}
printf("%d", sum);
It correctly computes the sum of all elements (15).
It accesses memory out of bounds.
It causes a compilation error due to n not being defined.
The output is unpredictable due to undefined behavior.
Which outcomes are possible when running this circular queue code with capacity 3?
Prints "1 3"
Prints "1 4"
The queue overflows with undefined behavior
The last enqueue silently fails, keeping the queue valid
What is the primary advantage of using an array over other data structures?
Dynamic size
Fast random access
Efficient insertion at the beginning
Automatic memory management
What is the main difference between a singly linked list and an array?
A linked list stores elements in contiguous memory
A linked list has a fixed size
A linked list uses pointers to connect elements
A linked list allows faster indexing
