• Home
  • Textbooks
  • Data Structures Using C
  • Linked Representation of Linear Data Structures

Data Structures Using C

Amol M. Jagtap, Ajit S. Mali

Chapter 4

Linked Representation of Linear Data Structures - all with Video Answers

Educators


Chapter Questions

Problem 1

Which of the following statements is true regarding the data structure of the linked list when compared to the array?
A. Arrays have better cache locality that can make them superior in terms of efficiency.
B. Inserting, displaying and deleting items into a linked list are easy.
C. Random access is not permitted within a typical linked lists implementation.
D. The size of the array should be decided at the time of compilation, and linked lists may change their size at any time dynamically.
E. All of the above

Check back soon!

Problem 2

The following C function takes a singly linked list as an 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.
```
typedef struct node I
int value;
struct node * next?
1 Node;
Node *move_to_front (Node *head)
i
Node 'p, 'q;
If({lead = = nuLL || (head->next = = NULL))
return heads
q = NuLl; ; p = head;
while {p-> next !=NULL) !
q=p;
p=p->next,
return head;
l
```

Choose the correct alternative to replace the blank line
A. $\mathrm{q}=$ NULL; $\mathrm{p}->$ next $=$ head; head $=\mathrm{p}$;
B. $q$->next $=$ NULL; head = p; p->next $=$ head;
C. head = p; p->next = q; q->next = NULL;
D. $q$->next = NULL; $p$->next = head; head = p

Check back soon!

Problem 3

The following C function takes a list of integers as parameter and rearranges the elements in the list. The function is called with the list containing the $1,2,3,4,5$, 6, 7 integers in the order indicated. What will be the contents of the list after the function has been executed?
```
struct node !
int valueg
struct node + next;
17
Void rearrange (struct node * list) [
stract node * p, * q ?
int temps
it {!1ist || !11st -> next) returnp
P = 11sts q = 11st -> next;
while (q) (
temp = p -> values p -> value = q -> value;
q -> value = temps p = q -> next
q = p? p -> next : 0p
\
l
```
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$

Check back soon!

Problem 4

What does the following operation do for a given linked list with an initial node as head?
```
void fun1 (struct node* head)
l
if(head == nULL)
returny
funl (head->next);
printf(*)d ", head->data);
)
```
A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse order
C. Prints alternate nodes of Linked List
D. Prints alternate nodes in reverse order

Check back soon!

Problem 5

The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function.
```
/* Link list node */
struct node
l
int data:
struct node* next,
$$\$7 $$
/* head_ref is a double pointer which points to head {or start} pointer
of linked list */
static void reverse{struct node** head_ref}
i
struct node* prev = NULL?
struct node* current = *head_reff
struct node* next,
while (current != NULL)
l
next = current->next?
current->next = prevy
prev = current;
current = next;
l
/* predict the statement here */
1
```

What needs to be added instead of "/ $/$ predict the statement here $* / "$, so that the function correctly reverses a linked list.
A. *head_ref=prev;
B. *head_ref = current;
C. *head_ref=next;
D. * head_ref=NULL;

Check back soon!

Problem 6

What is the result of the following function to start pointing to the first node of follow linked list?
```
1->2->3->4->5->6
void fun(struct node* start)
l
if(start == NULL)
returny
printf(")d ", start->data);
if {start->next != NULL )
fun(start->next->next);
printf{*/kd ", start->datal;
)
```
A. 146641
B. 135135
C. 1235
D. 135531

Check back soon!

Problem 7

Consider, we are given pointers to first and last node of a singly linear linked list, which of the below functions are dependent on the length of the linked list.
A. Delete the first node from the linked list
B. Insert a new node as a first node in the linked list
C. Delete the last node from the linked list
D. Insert a new node at the end of the linked list

Check back soon!

Problem 8

Consider that a pointer to a node X in a singly linear linked list is given. Pointers to head node is not given, can we delete the node X from given singly linear linked list?
A. Possible if X is not last node in the linked list. Apply two steps, first copy the data of next of X to X , second delete next of X .
B. Possible if size of linked list is known prior.
C. Possible if size of linked list is odd
D. Possible if X is not first node in the linked list. Apply two steps, first copy the data of next of $X$ to $X$, second delete next of $X$.

Check back soon!

Problem 9

