Linear Data Structures questions — page 1 of 2

Q39

GATE CS 2026 CS-1Linear Data StructuresMCQ2 marks−2/3 if wrong
Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head.
struct node{
 int elt;
 struct node *next;
};

int getListSize (struct node *head)
{
 if( E1 ) return 1;
 return E2;
}
Which one of the following options gives the correct replacements for the expressions E1 and E2?
Show answer without attempting

Answer: B

Q50

GATE CS 2026 CS-2Linear Data StructuresMSQ2 marks
Consider a stack SS and a queue QQ. Both of them are initially empty and have the capacity to store ten elements each. The elements 1, 2, 3, 4, and 5 arrive one by one, in that order. When an element arrives, it is assigned either to SS (pushed on SS) or to QQ (enqueued to QQ). Once all the five elements are stored, the output is generated in two steps. First, stack S is emptied by popping all elements. Then queue QQ is emptied by dequeueing all elements. The output obtained by following this process is 4  3  1  2  54 \; 3 \; 1 \; 2 \; 5.

Given the output, the objective is to predict whether an element was assigned to SS or QQ.

Which of the following options is/are possible valid assignment(s) of the elements?

Note: In the options, the notation xSxS denotes that element xx was assigned to SS and yQyQ denotes that element yy was assigned to QQ.
More than one option can be correct.
Show answer without attempting

Answer: A, B

Q62

GATE CS 2025 CS-1Linear Data StructuresNAT2 marks
Let LIST be a datatype for an implementation of linked list defined as follows:
typedef struct list {
 int data;
 struct list *next;
} LIST;
Suppose a program has created two linked lists, L1 and L2, whose contents are given in the figure below (code for creating L1 and L2 is not provided here). L1 contains 9 nodes, and L2 contains 7 nodes.

Consider the following C program segment that modifies the list L1. The number of nodes that will be there in L1 after the execution of the code segment is ________ . (Answer in integer)
int find (int query, LIST *list) {
 while (list != NULL){
 if(list->data == query) return 1;
 list = list->next;
 }
 return 0;
}
int main () {

 ptr1=L1; ptr2=L2;
 while (ptr1->next != NULL){
 query = ptr1->next->data;
 if (find (query, L2))
 ptr1->next = ptr1->next->next;
 else ptr1 = ptr1->next;
 }

 return 0;
}
Question figure
Show answer without attempting

Answer: 5

Q38

GATE CS 2025 CS-2Linear Data StructuresMCQ2 marks−2/3 if wrong
A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:

P: Unsorted doubly linked list with pointers to the head node and tail node of the list.
Q: Min-heap implemented using an array.
R: Binary Search Tree.

Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size nn of these data structures?
Show answer without attempting

Answer: A

Q45

GATE CS 2025 CS-2Linear Data StructuresMSQ2 marks
Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct.

We wish to augment the stack data structure with an O(1)O(1) time MIN operation that returns a pointer to the record with smallest key present in the stack
1) without deleting the corresponding record, and
2) without increasing the complexities of the standard stack operations.

Which one or more of the following approach(es) can achieve it?
More than one option can be correct.
Show answer without attempting

Answer: A

Q35

GATE CS 2024 CS-2Linear Data StructuresNAT1 mark
Let AA be an array containing integer values. The distance of AA is defined as the minimum number of elements in AA that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2,5,3,1,4,2,6][2, 5, 3, 1, 4, 2, 6] is ___________
Show answer without attempting

Answer: 3

Q48

GATE CS 2024 CS-2Linear Data StructuresMSQ2 marks
Let S1 and S2 be two stacks. S1 has capacity of 4 elements. S2 has capacity of 2 elements. S1 already has 4 elements: 100, 200, 300, and 400, whereas S2 is empty, as shown below.

Only the following three operations are available:
PushToS2: Pop the top element from S1 and push it on S2.
PushToS1: Pop the top element from S2 and push it on S1.
GenerateOutput: Pop the top element from S1 and output it to the user.

Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.

Which of the following output sequences can be generated by using the above operations?
Question figure
More than one option can be correct.
Show answer without attempting

Answer: B, C, D

Q13

GATE CS 2023 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list.
Let nn denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLLdel and DLLdel?
Show answer without attempting

Answer: D

Q59

