wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Linked List and Data Structures Quiz

Total questions: 155

Worksheet time: 1hrs 18mins

Name
Class
Date
1.

What is a node in a singly linked list composed of?

a)

Data, previous pointer

b)

Data, next pointer

c)

Only data

d)

Only a pointer

2.

Insertion at the beginning of a singly linked list takes:

a)

O(n) time

b)

O(1) time

c)

O(log n) time

d)

O(n²) time

3.

What is the time complexity to insert an element at the end of a singly linked list (without a tail pointer)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(2n)

4.

Which is an advantage of linked lists over arrays?

a)

Random access

b)

Fixed size

c)

Dynamic size adjustment

d)

Lower memory usage

5.

Which operation is more efficient in a doubly linked list compared to a singly linked list?

a)

Insertion at the head

b)

Deletion of a node given its pointer

c)

Traversal in reverse

d)

Searching

6.

What is the last node’s pointer set to in a circular linked list?

a)

Null

b)

Head node

c)

Tail node

d)

Random node

7.

Which of the following is NOT a linked list type?

a)

Singly linked

b)

Doubly linked

c)

Circular linked

d)

Array-based linked

8.

What is the time complexity to search for an element in a linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

9.

To reverse a singly linked list, you need to:

a)

Swap data of all nodes

b)

Reverse the direction of pointers

c)

Sort the list

d)

Delete alternate nodes

10.

How do you find the middle element of a linked list in one pass?

a)

Use a stack

b)

Use two pointers (fast and slow)

c)

Count all nodes first

d)

Traverse backward

11.

Which data structure is used to implement a linked list?

a)

Array

b)

Heap

c)

Queue

d)

Dynamic memory (nodes with pointers)

12.

In a singly linked list, the last node’s next pointer is:

a)

Null

b)

Points to the first node

c)

Points to the previous node

d)

Undefined

13.

What is a "dummy node" used for in linked list operations?

a)

To simplify edge cases (e.g., empty list)

b)

To store extra data

c)

To reduce memory usage

d)

To speed up traversal

14.

Which algorithm detects a cycle in a linked list?

a)

Dijkstra’s algorithm

b)

Floyd’s Tortoise and Hare

c)

Binary search

d)

Bubble sort

15.

What is the time complexity to delete a node in a doubly linked list (given the node’s address)?

a)

O(n)

b)

O(1)

c)

O(log n)

d)

O(n²)

16.

In a sorted linked list, the best approach to insert a new element is:

a)

Insert at the head

b)

Insert at the tail

c)

Traverse to find the correct position

d)

Random insertion

17.

Which of the following is true about a circular linked list?

a)

It cannot be empty

b)

The last node points to Null

c)

It requires a tail pointer

d)

It uses less memory than a singly linked list

18.

Merging two sorted linked lists into one sorted list takes:

a)

O(1) time

b)

O(n) time

c)

O(n log n) time

d)

O(n²) time

19.

What happens if you delete a node in a singly linked list without updating pointers?

a)

Memory leak

b)

Segmentation fault

c)

Data corruption

d)

All of the above

20.

Which linked list variation allows traversal in both directions?

a)

Singly linked list

b)

Doubly linked list

c)

Circular linked list

d)

Sorted linked list

21.

What is a data structure?

a)

A way to store and organize data efficiently

b)

A type of database

c)

A programming language

d)

A method for writing algorithms

22.

Which of the following is NOT a linear data structure?

a)

Stack

b)

Queue

c)

Tree

d)

Array

23.

Which of the following operations has O(1) time complexity in an array?

a)

Insertion at the end

b)

Searching an element

c)

Insertion at the beginning

d)

Deletion at the middle

24.

Which data structure follows the Last In First Out (LIFO) principle?

a)

Queue

b)

Stack

c)

Linked List

d)

Hash Table

25.

What is an algorithm?

a)

A programming language

b)

A flowchart

c)

