Font size
WorksheetsLinked List and Data Structures Quiz
Total questions: 155
Worksheet time: 1hrs 18mins
What is a node in a singly linked list composed of?
Data, previous pointer
Data, next pointer
Only data
Only a pointer
Insertion at the beginning of a singly linked list takes:
O(n) time
O(1) time
O(log n) time
O(n²) time
What is the time complexity to insert an element at the end of a singly linked list (without a tail pointer)?
O(1)
O(n)
O(log n)
O(2n)
Which is an advantage of linked lists over arrays?
Random access
Fixed size
Dynamic size adjustment
Lower memory usage
Which operation is more efficient in a doubly linked list compared to a singly linked list?
Insertion at the head
Deletion of a node given its pointer
Traversal in reverse
Searching
What is the last node’s pointer set to in a circular linked list?
Null
Head node
Tail node
Random node
Which of the following is NOT a linked list type?
Singly linked
Doubly linked
Circular linked
Array-based linked
What is the time complexity to search for an element in a linked list?
O(1)
O(n)
O(log n)
O(n log n)
To reverse a singly linked list, you need to:
Swap data of all nodes
Reverse the direction of pointers
Sort the list
Delete alternate nodes
How do you find the middle element of a linked list in one pass?
Use a stack
Use two pointers (fast and slow)
Count all nodes first
Traverse backward
Which data structure is used to implement a linked list?
Array
Heap
Queue
Dynamic memory (nodes with pointers)
In a singly linked list, the last node’s next pointer is:
Null
Points to the first node
Points to the previous node
Undefined
What is a "dummy node" used for in linked list operations?
To simplify edge cases (e.g., empty list)
To store extra data
To reduce memory usage
To speed up traversal
Which algorithm detects a cycle in a linked list?
Dijkstra’s algorithm
Floyd’s Tortoise and Hare
Binary search
Bubble sort
What is the time complexity to delete a node in a doubly linked list (given the node’s address)?
O(n)
O(1)
O(log n)
O(n²)
In a sorted linked list, the best approach to insert a new element is:
Insert at the head
Insert at the tail
Traverse to find the correct position
Random insertion
Which of the following is true about a circular linked list?
It cannot be empty
The last node points to Null
It requires a tail pointer
It uses less memory than a singly linked list
Merging two sorted linked lists into one sorted list takes:
O(1) time
O(n) time
O(n log n) time
O(n²) time
What happens if you delete a node in a singly linked list without updating pointers?
Memory leak
Segmentation fault
Data corruption
All of the above
Which linked list variation allows traversal in both directions?
Singly linked list
Doubly linked list
Circular linked list
Sorted linked list
What is a data structure?
A way to store and organize data efficiently
A type of database
A programming language
A method for writing algorithms
Which of the following is NOT a linear data structure?
Stack
Queue
Tree
Array
Which of the following operations has O(1) time complexity in an array?
Insertion at the end
Searching an element
Insertion at the beginning
Deletion at the middle
Which data structure follows the Last In First Out (LIFO) principle?
Queue
Stack
Linked List
Hash Table
What is an algorithm?
A programming language
A flowchart
A set of well-defined steps to solve a problem
A computer program
What is the time complexity of searching an element in an unsorted array?
O(1)
O(log n)
O(n)
O(n log n)
Which of the following notations represents the worst-case time complexity?
Big-O (O)
Big-Omega (Ω)
Big-Theta (Θ)
Small-o (o)
What is the best-case time complexity of QuickSort?
O(n)
O(n log n)
O(n²)
O(log n)
Which notation represents the average-case complexity?
O(n)
Θ(n)
Ω(n)
o(n)
If an algorithm has a complexity of O(log n), how does its execution time change when input size doubles?
Doubles
Increases logarithmically
Remains constant
Becomes linear
Which sorting algorithm has the worst-case time complexity of O(n²)?
Merge Sort
Quick Sort
Bubble Sort
Radix Sort
What is the time complexity of Binary Search?
O(n)
O(log n)
O(n log n)
O(n²)
Which of the following sorting algorithms is NOT based on comparison?
Merge Sort
Quick Sort
Bubble Sort
Counting Sort
Which sorting algorithm is best for nearly sorted data?
Quick Sort
Bubble Sort
Insertion Sort
Merge Sort
Which search algorithm works efficiently on sorted data?
Linear Search
Binary Search
Breadth-First Search
Depth-First Search
What is the main difference between a Singly Linked List and a Doubly Linked List?
Singly Linked List stores only one element
Doubly Linked List has references to both next and previous nodes
Singly Linked List cannot store duplicate values
None of the above
What does each node of a singly linked list contain?
Data only
Pointer only
Data and pointer to next node
Data and pointers to both previous and next nodes
How do you traverse a circular linked list?
Using recursion
Using a do-while loop
Using a queue
Using an extra pointer
What is the time complexity for inserting a node in the middle of a doubly linked list?
O(1)
O(n)
O(log n)
O(n log n)
What is a disadvantage of a circular linked list?
Cannot be implemented in Java
Cannot traverse easily using a while loop
Takes more memory than a singly linked list
More complex insertion and deletion operations
What is the space complexity of a singly linked list with n nodes?
O(1)
O(n)
O(log n)
O(n²)
What is the time complexity of a singly linked list with n nodes?
O(1)
O(n)
O(log n)
O(n²)
Which of the following is not a type of Linked List?
Singly Linked List
Doubly Linked List
Circular Linked List
Indexed Linked List
What is the time complexity of deleting the last node in a circular linked list?
O(1)
O(n)
O(log n)
O(n log n)
What is the key advantage of a Linked List over an array?
Random access is faster
Memory allocation is contiguous
Dynamic size and efficient insertions/deletions
Linked Lists are always smaller in size
How do you check if a given Linked List is circular?
Using a HashSet to track visited nodes
Using Floyd’s cycle-finding algorithm
Using a slow and fast pointer approach
All of the above
What is a Circular Linked List?
A Linked List that connects back to itself
A Linked List with a fixed size
A Linked List that cannot store duplicate values
None of the above
How do you remove the last element of a LinkedList in Java?
list.deleteLast()
list.remove(list.size() - 1)
list.removeLast()
list.popLast()
What is the main drawback of a singly linked list?
It requires extra memory
It cannot be traversed backward
It has O(n) insertion at the head
None of the above
What is the time complexity of inserting an element at the tail of a singly linked list (without a tail pointer)?
O(1)
O(n)
O(log n)
O(n²)
What is the time complexity of inserting an element at the tail of a doubly linked list (with a tail pointer)?
O(1)
O(n)
O(log n)
O(n²)
What is the default value of a Node's next reference in Java?
0
null
false
Garbage value
What is the time complexity of inserting an element at the head of a singly linked list?
O(1)
O(n)
O(log n)
O(n²)
What is the time complexity of searching for an element in a singly linked list?
O(1)
O(n)
O(log n)
O(n²)
What is the time complexity of deleting a node from the middle of a singly linked list (given only its reference)?
O(1)
O(n)
O(log n)
O(n²)
Which class in Java provides an implementation of a Linked List?
ArrayList
LinkedList
HashSet
Vector
What is the output of the following code? class Node { int data; Node next; Node(int data) { this.data = data; this.next = null; } } public class Main { public static void main(String[] args) { Node head = new Node(10); head.next = new Node(20); head.next.next = new Node(30); System.out.println(head.next.data); } }
10
20
30
Compilation error
What is the time complexity of reversing a singly linked list?
O(1)
O(n)
O(log n)
O(n²)
What is the time complexity of deleting the last node of a singly linked list (without a tail pointer)?
O(1)
O(n)
O(log n)
O(n²)
What is a Linked List in Java?
A data structure that stores elements in contiguous memory locations
A linear data structure where each element is a separate object
A collection that cannot grow dynamically
None of the above
What is the advantage of a doubly linked list over a singly linked list?
Requires less memory
Faster searching
Can be traversed in both directions
Uses fewer pointers
What is the main disadvantage of a Linked List over an array?
Dynamic size
Requires more memory due to reference
Faster access to elements
Easier to use
What is the time complexity for deleting a node from a doubly linked list?
O(1) if node address is given
O(n) if node address is not given
Both A and B
O(n log n)
What is the time complexity for inserting a node at the tail of a circular linked list?
O(1)
O(n)
O(log n)
O(n log n)
What is the advantage of a doubly linked list over a singly linked list?
Faster search
Uses less memory
Can be traversed in both directions
Cannot be modified
Which of the following statements about circular linked lists is true?
The last node points to null
The last node points to the head
It cannot have more than two nodes
It always contains an even number of nodes
What is the correct way to iterate over an array using an enhanced for loop?
for(int i=0; i
for(int element : arr)
for(int i : arr.length)
while(arr.length > 0)
What is the default value of an array of int in Java?
1
0
null
Garbage value
What is returned by Arrays.binarySearch() when the element is not found?
-1
-2
A negative index
0
How can you dynamically resize an array in Java?
Using resize() method
By reassigning it to a larger array
Using increaseArraySize()
Java arrays cannot be resized
What will be the output of the following code? int[][] arr = {{1, 2}, {3, 4}}; System.out.println(arr[1][1]);
1
2
3
4
How can you convert an array to a list in Java?
Arrays.toList()
Arrays.asList()
Array.asList()
List.toArray()
What is the output of this program? int[] arr = {1, 2, 3}; System.out.println(arr instanceof Object);
true
false
Compilation error
Runtime error
What does Arrays.fill(arr, 5) do?
Fills the array arr with the value 5
Fills only the first five elements
Throws an exception
Does nothing
Which of the following is true about Java arrays?
Arrays can store only primitive data types
Arrays are dynamically resizable
Arrays have a fixed size
Arrays do not allow duplicate values
What is the index of the first element of an array in Java?
0
1
-1
None of the above
Which method is used to sort an array in Java?
Arrays.sort()
Collections.sort()
Sort.sort()
array.sort()
How do you declare an array of 5 integers in Java?
int[5] arr;
int arr[5];
int[] arr = new int[5];
int arr = new int[5];
What will happen if an array index goes out of bounds?
The program will terminate abruptly
The compiler will throw an error
It will return a garbage value
It will continue execution normally
What is the time complexity of accessing an element in an array by index?
O(1)
O(n)
O(log n)
O(n²)
How do you initialize a two-dimensional array in Java?
int[][] arr = new int[3][3];
int arr[][] = new int[3,3];
int arr[3][3] = new int[][];
int arr = new int[3][3];
What is the default value of a boolean array in Java?
true
false
null
Compiler error
What is the default value of a boolean array in Java?
true
false
null
Compiler error
How do you declare an array in Java?
int arr = new int[10];
int arr[] = new int[10];
int[] arr = new int[10];
Both B and C
What is the time complexity of accessing an element in an array?
O(1)
O(n)
O(log n)
O(n²)
How can you copy an array in Java?
System.arraycopy()
Arrays.copyOf()
clone()
All of the above
What will be the output of the following code? int arr[] = new int[5]; System.out.println(arr[2]);
0
2
Compilation error
Runtime error
What is the output of this code? String arr[] = new String[5]; System.out.println(arr[0]);
Empty string ""
null
Compilation error
Garbage value
What will happen if an array element is accessed beyond its size?
Compilation error
Runtime error (ArrayIndexOutOfBoundsException)
The value will be 0
It will return null
How do you initialize an array in Java?
int[] arr = new int[3];
int[] arr = {1, 2, 3};
int arr[] = new int[]{1, 2, 3};
All of the above
What will be the output of the following code? int[][] arr = new int[2][2]; System.out.println(arr[0][1]);
Compilation error
Runtime error
0
Garbage value
What will be the output of the following code? int arr[] = {1, 2, 3, 4, 5}; System.out.println(arr.length);
4
5
6
Compiler error
What is tail recursion?
A recursive call made at the beginning of the function
A recursive call made at the end of the function
A recursive call inside a loop
A recursive function with multiple parameters
What is the recurrence relation for the Fibonacci sequence?
F(n) = F(n-1) + F(n-2)
F(n) = F(n-1) * F(n-2)
F(n) = F(n-1) - F(n-2)
F(n) = F(n-1) / F(n-2)
What is the output of the following function? public class Main { public static int fun(int n) { if (n == 1) return 1; return 2 * fun(n - 1); } public static void main(String[] args) { System.out.println(fun(4)); } }
8
16
4
32
Which of the following sorting algorithms is based on recursion?
Bubble Sort
Quick Sort
Selection Sort
Insertion Sort
What happens when a recursive function lacks a base case?
Runs indefinitely
Throws an exception
Runs but produces no output
Compiles but does nothing
What is the base case in the recursive factorial function?
n == 1
n == 0
n == -1
No base case
What is the space complexity of a recursive function that does not use extra variables?
O(1)
O(n)
O(log n)
O(n²)
Which of the following problems is best solved using recursion?
Finding the largest element in an array
Checking if a number is prime
Tower of Hanoi
Sorting an array
What is the time complexity of the Fibonacci function?
O(n)
O(2ⁿ)
O(n²)
O(log n)
What happens if a recursive function has no base case?
It runs once and stops
It runs indefinitely (StackOverflowError)
It runs in a loop
It gives a compilation error
What is recursion in Java?
A function calling another function
A function calling itself
A function that runs infinitely
A function with multiple parameters
What data structure is used for function calls in recursion?
Queue
Stack
Heap
Linked List
What is the base case in recursion?
The case when the function calls itself
The condition that stops the recursion
The middle element in recursion
The first function call
What is the primary advantage of recursion?
It makes code easier to understand
It improves execution speed
It reduces memory usage
It always avoids loops
What is the time complexity of computing the nth Fibonacci number using recursion?
O(n)
O(log n)
O(2ⁿ)
O(n²)
What is the worst-case time complexity of QuickSort using recursion?
O(n log n)
O(n²)
O(n)
O(log n)
What will be the output of the following function? public class Main { public static void print(int n) { if (n == 0) return; System.out.print(n + " "); print(n - 1); System.out.print(n + " "); } public static void main(String[] args) { print(3); } }
3 2 1 1 2 3
3 2 1
1 2 3
3 2 1 2 3
What will be the output of the following recursive function? public class Main { public static int factorial(int n) { if (n == 0) return 1; return n * factorial(n - 1); } public static void main(String[] args) { System.out.println(factorial(4)); } }
24
10
4
Compilation error
What will be the output of the following recursive function? public class Main { public static void fun(int n) { if (n <= 0) return; fun(n - 1); System.out.print(n + " "); fun(n - 1); } public static void main(String[] args) { fun(3); } }
3 2 1
1 2 1 3 1 2 1
1 2 3 2 1
Compilation error
What will be the output of this recursive function? public class Main { public static void fun(int n) { if (n == 0) return; System.out.print(n + " "); fun(n / 2); } public static void main(String[] args) { fun(10); } }
10 5 2 1
10 5 2 1 0
10 5 2
10 2 1
What will be the output of the following function? public class Main { public static int power(int base, int exp) { if (exp == 0) return 1; return base * power(base, exp - 1); } public static void main(String[] args) { System.out.println(power(2, 3)); } }
8
6
9
12
What will be the output of the following recursive function? public class Main { public static void fun(int n) { if (n == 0) return; System.out.print(n + " "); fun(n - 1); } public static void main(String[] args) { fun(5); } }
1 2 3 4 5
5 4 3 2 1
5 4 3 2
Infinite loop
What will be the output of the following recursive function? public class Main { public static void fun(int n) { if (n == 0) return; fun(n - 1); System.out.print(n + " "); } public static void main(String[] args) { fun(3); } }
3 2 1
1 2 3
3 2 1 0
Compilation error
What is the output of the following recursive function? public class Main { public static int fun(int n) { if (n <= 1) return n; return fun(n - 1) + fun(n - 2); } public static void main(String[] args) { System.out.println(fun(5)); } }
5
8
10
12
Which of the following best describes indirect recursion?
A function calling itself
Two or more functions calling each other in a cycle
A function that never stops
A function with multiple parameters
Which of the following problems is best solved using recursion?
Sorting an array
Tower of Hanoi
Printing elements of an array
Multiplication of two numbers
How can recursion be optimized?
Using loops
Using memoization
Using switch-case
Increasing function calls
Why are strings immutable in Java?
Security reasons
Performance optimization
String pooling
All of the above
Which of the following creates an empty string in Java?
String s = "";
String s = new String();
Both A and B
None of the above
What is the correct way to append text in StringBuilder?
sb.append("text");
sb.add("text");
sb.concatenate("text");
sb.plus("text");
What does str.trim() do?
Removes spaces from the start
Removes spaces from the end
Removes spaces from both ends
Does nothing
Which of the following is true about Java Strings?
Strings are mutable
Strings are immutable
Strings cannot be created using new
Strings are stored in stack memory
What will be the output of the following code? String s = "hello"; s = s.replace('l', 'w'); System.out.println(s);
hello
hewwo
hwwwo
Compilation error
Which class provides a mutable version of String?
StringBuffer
StringBuilder
Both A and B
None of the above
What is the return type of charAt(int index)?
char
int
String
boolean
What is the difference between StringBuilder and StringBuffer?
StringBuffer is synchronized, StringBuilder is not
StringBuilder is synchronized, StringBuffer is not
Both are the same
None of the above
Which method converts a string to a character array?
toCharArray()
toArray()
split()
charArray()
Which method is used to split a string into an array?
split()
substring()
cut()
divide()
What is the output of System.out.println("Java".indexOf('b'));?
1
2
-1
Compilation error
How do you compare two strings for equality in Java?
str1 == str2
str1.equals(str2)
str1.compareTo(str2) == 0
Both B and C
What is the return type of split() method?
String
String[]
List
int
What will be the output of this code? String s = "Hello"; System.out.println(s.length);
4
5
6
Compilation error
What will be the output of this code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
true
false
Compilation error
Runtime error
Strings in Java are stored in?
Heap memory
Stack memory
String pool (inside Heap memory)
Register memory
Which of the following is used to declare a String in Java?
String str = "Hello";
String str = new String("Hello");
Both A and B
None of the above
What will be the output of this code? String s = "Java"; System.out.println(s.substring(1, 3));
Ja
av
va
Compilation error
What is the correct way to concatenate two strings in Java?
str1.concat(str2);
str1 + str2;
str1.append(str2);
Both A and B
What is the main advantage of StringBuilder over String?
Faster performance for modifications
Thread safety
Uses less memory
None of the above
What will be the output of this code? String s = "Java"; System.out.println(s.replace('a', 'o'));
Jovo
Jova
Jovoa
Compilation error
What will be the output of the following code? StringBuilder sb = new StringBuilder("Java"); sb.append(" Programming"); System.out.println(sb);
Java
Java Programming
Compilation error
Runtime error
What will be the output of this code? String s = "Java Programming"; System.out.println(s.split(" ")[0]);
Java
Programming
Java Programming
Compilation error
What will be the output of this code? String s = "Hello"; s = s.concat(" World"); System.out.println(s);
Hello
Hello World
World
Compilation error
What will be the output of this code? String s1 = "Hello"; String s2 = "hello"; System.out.println(s1.equalsIgnoreCase(s2));
true
false
Compilation error
Runtime error
What will be the output of this code? String s1 = new String("Hello"); String s2 = new String("Hello"); System.out.println(s1 == s2);
true
false
Compilation error
Runtime error
What will be the output of this code? String s = "Java"; System.out.println(s.charAt(2));
J
a
v
Compilation error
What will be the output of this code? String s = " Java "; System.out.println(s.trim());
" Java "
"Java"
" Java"
Compilation error
What will be the output of this code? String s = "Hello"; System.out.println(s.concat(null));
Hello
nullHello
Compilation error
Runtime error
Which data structure is used for implementing recursion?
Stack
Queue
List
Array
What will be the output of the following code?
Stack
XYZ
ZYX
YZX
EmptyStackException
Which of the following is NOT an application of stack?
Data transfer between two asynchronous processes
Compiler syntax analyzer
Tracking local variables at runtime
Parentheses balancing program
What is the value of the postfix expression 6 3 2 4 + – *?
74
-18
22
40
Which data structure is needed to convert infix to postfix notation?
Tree
Branch
Stack
Queue
What is the optimal data structure used to solve Tower of Hanoi?
Tree
Heap
Priority queue
Stack
