L.
J Institute of Engineering and Technology
Data Structures using JAVA PRACTICE BOOK (SEM-II EVEN_2025-CE RELATED BRANCHES)
Note :
This practice book is only for reference purpose . L.J.U Test question paper may not be completely set from this practice bank.
Date : 25 Apr 2025
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
A linear list of elements in which deletion can be done from one
end (front) and insertion can take place only at the other end
1 4 A 1 Queue Stack Tree Linked list
(rear) is known as _____________
2 4 A queue follows __________ A 1 FIFO (First In First Out) principle LIFO (Last In First Out) principle Ordered array Linear tree
A normal queue, if implemented using an array of size
3 4 A 1 Rear = MAX_SIZE – 1 Front = (rear + 1)mod MAX_SIZE Front = rear + 1 Rear = front
MAX_SIZE, gets full when?
4 4 What is the term for inserting into a full queue known as? A 1 overflow underflow null pointer exception program won’t be compiled
Which among the following data structure may give overflow
5 4 error, even though the current number of elements in it is less D 1 Circular queue Stack Adaptive queue Simple queue
than its size.
Queues serve major role in ____ Simulation of limited resource
6 4 C 1 Simulation of recursion Simulation of heap sort None of these
allocation
Write an algorithm to perform Enqueue operation in simple
7 4 3
Queue
Write an algorithm to perform Dequeue operation in simple
8 4 3
Queue
Write algorithm for INSERT, DELETE and DISPLAY function of the
9 4 7
QUEUE.
If the elements “A”, “B”, “C” and “D” are placed in a queue and
10 4 A 1 ABCD DCBA DCAB ABDC
are deleted one at a time, in what order will they be removed?
Suppose implementation supports an instruction REVERSE,
A queue can be implemented where A queue can be implemented where
which reverses the order of elements on the stack, in addition A queue can be implemented where
A queue cannot be implemented ENQUEUE takes a single instruction ENQUEUE takes a sequence of three
11 4 C 1 both ENQUEUE and DEQUEUE take a
using this stack. and DEQUEUE takes a sequence of instructions and DEQUEUE takes a
to the PUSH and POP instructions. Which one of the following single instruction each.
two instructions. single instruction.
statements is TRUE with respect to this modified stack?
Match the following:-
A. Linear Queue (i). delete element from queue
B. Circular Queue (ii). If (R == size – 1), Queue is full.
12 4 D 1 A-(iii), B-(ii), C-(iv), D-(i) A-(iv), B-(iii), C-(ii), D-(i) A-(i), B-(iii), C-(iv), D-(ii) A-(ii), B-(iii), C-(iv), D-(i)
C. Enqueue (iii). If (F== R+1 || (R==size-1 && F==0)),
Queue is full
D. Dequeue (iv). Insert element into queue
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Suppose you are given an implementation of a queue of
integers. The operations that can be performed on the queue
are:
i. isEmpty (Q) — returns true if the queue is empty, false
otherwise.
ii. delete (Q) — deletes the element at the front of the queue
and returns its value.
Deletes the element at the front of
iii. insert (Q, i) — inserts the integer i at the rear of the queue. Reverses the order of the elements in the queue Q and inserts it at the rear
13 4 B 1 Leaves the queue Q unchanged Empties the queue Q
Consider the following function: the queue Q keeping the other elements in the
same order
void f (queue Q) {
int i;
if(!isEmpty(Q)){
i = delete(Q);
f(Q); }
insert(Q, i);
} What operation is performed by the above function f ?
Queue – enqueue() Array implementation. Assume that the
queue is having atleat one element.
void enqueue (int data)
{
The code might try to insert elements
if (capacity-1== rear) the code overwrites existing record the code doesn’t check if the data is the code doesn’t update the front of
14 4 B 1 even when the queue is full which will
return; when we try to insert new data empty the queue
lead to an overflow
else{
arr[rear]=data;
return;}
}
Provided the space is available, then to insert an element x in
the queue, we can use for the following class
class queue
{
++f ; Q[++r]=x ++f ; Q[r++]=x None of the above
15 4 int Q[] = new int[20]; B 1 ++f ; ++Q[r]=x
int f=-1, r=-1;
}
Then which of the options is correct?
Consider a standard Circular Queue 'q' implementation (which
has the same condition for Queue Full and Queue Empty)
16 4 whose size is 11 and the elements of the queue are q[0], q[1], D 1 q[0] q[1] q[2] q[10]
q[2].....,q[10]. The front and rear pointers are initialized to point
at q[2] . In which position will the 8th element be added?
Write a JAVA functions for insertion and deletion operation in
17 4 7
simple queue.
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Following is pseudo code of a function that takes a Queue as an
argument, and uses a stack S to do processing.
void fun(Queue Q)
{
Stack S; // Say it creates an empty stack S
// Run while Q is not empty
while (!isEmpty(Q))
{
// deQueue an item from Q and push the dequeued item to
S Keeps the Q same as it was before the
18 4 D 1 Removes the last from Q Makes Q empty Reverses the Q
push(S, deQueue(Q)); call
}
// Run while Stack S is not empty
while (!isEmpty(S))
{
// Pop an item from S and enqueue the poppped item to Q
enQueue(Q, pop(S));
}
}
What does the above function do in general?
Consider the following pseudo code. Assume that IntQueue is
an integer queue. What does the function fun do?
void fun(int n)
{
IntQueue Q // creates new integer queue
enqueue(Q,0);
enqueue(Q,1);
for (int i = 0; i < n; i++) Prints first n Fibonacci numbers in
19 4 C 1 Prints numbers from 0 to n-1 Prints numbers from n-1 to 0 Prints first n Fibonacci numbers
{ reverse order
int a = dequeue(Q);
int b = dequeue(Q);
enqueue(Q, b);
enqueue(Q, a + b);
print(a);
}
}
Consider the following pseudo code implementation of
Enqueue and Dequeue operations using two initially empty very
large stacks P and Q, with primitive stack operations PUSH and
POP.
Stack P, Q;
Enqueue(key k)
PUSH(k,P);
Dequeue( ) {
20 4 if(Q is empty) A 1 PUSH(POP(P),Q) PUSH(POP(P)) PUSH(P) PUSH(POP(Q))
{
while(P is not empty)
MISSING STATEMENT ;
}
return POP(Q);
}
Choose the correct statement in place of MISSING STATEMENT.
(Ignore error handling).
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Let Q be a Queue. enqueue and dequeue are usual Queue
operations to add and delete element respectively.
Q.enqueue(x) adds an element x to the queue.
Q.dequeue() performs a dequeue operation on the queue and
returns the value that gets dequeued.
Consider the following segment of code:
Q.enqueue(1);
21 4 int count=1; C 1 11 10 12 13
do {
count=count + 1;
x = Q. dequeue();
Q.enqueue (2*x);
Q.enqueue( 4*x);
} while (x!= 32);
What will be the value of the variable count, when the above
segment of code completes its execution?
Write a program to perform insert and delete routines on a
22 4 7
queue.
Suppose a queue is maintained by a circular array holding 10
elements. Find the number of elements in the queue after the
following operations
23 4 A 1 0 1 2 3
1) front=3, rear=7
2) front=9, rear=4
3) Front =4, rear=5 and then two elements are deleted.
Consider the following statements:
i. First-in-first out types of computations are efficiently
supported by STACKS.
ii. Implementing QUEUES on a circular array is more efficient
24 4 than implementing QUEUES A 1 Only (ii) is true (i) and (ii) are true (iii) and (iv) are true Only (iii) is true
on a linear array with two indices.
iii. Last-in-first-out type of computations are efficiently
supported by QUEUES.
Which of the following is correct?
In a circular queue, how do you increment the rear end of the
25 4 B 1 rear++ (rear+1) % CAPACITY (rear % CAPACITY)+1 rear–
queue?
What is the need for a circular queue?
26 4 A 1 effective usage of memory easier computations to delete elements based on priority implement LIFO principle in queues
Let the following circular queue can accommodate maximum six
elements with the following data
front = 2 rear = 5 front = 3 rear = 5 front = 3 rear = 4 front = 2 rear = 4
27 4 front = 2 rear = 4 A 1
queue = ______; L, M, N, O, ___ queue = L, M, N, O, ___ queue = ______; L, M, N, O, ___ queue = L, M, N, O, ___
queue = __, L, M, N, ___, ___
What will happen after ADD O operation takes place?
A circular queue is implemented using an array of size 10. The
28 4 array index starts with 0, front is 6, and rear is 9. The insertion A 1 0 7 9 10
of next element takes place at the array index.
Given a circular queue implemented with an array of size 8
29 4 (indexing from 0 to 7) and F=2 & R=7. After inserting an B 0.5 1 0 8 3
element, what would the new position of the rear pointer?
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Suppose a queue is implemented using a circular array QUEUE
with N=20 memory cells. The queue is initially empty. Perform
the following sequence of operations:
Enqueue 7 elements
Dequeue 5 elements
Enqueue 12 elements
30 4 B 1 0 1 2 3
Dequeue 10 elements
Enqueue 4 elements
Dequeue 8 elements
Enqueue 3 elements
Dequeue 2 elements
What is the number of elements in QUEUE at the end?
Suppose we have a standard circular queue named q of size 36
with Two different initial pointer positions
Case 1 front = 5, rear = 9 and
Case 1 – q[20], Case 2 – q[27] Case 1 – q[21], Case 2 – q[26]
31 4 Case 2 front = 24, rear = 15. A 1 Case 1 – q[21], Case 2 – OVERFLOW Case 1 – q[20], Case 2 – q[26]
Now, we perform insertion 12 times then where would the 12th
element go into this queue after an enqueue operation?
consider indexing starts from 0.
Write an algorithm to perform Enqueue operation in Circular
32 4 4
Queue
Write an algorithm to perform Dequeue operation in Circular
33 4 4
Queue
34 4 Circular Queue is also known as ________ A 1 Ring Buffer Square Buffer Rectangle Buffer Curve Buffer
If the MAX_SIZE is the size of the array used in the
35 4 implementation of circular queue. How is rear manipulated C 1 rear=(rear%1)+MAX_SIZE rear=rear%(MAX_SIZE+1) rear=(rear+1)%MAX_SIZE rear=rear+(1%MAX_SIZE)
while inserting an element in the queue?
If the MAX_SIZE is the size of the array used in the
implementation of circular queue, array index start with 0, front
36 4 point to the first element in the queue, and rear point to the B 1 Front=rear= -1 Front=(rear+1)%MAX_SIZE Rear=front+1 Rear=(front+1)%MAX_SIZE
last element in the queue. Which of the following condition
specify that circular queue is FULL?
If the MAX_SIZE is the size of the array used in the
implementation of circular queue, array index start with 0, front
37 4 point to the first element in the queue, and rear point to the B 1 Front=rear=0 Front= rear=-1 Front=rear+1 Front=(rear+1)%MAX_SIZE
last element in the queue. Which of the following condition
specify that circular queue is EMPTY?
An array of size MAX_SIZE is used to implement a circular
queue. Front, Rear, and count are tracked. Suppose front is 0
38 4 D 1 Zero One MAX_SIZE-1 MAX_SIZE
and rear is MAX_SIZE -1. How many elements are present in the
queue?
The initial configuration of circular queue as follows
39 4 C 1 x,y,____,_____,_____ x,___,y,____,____ ____,_____, x ,y,____ _____,x,y,_____,______
What is status of states of queue contents after the following
sequence of steps
enqueue x, dequeue, enqueue y, dequeue, dequeue
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Consider a circular queue of size 6.
Let Front =2, Rear =4, and Queue : __, L, M, N, __, __
Describe the queue as following operations are performed.
1) Add O
40 4 2) Add P B 1 R=4 and F=2 R=3 and F=5 R=3 and F=4 Queue Overflow
3) Delete
4) Delete
5) Add Q, R, S
6) Delete
Suppose we have a circular array implementation of the queue
type, with ten items in the queue stored at data [2] through
41 4 C 1 data[1] data[22] data[12] data[11]
data [11]. The current SIZE is 22. Where does the insert method
place the new entry in the array?
The problem of false alarm about overflow of linear queue is
42 4 D 1 deque Stack Array Circular Queue
removed by the application of_________.
Write an algorithm for circular queue that insert an element at
43 4 4
rear end
Write a JAVA program to implement a circular queue using
44 4 7
array with all necessary overflow and underflow checks
Write a JAVA function for circular queue for the below
operations.
45 4 2
1)To check Overflow condition
2)To check Underflow condition
Write a JAVA function to implement Circular queue insertion.
46 4 2
Consider a standard Circular Queue 'q' implementation (which
has the same condition for Queue Full and Queue Empty)
47 4 whose size is 11 and the elements of the queue are q[0], q[1], A 1 q[0] q[1] q[9] q[10]
q[2].....,q[10]. The front and rear pointers are initialized to point
at q[2] . In which position will the ninth element be added?
What will the final value of Front and Rear pointer value after
given below operation for linear and circular queue.
48 4 A 1 linear: F=3, R=5 circular: F=3, R=1 linear: F=3, R=5 circular: F=3, R=2 linear: F=5, R=5 circular: F=3, R=1 linear: F=3, R=3 circular: F=3, R=1
A circular array-based queue q is capable of holding 7 elements.
After execution of the following code, find the element at index
2, if the array is initially empty and array has indices from 0 to 6.
for (x=1; x<=6; x++)
q.enqueue (x);
49 4 D 1 1 2 3 4
for (x=1; x<=4; x++)
{
q.dequeue();
q.enqueue (q. Dequeue ());
}
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Consider the following queue, where queue is a circular queue
having 6 memory cells.
Front=2, Rear=4 Queue: _, A, C, D, _, _
Describe queue as following operation take place:
50 4 F is added to the queue 3
Two letters are deleted
R is added to the queue
S is added to the queue
One letter is deleted
Perform following operations in a circular queue of length 4 and
give the Front, Rear and Size of the queue after each operation.
1) Insert A, B
51 4 3
2) Insert C
3) Delete
4) Insert D
Write an algorithm/program to implement Insert & Delete
52 4 operation into a Circular Queue using array representation of 7
Queue.
What is a deque?
A queue with insert/delete defined for A queue implemented with a doubly A queue implemented with both singly A queue with insert/delete defined for
53 5 A 1
both front and rear ends of the queue linked list and doubly linked lists front side of the queue
Which of the following data structure follows FIFO technique?
54 5 D 1 Priority Queue deque Both of these None of these
Consider a Double Ended Queue given below, initially empty:
________
The following operations are performed on the dequeue:
Insert X at the front.
55 5 Insert Y at the rear. D 1 ________ _W_XYZ__ __WXY___ None
Insert Z at the rear.
Delete an element from the front.
Insert W at the front.
Delete an element from the rear.
What is the resulting state of the double-ended queue after
performing these operations?
Given an initially empty Deque named D, perform the operations below
in the order shown, then answer the questions below
D.insertAtREAR(12) ;
D.insertAtREAR(22) ;
D.insertAtFront(32);
D.insertAtREAR (42);
D.removeFromFront();
D.insertAtREAR (52);
56 5 D.removeFromFront(); C 1 elements = 0, front = 72, rear = 52 elements = 0, front = 82, rear = 52 elements = 4, front = 82, rear = 42 None
D.insertAtREAR (62);
D.insertAtFront (72);
D.insertAtFront (82);
D.removeFromREAR ();
D.removeFromREAR ();
(i) How many elements are in the deque? (ii) What value is at the front
of the deque?
(iii) What value is at the rear of the deque?
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
For a double ended queue the following method performs what?
void display()
{
int i=front;
The method displays all the elements The method displays all the elements The method displays all the elements The method displays all the elements
57 5 while(i!=rear) B 0.5
of queue. of queue except last. of queue except first. of queue in reverse
{
System.out.print(a[i]);
i=(i+1)%size;
} }
A queue where deletion can be made from both ends, but
58 5 B 0.5 output restricted queue input restricted queue circular queue None of these
insertion can be made at one end is called ________.
What is the result of applying the dequeue operation on an empty An error is raised indicating an The front element is removed, and the
59 5 B 0.5 The queue have one element None of these
queue? underflow condition. queue becomes empty.
Consider a deque given below which has LEFT=1, RIGHT=5
_ABCDE____.
Now perform the following operations on the deque and trace
values of LEFT and RIGHT respectively.
60 5 1. Add F on the left. A 1 2,8 1,8 1,7 2,7
2. Add G on the right.
3. Add H on the right.
4. Delete two alphabets from left
5. Add I on the right
After performing these set of operations in double ended queue,
what does the final list look contain?
InsertFront(10); InsertFront(20); InsertRear(30); DeleteFront();
61 5 InsertRear(40); InsertRear(10); DeleteRear(); InsertRear(15); D 1 10 30 10 15 20 30 40 15 20 30 40 10 10 30 40 15
display();
A Double-ended queue supports operations such as adding and
removing items from both the sides of the queue. They support
four operations like addFront(adding item to top of the queue),
addRear(adding item to the bottom of the queue),
removeFront(removing item from the top of the queue) and
62 5 B 1 1 2 3 4
removeRear(removing item from the bottom of the queue). You
are given only stacks to implement this data structure. You can
implement only push and pop operations. What are the total
number of stacks required for this operation?(you can reuse the
stack)
Consider a Double Ended Queue given below which has F=3,
R=4 and size = 8
_ _BC_ _ _ _
63 5 A 1 3,5 3,6 1,5 2,5
Now perform the following operations on the dequeue (Insert A
at front, Insert D at front, Insert E at rear , Delete two alphabets
from front) What is the value of F and R?
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Given an initially empty Deque named D, perform the operations
below
in the order shown, then answer the questions below
Deque < int > D;
D. insertAtREAR( 42 ) ;
D. insertAtREAR( 17 ) ;
D. insertAtFront(12);
D. insertAtREAR ( 87) ;
D. removeFromFront();
64 5 D 1 element=0,f=44,r=17 element=1,f=23,r=88 element=5,f=99,r=88 element=5,f=44,r=23
D. insertAtREAR ( 23 ) ;
D. removeFromFront();
D. insertAtREAR (99 )
D. insertAtFront ( 88 ) ;
D. insertAtFront (44 ) ;
D. removeFromREAR ();
(a) How many elements are in the deque?
(b) What value is at the front of the deque?
(c) What value is at the rear of the deque?
Consider the double ended queues Q1 containing four elements
and Q2 containing none (shown as the Initial State in the figure).
The only operations allowed on these two queues are
Enqueue(Q, element) and Dequeue(Q).The minimum number of
Enqueue operations on Q1 required to place the elements of Q1
in Q2 in reverse order (shown as the Final State in the figure)
without using any additional storage is________________.
65 5 A 1 0 1 2 3
66 5 Write a program to implement Deque Operations 7
Write a function to insert and delete items from double ended
67 5 4
queue from front
Write a function to insert and delete items from double ended
68 5 4
queue from rear
Write all necessary methods to develop input restricted
69 5 Queue.(Do not use Link list for implementation, display method 4
not required)
If priority queue is implemeneted using arrays then which of the
70 5 A 1 enqueue dequeue peek Reverse
following is not the basic operation of the queue?
Which of the following can not be used to implemenet priority
71 5 D 1 Arrays Linked List Heaps None of these
queue?
Which one of the following is an application of Queue Data When data is transferred
Structure? When a resource is shared among asynchronously (data not necessarily
72 5 D 1 Load Balancing All of the above
multiple consumers. received at same rate as sent) between
two processes
Which of the following is not a disadvantage to the usage of There are chances of wastage of
array? memory space if elements inserted in Accessing elements at specified
73 6 D 1 Fixed size Insertion based on position
an array are lesser than the allocated positions
size
A linear collection of data elements where the linear node is
74 6 A 1 Linked list Node list Primitive list Unordered list
given by means of reference is called?
In linked list each node contains a minimum of two fields. One
75 6 C 1 reference to character reference to integer reference to node Node
field is data field to store the data second field is?
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Linked list is considered as an example of ___________ type of
76 6 A 1 Dynamic Static Compile time Heap
memory allocation.
In Linked List implementation, a node carries information
77 6 C 1 Data Link Data and Link Node
regarding ___________
Linked list data structure offers considerable saving in Space Utilization and Computational
78 6 C 1 Computational Time Space Utilization Speed Utilization
_____________ Time
Which of the following points is/are not true about Linked List Arrays have better cache locality that
It is easy to insert and delete Random access is not allowed in a Access of elements in linked list takes
79 6 D 1 can make them better in terms of
elements in Linked List typical implementation of Linked Lists less time than compared to arrays
data structure when it is compared with an array? performance
What is the output of following function for start pointing to
first node of following linked list?
1->2->3->4->5->6
void fun(Node start)
{
if(start == null)
return;
System.out.print(" " + start.data);
80 6 D 1 146641 135135 1235 135531
if(start.next != null )
fun(start.next.next);
System.out.print(" "+ start.data);
}
Note - Cosnider inner class Node has outer class Linkedlist and
having two data memeber data(to store the data) and next ( to
store the reference of the next Node). First of a given likedlist is
passed as an argument to the given function
What is the output of following function where head pointing to
first node of following linked list?
10→20→30→40→50
void fun(Node head)
{
81 6 int x=45; C 1 10 10 20 10 30 None
System.out.print(" " +head.info);
head=head.link.link;
if(head.info<=x)
System.out.print(" " +head.info);
}
What is the output of following function where head pointing to
first node of following linked list?
10->20->30->40->50
void fun(Node head)
{
20 30
82 6 int x=25; B 1 25 10 20
System.out.print(" " +head.info);
head=head.link.link;
if(head.info<=x)
System.out.print(" " +head.info);
}
Given reference to a node X in a singly linked list. Only one
83 6 reference is given, reference to first node is not given, can we A 1 Possible if X is not last node Possible if size of linked list is even Possible if size of linked list is odd Possible if X is not first node
delete the node X from given linked list?
A variant of linked list in which last node of the list points to
84 6 A 1 Singly linked list Doubly linked list Circular linked list Multiply linked list
null?
85 6 In Singly linked list each node contain ______ fields. B 1 One Two Three Four
Which of the following points is/are true about Linked List data Arrays have better cache locality that The size of array has to be pre-
Random access is not allowed in a
86 6 structure when it is compared with array D 1 can make them better in terms of decided, linked lists can change their All of the Given
typical implementation of Linked Lists
performance. size any time.
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
You are given pointers to first and last nodes of a singly linked
Insert a new element as a first Add a new element at the end of the
87 6 list, which of the following operations are dependent on the C 1 Delete the first element Delete the last element of the list
element list
length of the linked list?
Consider a single linked list where F and L are pointers to the
first and last elements respectively of the linked list. The time
for performing which of the given operations depends on the
length of the linked list?
Interchange the first two elements of
88 6 C 1 Delete the first element of the list Delete the last element of the list Add an element at the end of the list
the list
What will be the output of the following code segment if list is:
10->20->30->40->50->60?
void solve(Node root) {
int s = 0;
while(root.next != null) {
89 6 s += root.val; C 1 120 210 150 60
root = root.next;
}
System.out.println(s);}
Cosnider the Node inner class of SLinkedList is having two data
member - val, next
Consider the Java code fragment given below.
void join(Node m, Node n){
Node p = n;
while(p.next != null)
{ always gives null pointer dereference
90 6 A 1 append list m to the end of list n append list n to the end of list m depends on the input
p = p.next; for all inputs
}
p.next = m;}}
Assuming that m and n point to valid null terminated, non
empty linked lists, invocation of join will
Consider the following linked list :
class Node
{
int info;
91 6 Node link; D 1 10 12 14 16
}head = null;
What will be the value of the following statement?
Head.link.link.link.info;
10-> 12-> 14-> 16-> 20
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
The following Java function takes a singly-linked list as input
argument. It modifies the list by moving the last element to the
front of the list and returns the modified list. Some part of the
code is left blank.
Node move_to_front(Node head)
{
Node p, q;
if ((head == null) || (head.next == null))
return head;
q = null;
p = head; q=null;p.next=head;head=p; q.next=null;head=p;p.next=head; head=p;p.next=q;q.next=null; q.next=null;p.next=head;head=p;
92 6 D 1
while (p.next != null)
{
q=p;
p=p.next;
}
_______________
return head; }
Choose the correct alternative to replace the blank line.
What does the following code snippet do?
int solve (ListNode list) {
ListNode fast = list;
ListNode slow = list;
while(fast.next != null && fast.next.next != null) {
Find middle element in the linked list. Find last element in the linked list Find first element in the linked list No elements
93 6 fast = fast.next.next; A 1
slow = slow.next;
}
return slow.data;
}
}
In the linked list implementation of the queue, where does the
At the tail After all other entries that are greater
insert method place the new entry on the linked list? At the head After all other entries that are smaller
94 6 B 1 than the new entry
than the new entry
Suppose cursor refers to a node in a linked list. What Boolean
expression will be true when cursor refers to the tail node of
cursor.next == null cursor.data == null cursor.data == 0
95 6 the list? A 1 cursor == null
What is the output of the following function when it is called?
void disp( node first )
if( first != null ) Display the data of next node always
Display the data of all nodes of the list Does not execute Display the data of the first node only
96 6 { B 1 in the list
System.out.println(" "+first.data);
disp( first.next );
}
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
node start=head;
Suppose start is a reference to the head of one SLL.
class node{
int data;
node next;
} Print the “data” field of 1st node Print the “data” field of 2nd node Print the “data” field of 3rd node Print the “data” field of 4th node
97 6 B 1
Consider the above code and predict what will be the output by
following piece of code
System.out.println(start.next.data);
What does the following function do for a given Linked List with
first node as head?
void fun1(Slinkedlist head)
{ Prints all nodes of linked list in reverse Prints alternate nodes in reverse
98 6 B 1 Prints all nodes of linked lists Prints alternate nodes of Linked List
if(head==null) order order
return;
fun1(head.next);
System.out.println(" "+head.data);
}
What is the output, if a SLL:1→2→3→4→5 is passed in the
above Java code if the inner class node contains int data
memeber and node next member?
void print(node ptr)
{
if(ptr!= null)
{
99 6 C 1 12345 54321 1 1 1 1 1….. 1234
System.out.print(ptr.data);
do{
System.out.print(ptr.data);
} while(ptr.next != null);
}
}
Assume Head reference at node 1
If the Queue is implemented using singly linked list, keeping
track of a front and rear reference, which of these references Only front Pointer changes Only rear Pointer changes
100 6 D 1 Neither of the pointer change Both of the pointers changes
will change during an insertion into a non-empty queue?
What is the output of following function for start refered to first
node of following linked list? 1->2->3->4->5->6
void fun(Node start)
{
if(start == null)
return;
101 6 System.out.print(start.next.data); A 1 246531 135531 246642 24631
if(start.next != null )
fun(start.next.next);
System.out.print(start.data);
}
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
The following java function takes a single-linked list of integers
as a parameter and rearranges the elements of the list. The
function is called with the list containing the integers 1, 2, 3, 4,
5, 6, 7 in the given order. What will be the contents of the list
after the function completes execution?
class Node
{
int value;
Node next;
}
void rearrange(Node list)
{
Node p,q;
int temp;
102 6 if ((list==null) || list.next==null) B 1 1,2,3,4,5,6,7 2,1,4,3,6,5,7 1,3,2,5,4,7,6 2,3,4,5,6,7,1
return;
p = list;
q = list.next;
while(q != null)
{
temp = p.value;
p.value = q.value;
q.value = temp;
p = q.next;
if(p.next != null){
q = p.next;}
else { q = null;}
}
}
Consider the following function to traverse a linked list. Choose
the correct missing statement at the place of ? to write the
function correctly for traverse the list.
void traverse(Node head)
{
???????????????????
103 6 D 1 t=thead; head=t; Node=head; Node t=head;
while (t != null)
{
System.out.print(“ ”+ t.data);
t = t.next;
}
}
In linked list implementation of a stack, where does a new
104 6 A 1 At the head of link list At the center position in the link list At the tail of the link list At any position in the linked list
element be inserted?
In linked list implementation of a simple queue, front and rear
EMPTY: Both front and rear pointer
reference of nodes are tracked. Which of these references will EMPTY: Only front pointer EMPTY: Only front pointer EMPTY: Both front and rear pointer
105 6 C 1 NONEMPTY: Both front and rear
change during an insertion into EMPTY and NONEMPTY queue NONEMPTY: Only front pointer NONEMPTY: Only rear pointer NONEMPTY: Only rear pointer
pointer
respectively?
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Consider the following implementation of linked list, which of
the following lines should be inserted to complete the above
code and what a function do?
class Node
{
int data;
Node next;
}
106 6 D 1 function(1), nothing function(0), nothing 1, error function (t.next, value), search
int function (Node t, int value)
{
if ( t == null)
return 0;
if (t.data == value)
return 1;
return ______________;
}
Which of the following statements are false? random access of elements at linked arrays have better cache locality than size of linked list is dynamic and can random access of elements at array is
107 6 D 1
list is not possible linked list be changed as needed not possible
What will be the value of “count” after the following code
snippet terminates?
Consider head as the reference of the satrting Node of the
Linkedlist.
void puzzel(Node head) {
/*
The LinkedList is defined as:
head.val = value of the node
108 6 head.next = address of next element from the node A 1 10 5 1 2
The List is 1 -> 2 -> 3 -> 4 -> 5
*/
int count = 0;
while(head.next != null) {
count += head.val;
head = head.next; }
System.out.println(count);
}
The following function reverse() is supposed to reverse a singly linked
list. There is one line missing at the end of the function.
/* Inner class contains int data, Node next*/
/* head_ref is a reference which points to head (or start) node of linked
list */
void reverse (node head_ref){
node prev = null;
node current = head_ref;
node n1;
109 6 while (current != null) { A 1 head_ref=prev; head_ref=current; head_ref=next; head_ref=n1;
n1 = current.next;
current.next = prev;
prev = current;
current = n1;
}
/*ADD A STATEMENT HERE*/}
What should be added in place of "/*ADD A STATEMENT HERE*/", so
that the function correctly reverses a linked list.
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
The following function reverse() is supposed to reverse a singly linked
list. There is one line missing at the end of the function.
/* Inner class contains int data, Node next*/
/* head_ref is a reference which points to head (or start) node of linked
list */
void reverse (node head_ref){
node prev = null;
node current = head_ref;
current.next = prev; prev =
110 6 node n1; C 1 current = prev; prev = current.next; current.next = prev; prev = current; current = prev.next; prev = current;
current.next;
while (current != null) {
n1 = current.next;
/*ADD A STATEMENT HERE*/
/*ADD A STATEMENT HERE*/
current = n1; }
head_ref =prev;}
What should be added in place of "/*ADD A STATEMENT HERE*/", so
that the function correctly reverses a linked list.
In implementation of Queue data structure using Linked list,
111 6 Dequeue operation of queue is equivalent to _____________ B 1 Deletion not possible Delete at first Deletion in descending order Cannot be implemented using LL
operation of Linked list.
void count()
{
Node Temp=First;
int c=1;
if(Temp==null)
{
System.out.println("Singly Linked List is Empty");
}
112 6 while(Temp!=null) D 1 Print Total Count of Nodes:12 Print Total Count of Nodes:11 Print Total Count of Nodes:2 Print Total Count of Nodes:13
{
Temp=Temp.next; c++
}
System.out.println("Total Count of Nodes:"+c);
}
What will be the above count method do for a singly linked list
having 12 elements.
Consider the following function foo() which takes the first of
two singly linked list as an arguments.
Node foo(Node first1, Node first2)
{
Node final, temp;
if(first1==null) return first2;
if(first2==null) return first1;
113 6 temp = foo (first1.next, first2.next); A 1 1,2,3,4,5,8,7,10,9,10 1,2,3,4,5,7,8,9,10 1,2,3,4,5,6,7,8,9,10 None of these
final = first1;
first1.next=first2;
first2.next=temp;
return final;
}
what will be the final linked list return by foo() if executed upon
following linked list?
Linked List 1: 1→3→5→7→9→10
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Consider the following function foo() which takes the first of
two singly linked list as an arguments.
Node foo(Node first1, Node first2){
Node final, temp;
if(first1==null) return first2;
if(first2==null) return first1;
temp = foo (first1.next, first2.next);
114 6 final = first1; A 1 1,2,3,4,5,6,7,8,9,10 1,2,3,4,5,8,7,10,9,10 2,1,4,3,6,5,8,7,9,10 Error
first1.next=first2;
first2.next=temp.data;
return final;}
what will be the final linked list return by foo() if executed upon
following linked list?
Linked List 1: 1→3→5→7
Linked List 2: 2→4→6→8→9→10
Consider the following code for a singly linked list. Select the
appropriate option for the missing statements. (Note – the
method performs multiplication of the all the elements of a
linked list.)
void product(Node First)
{
Node temp=First;
product += temp.data; and temp = product = product + temp.data; and product = product * temp.data; and
115 6 int product=1; C 1 None
temp.next; temp = temp.next; temp = temp.next;
while(temp!=null)
{
Missing Statement 1;
Missing Statement 2;
}
System.out.println("Product of All elements is"+product);
}
Write a JAVA program to count the number of nodes in a singly
116 6 5
linked list
Write a JAVA program to Delete the node whose value = Y
117 6 5
Consider singly linked storage structures, Write a java program
118 6 5
which performs an insertion at the end of a linked linear list.
119 6 Write a java program for deletion in Singly Linked List. 5
Write a function for insert in the queue implementation using
120 6 2
Linked list.
121 6 Write a method for insert at end in singly Linked list. 3
122 6 Write a program to search an element in a linked list. 5
Write a java program to print all odd positioned nodes from a
123 6 3
Singly LinkedList. (Consider 1-base indexing)
Write a java function named “displayfromend()” which displays
124 6 1
the contents of the linked list from the end in singly Linkedlist
Write a JAVA function that copies one linked list to another
linked list. The original linked list should be starting at the
pointer “head” and the newly created linked list must have
starting pointer “begin”. It should work for the following test
125 6 case where 3 nodes are already created having data 12, 14 and 2
16 in a linked list pointed by head. The newly created linked list
must have the data 12 at the place where “begin” points
followed by 14 and 16. Write the output of the following test
case.
Write a program to implement stack (PUSH, POP, DISPLAY)
126 6 4
functions with main function using link list.
Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
Write a JAVA Function for PUSH operation of Stack using Link
127 6 2
List.
Write a java Program for insertion in Ordered Singly Link list.
128 6 3
Write a program to count the number of nodes in a singly linked
129 6 3
list
Write a Java program to determine whether all elements in a
linked list are unique or not. Implement a method named
insertAtLast() to insert elements in linked list, a method named
130 6 5
areAllElementsUnique() that takes a linked list of integers as
input and returns true if all elements are unique, and false
otherwise.