A set of well-defined steps to solve a problem

d)

A computer program

26.

What is the time complexity of searching an element in an unsorted array?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n log n)

27.

Which of the following notations represents the worst-case time complexity?

a)

Big-O (O)

b)

Big-Omega (Ω)

c)

Big-Theta (Θ)

d)

Small-o (o)

28.

What is the best-case time complexity of QuickSort?

a)

O(n)

b)

O(n log n)

c)

O(n²)

d)

O(log n)

29.

Which notation represents the average-case complexity?

a)

O(n)

b)

Θ(n)

c)

Ω(n)

d)

o(n)

30.

If an algorithm has a complexity of O(log n), how does its execution time change when input size doubles?

a)

Doubles

b)

Increases logarithmically

c)

Remains constant

d)

Becomes linear

31.

Which sorting algorithm has the worst-case time complexity of O(n²)?

a)

Merge Sort

b)

Quick Sort

c)

Bubble Sort

d)

Radix Sort

32.

What is the time complexity of Binary Search?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(n²)

33.

Which of the following sorting algorithms is NOT based on comparison?

a)

Merge Sort

b)

Quick Sort

c)

Bubble Sort

d)

Counting Sort

34.

Which sorting algorithm is best for nearly sorted data?

a)

Quick Sort

b)

Bubble Sort

c)

Insertion Sort

d)

Merge Sort

35.

Which search algorithm works efficiently on sorted data?

a)

Linear Search

b)

Binary Search

c)

Breadth-First Search

d)

Depth-First Search

36.

What is the main difference between a Singly Linked List and a Doubly Linked List?

a)

Singly Linked List stores only one element

b)

Doubly Linked List has references to both next and previous nodes

c)

Singly Linked List cannot store duplicate values

d)

None of the above

37.

What does each node of a singly linked list contain?

a)

Data only

b)

Pointer only

c)

Data and pointer to next node

d)

Data and pointers to both previous and next nodes

38.

How do you traverse a circular linked list?

a)

Using recursion

b)

Using a do-while loop

c)

Using a queue

d)

Using an extra pointer

39.

What is the time complexity for inserting a node in the middle of a doubly linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

40.

What is a disadvantage of a circular linked list?

a)

Cannot be implemented in Java

b)

Cannot traverse easily using a while loop

c)

Takes more memory than a singly linked list

d)

More complex insertion and deletion operations

41.

What is the space complexity of a singly linked list with n nodes?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

42.

What is the time complexity of a singly linked list with n nodes?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

43.

Which of the following is not a type of Linked List?

a)

Singly Linked List

b)

Doubly Linked List

c)

Circular Linked List

d)

Indexed Linked List

44.

What is the time complexity of deleting the last node in a circular linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

45.

What is the key advantage of a Linked List over an array?

a)

Random access is faster

b)

Memory allocation is contiguous

c)

Dynamic size and efficient insertions/deletions

d)

Linked Lists are always smaller in size

46.

How do you check if a given Linked List is circular?

a)

Using a HashSet to track visited nodes

b)

Using Floyd’s cycle-finding algorithm

c)

Using a slow and fast pointer approach

d)

All of the above

47.

What is a Circular Linked List?

a)

A Linked List that connects back to itself

b)

A Linked List with a fixed size

c)

A Linked List that cannot store duplicate values

d)

None of the above

48.

How do you remove the last element of a LinkedList in Java?

a)

list.deleteLast()

b)

list.remove(list.size() - 1)

c)

list.removeLast()

d)

list.popLast()

49.

What is the main drawback of a singly linked list?

a)

It requires extra memory

b)

It cannot be traversed backward

c)

It has O(n) insertion at the head

d)

None of the above

50.

What is the time complexity of inserting an element at the tail of a singly linked list (without a tail pointer)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

51.

What is the time complexity of inserting an element at the tail of a doubly linked list (with a tail pointer)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

52.

