Chapter 3-Linked List
Chapter 3-Linked List
3.1Introduction
1. How many cases are there, which are used to compare various data
structure's execution time in a relative manner?
A. 2
B. 3
C. 4
D. 5
Ans : B. 3
A. Worst Case
B. Average Case
C. Best Case
D. None of the above
A. Æ’(n)
B. f(m)
C. mf(n)
D. nf(m)
Ans : C. mf(n)
A. Entity Set
B. Record
C. File
D. Field
Ans : D.Field
A. Completeness
B. Correctness
C. Time Complexity
D. Space Complexity
Ans : A. Completeness
A. Completeness
B. Correctness
C. Time Complexity
D. Space Complexity
A. Group Items
B. Attribute and Entity
C. Elementary Items
D. File items
A. A Posterior Analysis
B. A Priori Analysis
C. A Feasibility Analysis
D. A Independent Analysis
A. A Posterior Analysis
B. A Priori Analysis
C. A Feasibility Analysis
D. A Independent Analysis
Each node has only one pointer to traverse the list back and forth
A doubly linked list that uses bitwise AND operator for storing
addresses
8) .......... may take place only when there is some minimum amount
(or) no space left in free storage
list.
A. Memory management
B. Garbage collection
C. Recycle bin
D. Memory management
Answer B. Garbage collection
9) A linear list in which the last node points to the first node is
........
A. singly linked list
B. circular linked list
C. doubly linked list
D. none of the above
Answer B. circular linked list
10) A doubly linked list has .......... pointers with each node.
A. 0
B. 1
C. 2
D. 3
Answer C. 2
12) The pointer that points to the first node in the list is........
A. FIRST
B. AVAIL
C. TOP
D. REAR
[A] Traversal
[B] Retrieval
[C] Deletion
[D] Insertion
(2) A linear list in which the last node points to the first node is
........
(3) A linear list in which the pointer points only to the successive
node is......
[A] Guard
[B] Sentinel
[A] first
[B] middle
[C] last
(7) A doubly linked list has .......... pointers with each node.
[A] 0
[B] 1
[C] 2
[D] 3
Answer: [C] 2
(8) A linear list in which each node has point to the predecessor and
successors nodes is called ........
[A] beginning
[B] middle
[C] end
Answer:
Q.11. What would be the asymptotic time complexity to add a node at
the end of singly linked list, if the pointer is initially pointing to
the head of the list?
1. O(1)
2. O(n)
3. θ(n)
4. θ(1)
Answer:- (3)
Ο(n2)
Ο(nlog n)
Ο(n3)
Ο(n)
Answer:- (4)
not be executed.
execute infinitely.
Answer:- (3)
Dn = n log2n
Dn = n log2n +1
Dn = log2n
Dn = log2n + 1
Answer:- (4)
Q.4. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
AB + CD* E €“ F **G /
AB + CD* E €“ *F *G /
AB + CDE * €“ * F *G /
Answer:- (3)
Branch
Tree
Queue
Stack
Answer:- (4)
Q.6. One can convert a binary tree to its mirror image by traversing
it in
Inorder
Preorder
Postorder
Answer:- (3)
Q.7. For an undirected graph with n vertices and e edges, the sum of
degree of each vertex is equal to
2n
2e
(e2+1)/2
(2n-1)/2
Answer:- (2)
Queue
Circular queue
Dequeue
Priority queue
Answer:- (3)
O(1)
O(n)
θ(n)
θ(1)
Answer:- (3)
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
ptr = (NODE*)malloc(sizeof(NODE));
ptr = (NODE*)malloc(NODE);
ptr = (NODE*)malloc(sizeof(NODE*));
ptr = (NODE)malloc(sizeof(NODE));
Answer:- (1)
Q.11. Which of the following points is/are not true about Linked List
data structure when it is compared with array?
Arrays have better cache locality that can make them better in terms
of performance
Answer:- (4)
Q.12. You are given pointers to first and last nodes of a singly
linked list, which of the following operations are dependent on the
length of the linked list?
Answer:- (3)
Each node has only one pointer to traverse the list back and forth
A doubly linked list that uses bitwise AND operator for storing
addresses
Answer:- (1)
Answer:- (2)
Answer:- (3)
space allocation for array is fixed and cannot be changed during run-
time
Answer:- (1)
n-ary tree
queue
priority queue
stack
Answer:- (4)
O(nlogn)
O(n)
O(1)
Answer:- (4)
AVAIL
FRONT
REAR
NULL
Answer:- (1)
In push operation, if new nodes are inserted at the end, then in pop
operation, nodes must be removed from end
In push operation, if new nodes are inserted at the end, then in pop
operation, nodes must be removed from beginning.
Answer:- (1)
21) To insert a new node in linked list free node will be available in
........
A. Available list
B. Avail list
C. Free node list
D. Memory space list
A - Selection Sort
B - Bubble Sort
C - Merge Sort
D - Insertion Sort
A - expression parsing
B - recursion
C - resource allocation
D - all of the above
A - Selection Sort
B - Insertion Sort
C - Merge Sort
D - both A &am; B
A - Binary Search
B - Interpolation Search
C - Linear Search
D - All of the above
A - Time Complexity
B - Space Complexity
C - Program Complexity
D - None of the above!
A - Selection Sort
B - Bubble Sort
C - Merge Sort
D- Insertion Sort
Question: 1
A data structure in which linear sequence is maintained by pointers is
known as
(A) Array
(B) Stack
(C) Linked list
(D) Pointer-based data structure
Ans: C
Linked list
Question: 2
Which of the following data structure works on the principle of First
Come First Serve?
(A) Priority queue
(B) Heap
(C) Stack
(D) Queue
Ans: D
Queue
Question: 3
A ____ is a linear collection of self-referential structures, called
nodes, connected by pointer links.
(A) Queue
(B) Linked list
(C) Tree
(D) Stack
Ans: B
Linked list
Question: 4
A queue where all elements have equal priority is a
(A) ILFO data structure
(B) LILO data structure
(C) FIFO data structure
(D) LIFO data structure
Ans: C
FIFO data structure
Question: 5
A file that is only read by a program is known as ____
(A) Input file
(B) Temporary file
(C) Work file
(D) Input/output file
Ans: A
Input file
Question: 6
Which of the following sorting algorithm is the slowest?
(A) Bubble sort
(B) Heap sort
(C) Shell sort
(D) Quick sort
Ans: A
Bubble sort
Question: 7
Which of the following data structure can be used to represent many-
to-many relation?
(A) B-tree
(B) Binary tree
(C) Graph
(D) All of above
Ans: C
Graph
Question: 8
Which of the following statement is not true about linked lists?
(A) Element in a linked list, if it is sorted, can be quickly searched
by applying binary search technique
(B) Elements are not necessarily stored in contiguous locations
(C) Insertions and deletions can be performed efficiently as compared
to arrays
(D) Linked list is a dynamic structure
Ans: A
Element in a linked list, if it is sorted, can be quickly searched by
applying binary search technique
Question: 9
Which of the following is not a linear data structure?
(A) Stack
(B) Queue
(C) Linked list
(D) Binary tree
Ans: D
Binary tree
Question: 10
Which of the following data structure permits insertion and deletion
operations only on one end of the structure?
(A) Linked list
(B) Array
(C) Stack
(D) Queue
Ans: C
Stack
Answer: b O(n)
7. How would you delete a node in the singly linked list? The position
to be deleted is given.
a)
public void delete(int pos) { if(pos < 0) pos = 0; if(pos >
size) pos = size; if( size == 0) return; if(pos == 0)
head = head.getNext(); else { Node temp = head;
for(int i=1; i<pos; i++) { temp = temp.getNext(); }
temp.setNext(temp.getNext().getNext()); } size--; }
b)
public void delete(int pos) { if(pos < 0) pos = 0; if(pos >
size) pos = size; if( size == 0) return; if(pos == 0)
head = head.getNext(); else { Node temp = head;
for(int i=1; i<pos; i++) { temp = temp.getNext(); }
temp.setNext(temp.getNext()); } size--; }
c)
public void delete(int pos) { if(pos < 0) pos = 0; if(pos > size)
pos = size; if( size == 0) return; if(pos == 0) head
= head.getNext(); else { Node temp = head; for(int i=1;
i<pos; i++) { temp = temp.getNext().getNext(); }
temp.setNext(temp.getNext().getNext()); } size--; }
d)public void delete(int pos) { if(pos < 0) pos = 0; if(pos > size)
pos = size; if( size == 0) return; if(pos == 0) head =
head.getNext(); else { Node temp = head; for(int i=0; i<pos;
i++) { temp = temp.getNext(); }
temp.setNext(temp.getNext().getNext()); } size--; }
Answer: a)
public void delete(int pos) { if(pos < 0) pos = 0; if(pos >
size) pos = size; if( size == 0) return; if(pos == 0)
head = head.getNext(); else { Node temp = head;
for(int i=1; i<pos; i++) { temp = temp.getNext(); }
temp.setNext(temp.getNext().getNext()); } size--; }
Answer: c) Find and return the position of the given element in the
list
struct node{
int value;
struct node* next;
};
void rearrange (struct node* list)
{
struct node *p,q;
int temp;
if (! List || ! list->next) return;
p->list; q=list->next;
while(q)
{
temp=p->value; p->value=q->value;
q->value=temp;p=q->next;
q=p?p->next:0;
}
}
a) 1, 2, 3, 4, 5, 6, 7
b) 2, 1, 4, 3, 6, 5, 7
c) 1, 3, 2, 5, 4, 7, 6
d) 2, 3, 4, 5, 6, 7, 1
ANSWER: b) 2, 1, 4, 3, 6, 5, 7
struct item
{
int data;
struct item * next;
};
int f (struct item *p)
{
return((p==NULL) ||((p->next==NULL)||(p->data<=p->next->data) && (p-
>next)));
}