Consider the function f defined below.
```
struct item
l
int data;
struct item * next;
l/
int f(struct item *p)
i
return (
(p == NULL) 11
(p->next == nULL) ||
({ p->-data <= p->next->data) $$\$ $ $$ f(p->next))
);
l
```

For a given linked list p, the function $f$ returns 1 if and only if (GATE CS 2003)
A. the list is empty or has exactly one element
B. the elements in the list are sorted in non-decreasing order of data value
C. the elements in the list are sorted in non-increasing order of data value
D. not all elements in the list have the same data value.

Check back soon!

Problem 10

Consider, a singly circular linked list is used to represent a Queue. There is only one p variable to access the queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time? (GATE 2004)
A. rear node
B. front node
C. not possible with a single pointer
D. node next to front

Check back soon!

Problem 11

In a circular linked list which of the following is correct,
A. Components are all linked together in some sequential manner.
B. There is no beginning and no end.
C. Components are arranged hierarchically.
D. Forward and backward traversal within the list is permitted.

Check back soon!

Problem 12

In singly linear linked list each node contain minimum of two fields. One field is called as a data field to store the actual data second field is used for to store?
A. Pointer to float data
B. Pointer to integer data
C. Pointer to node
D. Pointer to character data

Check back soon!

Problem 13

Consider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that a node of doubly linked list has previous pointer as prev and next pointer as next.
```
void fun(struct node **head_ref)
f
struct node *temp = nULL;
struct node *current = *head_ref;
while (current != NulL)
l
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
l
if(temp != null)
*head_ref = temp->prevs
}
```

Assume that reference of head of following doubly linked list is passed to above function
123456.

What should be the modified linked list after the function call?
A. 214365
B. 543216 .
C. 654321 .
D. 654312

Check back soon!

Problem 14

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is (GATE CS 2002)
A. $\log 2 n$
B. $n / 2$
C. $\log 2 n-1$
D. $\mathbf{n} \backslash$

Check back soon!

Problem 15

A linear collection of data elements where the linear node is given by means of pointer is called?
A. Linked list
B. Node list
C. Primitive list
D. None

Check back soon!

Problem 16

Which of the following operations is carried out more efficiently by the doublylinked list than by the singly-linked list?
A. Deleting a node whose location in given
B. Searching of an unsorted list for a given item
C. Inverting a node after the node with given location
D. Traversing a list to process each node

Check back soon!

Problem 17

Consider an implementation of unsorted singly linked list. ||||||Suppose it has its representation with a head and tail pointer. Given the representation, which of the following operation can be implemented in $\mathrm{O}(1)$ time?
i. Insertion at the front of the linked list
ii. Insertion at the end of the linked list
iii. Deletion of the front node of the linked list
iv. Deletion of the last node of the linked list
A. I and II
B. I and III
C. I,II and III
D. I,II and IV

Check back soon!

Problem 18

Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in $\mathrm{O}(1)$ time?
i. Insertion at the front of the linked list
ii. Insertion at the end of the linked list
iii. Deletion of the front node of the linked list
iv. Deletion of the last node of the linked list
A. I and II
B. I and III
C. I, II and III
D. I, II and IV

Check back soon!

Problem 19

Consider an implementation of unsorted circular linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in $\mathrm{O}(1)$ time?
i. Insertion at the front of the linked list
ii. Insertion at the end of the linked list
iii. Deletion of the front node of the linked list
iv. Deletion of the end node of the linked list
A. I and II
B. I and III
C. I, II, III and IV
D. None

Check back soon!

Problem 20

In singly linear linked list each node contains how many minimum fields?
A. Five
B. Zero
C. Two
D. Four

Check back soon!

Problem 21

A non-circular doubly linked list can be defined as a......
A. Set of nodes, each with two pointers previous and next
B. Set of nodes chained together with pointers
C. Linear sequence of nodes in sequential memory locations
D. Linear sequence of nodes chained together with pointers

Check back soon!

Problem 22

Which of the below operations is a dictionary operation?
A. Search an element
B. Delete an element
C. Insert an element
D. All of these

Check back soon!

Problem 23

What is known as a linear collection of data items, where the each node is given by means of a pointer to the next node?
A. Linked list
B. Node list
C. Primitive list
D. None of these

Check back soon!

Problem 24