What is the default value of a Node's next reference in Java?

a)

0

b)

null

c)

false

d)

Garbage value

53.

What is the time complexity of inserting an element at the head of a singly linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

54.

What is the time complexity of searching for an element in a singly linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

55.

What is the time complexity of deleting a node from the middle of a singly linked list (given only its reference)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

56.

Which class in Java provides an implementation of a Linked List?

a)

ArrayList

b)

LinkedList

c)

HashSet

d)

Vector

57.

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); } }

a)

10

b)

20

c)

30

d)

Compilation error

58.

What is the time complexity of reversing a singly linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

59.

What is the time complexity of deleting the last node of a singly linked list (without a tail pointer)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

60.

What is a Linked List in Java?

a)

A data structure that stores elements in contiguous memory locations

b)

A linear data structure where each element is a separate object

c)

A collection that cannot grow dynamically

d)

None of the above

61.

What is the advantage of a doubly linked list over a singly linked list?

a)

Requires less memory

b)

Faster searching

c)

Can be traversed in both directions

d)

Uses fewer pointers

62.

What is the main disadvantage of a Linked List over an array?

a)

Dynamic size

b)

Requires more memory due to reference

c)

Faster access to elements

d)

Easier to use

63.

What is the time complexity for deleting a node from a doubly linked list?

a)

O(1) if node address is given

b)

O(n) if node address is not given

c)

Both A and B

d)

O(n log n)

64.

What is the time complexity for inserting a node at the tail of a circular linked list?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

65.

What is the advantage of a doubly linked list over a singly linked list?

a)

Faster search

b)

Uses less memory

c)

Can be traversed in both directions

d)

Cannot be modified

66.

Which of the following statements about circular linked lists is true?

a)

The last node points to null

b)

The last node points to the head

c)

It cannot have more than two nodes

d)

It always contains an even number of nodes

67.

What is the correct way to iterate over an array using an enhanced for loop?

a)

for(int i=0; i

b)

for(int element : arr)

c)

for(int i : arr.length)

d)

while(arr.length > 0)

68.

What is the default value of an array of int in Java?

a)

1

b)

0

c)

null

d)

Garbage value

69.

What is returned by Arrays.binarySearch() when the element is not found?

a)

-1

b)

-2

c)

A negative index

d)

0

70.

How can you dynamically resize an array in Java?

a)

Using resize() method

b)

By reassigning it to a larger array

c)

Using increaseArraySize()

d)

Java arrays cannot be resized

71.

What will be the output of the following code? int[][] arr = {{1, 2}, {3, 4}}; System.out.println(arr[1][1]);

a)

1

b)

2

c)

3

d)

4

72.

How can you convert an array to a list in Java?

a)

Arrays.toList()

b)

Arrays.asList()

c)

Array.asList()

d)

List.toArray()

73.

What is the output of this program? int[] arr = {1, 2, 3}; System.out.println(arr instanceof Object);

a)

true

b)

false

c)

Compilation error

d)

Runtime error

74.

What does Arrays.fill(arr, 5) do?

a)

Fills the array arr with the value 5

b)

Fills only the first five elements

c)

Throws an exception

d)

Does nothing

75.

Which of the following is true about Java arrays?

a)

Arrays can store only primitive data types

b)

Arrays are dynamically resizable

c)

Arrays have a fixed size

d)

Arrays do not allow duplicate values

76.

What is the index of the first element of an array in Java?

a)

0

b)

1

c)

-1

d)

None of the above

77.

Which method is used to sort an array in Java?

a)

Arrays.sort()

b)

Collections.sort()

c)

Sort.sort()

d)

array.sort()

78.

How do you declare an array of 5 integers in Java?

a)

int[5] arr;

b)

int arr[5];

c)

int[] arr = new int[5];

d)

int arr = new int[5];

79.

What will happen if an array index goes out of bounds?

a)

The program will terminate abruptly

b)