GATE CS 2023 CSLinear Data StructuresNAT2 marks
Consider a sequence aa of elements a0=1,a1=5,a2=7,a3=8,a4=9a_0 = 1, a_1 = 5, a_2 = 7, a_3 = 8, a_4 = 9, and a5=2a_5 = 2. The following operations are performed on a stack SS and a queue QQ, both of which are initially empty.

I: push the elements of aa from a0a_0 to a5a_5 in that order into SS.
II: enqueue the elements of aa from a0a_0 to a5a_5 in that order into QQ.
III: pop an element from SS.
IV: dequeue an element from QQ.
V: pop an element from SS.
VI: dequeue an element from QQ.
VII: dequeue an element from QQ and push the same element into SS.
VIII: Repeat operation VII three times.
IX: pop an element from SS.
X: pop an element from SS.

The top element of SS after executing the above operations is ____________.
Show answer without attempting

Answer: 8

Q15

GATE CS 2022 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
Consider the problem of reversing a singly linked list. To take an example, given the linked list below,

head -> [a] -> [b] -> [c] -> [d] -> [e] -> NULL

the reversed linked list should look like

head -> [e] -> [d] -> [c] -> [b] -> [a] -> NULL

Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1)O(1) space?
Show answer without attempting

Answer: A

Q62

GATE CS 2022 CSLinear Data StructuresNAT2 marks
Consider the queues Q1Q_1 containing four elements and Q2Q_2 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 Q1Q_1 required to place the elements of Q1Q_1 in Q2Q_2 in reverse order (shown as the Final State in the figure) without using any additional storage is___________.
Question figure
Show answer without attempting

Answer: 0

Q21

GATE CS 2021 CS-1Linear Data StructuresNAT1 mark
Consider the following sequence of operations on an empty stack.
push(54); push(52); pop(); push(55); push(62); s = pop();
Consider the following sequence of operations on an empty queue.
enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q = dequeue();
The value of s + q is ______.
Show answer without attempting

Answer: 86

Q16

GATE CS 2020 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
What is the worst case time complexity of inserting nn elements into an empty linked list, if the linked list needs to be maintained in sorted order?
Show answer without attempting

Answer: C

Q3

GATE CS 2018 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let nn denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail.

Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?
Question figure
Show answer without attempting

Answer: B

Q8

GATE CS 2017 CS-1Linear Data StructuresMCQ1 mark−1/3 if wrong
Consider the C code fragment given below.
typedef struct node {
    int data;
    node* next;
} node;

void join(node* m, node* n) {
    node* p = n;
    while (p->next != NULL) {
        p = p->next;
    }
    p->next = m;
}
Assuming that mm and nn point to valid NULL-terminated linked lists, invocation of join will
Show answer without attempting

Answer: B

Q13

GATE CS 2017 CS-2Linear Data StructuresMCQ1 mark−1/3 if wrong
A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed in O(1)O(1) time?

I. Next pointer of front node points to the rear node.
II. Next pointer of rear node points to the front node.
Show answer without attempting

Answer: B

Q10

GATE CS 2016 CS-1Linear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (nn refers to the number of items in the queue)?
Show answer without attempting

Answer: A

Q34

GATE CS 2016 CS-1Linear Data StructuresMCQ2 marks−2/3 if wrong
The following function computes the maximum value contained in an integer array p[] of size n (n >= 1).
int max(int *p, int n) {
    int a=0, b=n-1;

    while (__________) {
        if (p[a] <= p[b]) { a = a+1; }
        else              { b = b-1; }
    }

    return p[a];
}
The missing loop condition is
Show answer without attempting

Answer: D

Q41

GATE CS 2016 CS-1Linear Data StructuresNAT2 marks
Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.
while Q is not Empty do
    if S is Empty OR Top(S) <= Head(Q) then
        x := Dequeue(Q);
        Push(S,x);
    else
        x := Pop(S);
        Enqueue(Q,x);
    end
end
The maximum possible number of iterations of the while loop in the algorithm is ________.
Show answer without attempting

Answer: 256.0

Q15

GATE CS 2016 CS-2Linear Data StructuresMCQ1 mark−1/3 if wrong
NN items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed.

An algorithm performs the following operations on the list in this order: Θ(N)\Theta(N) delete, O(log⁡N)O(\log N) insert, O(log⁡N)O(\log N) find, and Θ(N)\Theta(N) decrease-key. What is the time complexity of all these operations put together?
Show answer without attempting

Answer: C

0/200 correct0 marks

Related topics in Programming and Data Structures