In singly linear linked list, each node contains minimum of two fields. One field is the data field to store the data second field. What is it called as?
A. Pointer to character array
B. Pointer to integer
C. Node address
D. Pointer to next linked list node

Check back soon!

Problem 25

Which of the following type of the linked list can be used so that concatenation of two lists can give the time complexity as O (1)?
A. Singly linked list
B. Doubly linked list
C. Doubly circular linked list
D. Array implementation of list

Check back soon!

Problem 26

The linked lists are not appropriate for implementing?
A. Insertion sort
B. Radix sort
C. Polynomial manipulation
D. Binary search

Check back soon!

Problem 27

In the worst case, the number of comparisons needs to search a node in a singly linked list of length $n$ is having time complexity.
A. $\log n$
B. $\mathbf{n}$
C. $\log 2 n-1$
D. $n / 2$

Check back soon!

Problem 28

Which of the following C language code is used to create a new node in the singly linear linked list.
```
struct node
l
int data:
struct node * next;
}
typedef struct node IIST?
LIST*ptr;
```
A. $\mathbf{p t r}=\left(\right.$ LIST $\left.^*\right)$ malloc(sizeof(LIST) $) ;$
B. ${ }^{* p t r}=\left(\right.$ LIST $\left.^*\right)$ malloc(LIST);
C. $\operatorname{ptr}=\left(\operatorname{LIST}^*\right)$ malloc $\left(\right.$ sizeof(LIST $\left.\left.{ }^*\right)\right)$;
D. $\mathrm{ptr}=($ LIST $)$ malloc(sizeof(LIST) $)$;

Check back soon!

Problem 29

What is the return type of the malloc 0 function?
A. void
B. int *
C. float *
D. void *

Check back soon!

Problem 30

LLINK is the pointer toward the....
A. successor node
B. predecessor node
C. head node
D. last node

Check back soon!

Problem 31

Each node of a singly linear linked list must contain at least.....
A. Three fields
B. Two fields
C. Six fields
D. Five fields

Check back soon!

Problem 32

Linked list data structures are most appropriate
A. For comparatively constant collections of data
B. For the size of the structure and the data within the structure are continuously changing.
C. Both A and B
D. None of the above

Check back soon!

Problem 33

Inserting an element at the start of an array is more difficult than inserting an element at the start of a linked list.
A. TRUE
B. FALSE

Check back soon!

Problem 34

The disadvantage in using a circular linked list is $\qquad$
A. It is possible to enter into an infinite loop
B. Last node stores the address of first node in circular linked list
C. Searching is time consuming
D. Circular linked list requires more memory space

Check back soon!

Problem 35

Which of the following statement is true?
a. Using singly linear linked lists and singly circular linked list, it is not possible to traverse the linked list in reverse order.
b. To find the predecessor of any node, it is required to traverse the list from the first node in case of singly linear linked list.
A. a only
B. b only
C. Both a and b
D. None of these

Check back soon!

Problem 36

Which of the following singly linear linked list representation using C language is correct?
A.
```
struct node
i
int data;
struct node *next?
l%
```
```
B. struct node
l
int datay
struct node **next;
17
C. struct node
i
int data;
struct node *next;
struct node *prevs
17
```
D.
```
struct node
i
int data;
int node *next;
17
```

Check back soon!

Problem 37

Which of the following statements is false or true?
1. In doubly linear linked list contains two link fields one is storing the address of next node and the other stores the address of the previous node.
2 . To create a new node dynamically, malloc $O$ function in used.
A. Statement 1 is false
B. Statement 2 is false
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 38

Which of the following statements is false or true?
1. malloc() function having return type as void * which is generic pointer.
2. malloc $($ ) function requires only one argument which is size in interger.
A. Statement 1 is false
B. Statement 2 is false
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 39

Which of the following statements is false or true?
1. With linked list, insertion and deletions can be efficiently carried out.
2. Once elements are stored sequentially, it becomes very difficult to insert an element in between or to delete the middle element from the array.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 40

Which of the following statements is false or true?
```
1. struct node
f
struct node "prev;
int data;
struct node *next;
1/ This is the node representation for Singly Linear
Linked List in C language.
```
2. struct node
```
i
int data;
struct node *mext;
1/ This is the node representation for Doubly Linear
Linked List in C language.
```
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!