The compiler will throw an error

c)

It will return a garbage value

d)

It will continue execution normally

80.

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

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

81.

How do you initialize a two-dimensional array in Java?

a)

int[][] arr = new int[3][3];

b)

int arr[][] = new int[3,3];

c)

int arr[3][3] = new int[][];

d)

int arr = new int[3][3];

82.

What is the default value of a boolean array in Java?

a)

true

b)

false

c)

null

d)

Compiler error

83.

What is the default value of a boolean array in Java?

a)

true

b)

false

c)

null

d)

Compiler error

84.

How do you declare an array in Java?

a)

int arr = new int[10];

b)

int arr[] = new int[10];

c)

int[] arr = new int[10];

d)

Both B and C

85.

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

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

86.

How can you copy an array in Java?

a)

System.arraycopy()

b)

Arrays.copyOf()

c)

clone()

d)

All of the above

87.

What will be the output of the following code? int arr[] = new int[5]; System.out.println(arr[2]);

a)

0

b)

2

c)

Compilation error

d)

Runtime error

88.

What is the output of this code? String arr[] = new String[5]; System.out.println(arr[0]);

a)

Empty string ""

b)

null

c)

Compilation error

d)

Garbage value

89.

What will happen if an array element is accessed beyond its size?

a)

Compilation error

b)

Runtime error (ArrayIndexOutOfBoundsException)

c)

The value will be 0

d)

It will return null

90.

How do you initialize an array in Java?

a)

int[] arr = new int[3];

b)

int[] arr = {1, 2, 3};

c)

int arr[] = new int[]{1, 2, 3};

d)

All of the above

91.

What will be the output of the following code? int[][] arr = new int[2][2]; System.out.println(arr[0][1]);

a)

Compilation error

b)

Runtime error

c)

0

d)

Garbage value

92.

What will be the output of the following code? int arr[] = {1, 2, 3, 4, 5}; System.out.println(arr.length);

a)

4

b)

5

c)

6

d)

Compiler error

93.

What is tail recursion?

a)

A recursive call made at the beginning of the function

b)

A recursive call made at the end of the function

c)

A recursive call inside a loop

d)

A recursive function with multiple parameters

94.

What is the recurrence relation for the Fibonacci sequence?

a)

F(n) = F(n-1) + F(n-2)

b)

F(n) = F(n-1) * F(n-2)

c)

F(n) = F(n-1) - F(n-2)

d)

F(n) = F(n-1) / F(n-2)

95.

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)); } }

a)

8

b)

16

c)

4

d)

32

96.

Which of the following sorting algorithms is based on recursion?

a)

Bubble Sort

b)

Quick Sort

c)

Selection Sort

d)

Insertion Sort

97.

What happens when a recursive function lacks a base case?

a)

Runs indefinitely

b)

Throws an exception

c)

Runs but produces no output

d)

Compiles but does nothing

98.

What is the base case in the recursive factorial function?

a)

n == 1

b)

n == 0

c)

n == -1

d)

No base case

99.

What is the space complexity of a recursive function that does not use extra variables?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

100.

Which of the following problems is best solved using recursion?

a)

Finding the largest element in an array

b)

Checking if a number is prime

c)

Tower of Hanoi

d)

Sorting an array

101.

What is the time complexity of the Fibonacci function?

a)

O(n)

b)

O(2ⁿ)

c)

O(n²)

d)

O(log n)

102.

What happens if a recursive function has no base case?

a)

It runs once and stops

b)

It runs indefinitely (StackOverflowError)

c)

It runs in a loop

d)

It gives a compilation error

103.

What is recursion in Java?

a)

A function calling another function

b)

A function calling itself

c)

A function that runs infinitely

d)

A function with multiple parameters

104.

What data structure is used for function calls in recursion?

a)

Queue

b)

Stack

c)

Heap

d)

Linked List

105.

What is the base case in recursion?

a)

The case when the function calls itself

b)

The condition that stops the recursion

c)

The middle element in recursion

d)

The first function call

106.

What is the primary advantage of recursion?

a)

It makes code easier to understand

b)

It improves execution speed

c)

It reduces memory usage

d)

It always avoids loops

107.

What is the time complexity of computing the nth Fibonacci number using recursion?

a)

O(n)

b)

O(log n)

c)

O(2ⁿ)

d)

O(n²)

108.

What is the worst-case time complexity of QuickSort using recursion?

a)

O(n log n)

b)

O(n²)

c)

O(n)

d)

O(log n)

109.

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); } }

a)

3 2 1 1 2 3

b)

3 2 1

c)

1 2 3

d)

3 2 1 2 3

110.

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)); } }

a)

24

b)

10

c)

4

d)

Compilation error

111.

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); } }

a)

3 2 1

b)

1 2 1 3 1 2 1

c)

1 2 3 2 1

d)

Compilation error

112.

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); } }

a)

10 5 2 1

b)

10 5 2 1 0

c)

10 5 2

d)

10 2 1

113.

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)); } }

a)

8

b)

6

c)

9

d)

12

114.

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); } }

a)

1 2 3 4 5

b)

5 4 3 2 1

c)

5 4 3 2

d)

Infinite loop

115.

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); } }

a)

3 2 1

b)

1 2 3

c)

3 2 1 0

d)

Compilation error

116.

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)); } }

a)

5

b)

8

c)

10

d)

12

117.

Which of the following best describes indirect recursion?

a)

A function calling itself

b)

Two or more functions calling each other in a cycle

c)

A function that never stops

d)

A function with multiple parameters

118.

Which of the following problems is best solved using recursion?

a)

Sorting an array

b)

Tower of Hanoi

c)

Printing elements of an array

d)

Multiplication of two numbers

119.

How can recursion be optimized?

a)

Using loops

b)

Using memoization

c)

Using switch-case

d)

Increasing function calls

120.

Why are strings immutable in Java?

a)

Security reasons

b)

Performance optimization

c)

String pooling

d)

All of the above

121.

Which of the following creates an empty string in Java?

a)

String s = "";

b)

String s = new String();

c)

Both A and B

d)

None of the above

122.

What is the correct way to append text in StringBuilder?

a)

sb.append("text");

b)

sb.add("text");

c)

sb.concatenate("text");

d)

sb.plus("text");

123.

What does str.trim() do?

a)

Removes spaces from the start

b)

Removes spaces from the end

c)

Removes spaces from both ends

d)

Does nothing

124.

Which of the following is true about Java Strings?

a)

Strings are mutable

b)

Strings are immutable

c)

Strings cannot be created using new

d)

Strings are stored in stack memory

125.

What will be the output of the following code? String s = "hello"; s = s.replace('l', 'w'); System.out.println(s);

a)

hello

b)

hewwo

c)

hwwwo

d)

Compilation error

126.

Which class provides a mutable version of String?

a)

StringBuffer

b)

StringBuilder

c)

Both A and B

d)

None of the above

127.

What is the return type of charAt(int index)?

a)

char

b)

int

c)

String

d)

boolean

128.

What is the difference between StringBuilder and StringBuffer?

a)

StringBuffer is synchronized, StringBuilder is not

b)

StringBuilder is synchronized, StringBuffer is not

c)

Both are the same

d)

None of the above

129.

Which method converts a string to a character array?

a)

toCharArray()

b)

toArray()

c)

split()

d)

charArray()

130.

Which method is used to split a string into an array?

a)

split()

b)

substring()

c)

cut()

d)

divide()

131.

What is the output of System.out.println("Java".indexOf('b'));?

a)

1

b)

2

c)

-1

d)

Compilation error

132.

How do you compare two strings for equality in Java?

a)

str1 == str2

b)

str1.equals(str2)

c)

str1.compareTo(str2) == 0

d)

Both B and C

133.

What is the return type of split() method?

a)

String

b)

String[]

c)

List

d)

int

134.

What will be the output of this code? String s = "Hello"; System.out.println(s.length);

a)

4

b)

5

c)

6

d)

Compilation error

135.

What will be the output of this code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);

a)

true

b)

false

c)

Compilation error

d)

Runtime error

136.

Strings in Java are stored in?

a)

Heap memory

b)

Stack memory

c)

String pool (inside Heap memory)

d)

Register memory

137.

Which of the following is used to declare a String in Java?

a)

String str = "Hello";

b)

String str = new String("Hello");

c)

Both A and B

d)

None of the above

138.

What will be the output of this code? String s = "Java"; System.out.println(s.substring(1, 3));

a)

Ja

b)

av

c)

va

d)

Compilation error

139.

What is the correct way to concatenate two strings in Java?

a)

str1.concat(str2);

b)

str1 + str2;

c)

str1.append(str2);

d)

Both A and B

140.

What is the main advantage of StringBuilder over String?

a)

Faster performance for modifications

b)

Thread safety

c)

Uses less memory

d)

None of the above

141.

What will be the output of this code? String s = "Java"; System.out.println(s.replace('a', 'o'));

a)

Jovo

b)

Jova

c)

Jovoa

d)

Compilation error

142.

What will be the output of the following code? StringBuilder sb = new StringBuilder("Java"); sb.append(" Programming"); System.out.println(sb);

a)

Java

b)

Java Programming

c)

Compilation error

d)

Runtime error

143.

What will be the output of this code? String s = "Java Programming"; System.out.println(s.split(" ")[0]);

a)

Java

b)

Programming

c)

Java Programming

d)

Compilation error

144.

What will be the output of this code? String s = "Hello"; s = s.concat(" World"); System.out.println(s);

a)

Hello

b)

Hello World

c)

World

d)

Compilation error

145.

What will be the output of this code? String s1 = "Hello"; String s2 = "hello"; System.out.println(s1.equalsIgnoreCase(s2));

a)

true

b)

false

c)

Compilation error

d)

Runtime error

146.

What will be the output of this code? String s1 = new String("Hello"); String s2 = new String("Hello"); System.out.println(s1 == s2);

a)

true

b)

false

c)

Compilation error

d)

Runtime error

147.

What will be the output of this code? String s = "Java"; System.out.println(s.charAt(2));

a)

J

b)

a

c)

v

d)

Compilation error

148.

What will be the output of this code? String s = " Java "; System.out.println(s.trim());

a)

" Java "

b)

"Java"

c)

" Java"

d)

Compilation error

149.

What will be the output of this code? String s = "Hello"; System.out.println(s.concat(null));

a)

Hello

b)

nullHello

c)

Compilation error

d)

Runtime error

150.

Which data structure is used for implementing recursion?

a)

Stack

b)

Queue

c)

List

d)

Array

151.

What will be the output of the following code? Stack stack = new Stack<>(); String s = "XYZ"; for (char c : s.toCharArray()) { stack.push(c); } StringBuilder sb = new StringBuilder(); while (!stack.isEmpty()) { sb.append(stack.pop()); } System.out.println(sb.toString());

a)

XYZ

b)

ZYX

c)

YZX

d)

EmptyStackException

152.

Which of the following is NOT an application of stack?

a)

Data transfer between two asynchronous processes

b)

Compiler syntax analyzer

c)

Tracking local variables at runtime

d)

Parentheses balancing program

153.

What is the value of the postfix expression 6 3 2 4 + – *?

a)

74

b)

-18

c)

22

d)

40

154.

Which data structure is needed to convert infix to postfix notation?

a)

Tree

b)

Branch

c)

Stack

d)

Queue

155.

What is the optimal data structure used to solve Tower of Hanoi?

a)

Tree

b)

Heap

c)

Priority queue

d)

Stack