functions (3.papers)

loops (1.papers)

Conditional statements (2.papers)

arrays (2.papers)

structures (3.papers)

unions (1.papers)

Enums and TypeDefs (3.papers)

pointers (7.papers)

null pointers (1.papers)

strings (2.papers)

misc c concepts (1.papers)

Data structures (5.papers)

linked lists (3.papers)

trees (1.papers)

basics (5.papers)

bitwise operators (1.papers)

1

Sample linked list program in c: what is below disp() function doing? what kind of data structure it is? struct linkedlist{ int val; struct linkedlist *next; }*head = NULL, *tail = NULL; void disp(){ struct linkedlist *temp = head; while(temp!=NULL){ printf("%d ",temp->val); temp = temp->next; } }

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list, except for last node.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list, except for last node.

Show Answer

2

what is below disp() function doing? what kind of data structure it is? struct linkedlist{ int val; struct linkedlist *next; }*head = NULL, *tail = NULL; void disp(){ struct linkedlist *temp = head; while(temp->next!=NULL){ printf("%d ",temp->val); temp = temp->next; } }

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list, except for last node.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list, except for last node.

Show Answer

3

what is below disp() function doing? what kind of data structure it is? struct linkedlist{ int val; struct linkedlist *next; }*head = NULL, *tail = NULL; void disp(struct linkedlist *node){ int cnt = -1; struct linkedlist *temp = head; while(temp != NULL && temp != node){ temp = temp->next; cnt++; } if(temp == NULL) { printf("sorry"); }else{ printf("done..%d",cnt+1) } }

function disp() is trying to display all the elements of the given single linked list. after printing all the nodes values, it will print sorry all the times.

function disp() is trying to find if a given node is available in this single linked list or not. if given node is available, then it is printing done with the index of that node in this linked list. assuming that starting node index is 0. else it prints sorry.

function disp() is trying to find if a given node is available in this single linked list or not. if given node is available, then it is printing done with the index of that node in this linked list. assuming that starting node index is 1. else it prints sorry.

function disp() is trying to find if a given node is available in this single linked list or not. if given node is available, then it is printing done with the index of that node in this linked list. assuming that starting node index is 0. else it prints sorry. But this logic wont work, because whether node is available or not, it always prints sorry only.

Show Answer

4

what is below fun() function doing? struct linkedlist{ int val; struct linkedlist *next; }*head = NULL, *tail = NULL; void fun(struct linkedlist *node){ struct linkedlist *temp = head; struct linkedlist *prev = temp; while(temp != NULL && temp != node){ prev = temp; temp = temp->next; } if(temp != NULL && temp == head) { head = head->next; free(temp); }else if(temp != NULL){ prev->next = temp->next; free(temp); } }

function fun () is trying to remove a given node in this single linked list if it is available. but this logic won't work for head and tail node.

function fun () is trying to remove a given node in this single linked list if it is available. but this logic won't work for tail node.

function fun () is trying to remove a given node in this single linked list if it is available. but this logic won't work for head node.

function fun () is trying to remove a given node in this single linked list if it is available. it works for all the scenarios including head and tail node.

Show Answer

5

what is below disp() function doing? struct linkedlist{ int val; struct linkedlist *next; }*head = NULL, *tail = NULL; main(){ disp(head); } void disp(struct linkedlist *temp){ if(temp==NULL) return; disp(temp->next); printf("%d ", temp->val); }

this disp() function is trying to display the values of all the nodes from starting to ending node, by traversing through the single linked list using recursion technique.

this disp() function is trying to display the values of all the nodes from ending to starting node (reverse order), by traversing through the single linked list using recursion technique.

this disp() function is trying to display the values of all the nodes from ending to starting node (reverse order), by traversing through the single linked list using recursion technique. But this will not print starting node value.

this disp() function is trying to display the values of all the nodes from ending to starting node (reverse order), by traversing through the single linked list using recursion technique. But this will not print ending node value.

Show Answer

6

How to delete a node in linked list in c: If a pointer to a node in the single linked list is provided, then how to delete that node with out traversing through that linked list?

With out traversing through the linked list, it is not possible to delete a give node, because when we are deleting that node, we have to make sure that previous node will point to the next node of current node. since we are not traversing, this is not possible.

call free(node); and assign node=NULL; so that the node will be deleted successfully.

since we have to delete node without traversing, we can copy the content of next node to current node, and delete the next node. But this trick will not work if the node supplied is the last node.

we can free the current node, and change the previous node next pointer to point to next node of current node.

Show Answer

7

how to delete a node from doubly linked list in c: If a pointer to a node in the double linked list is provided, then how will you delete that node with out traversing through that linked list.? Assuming that it is not a head or tail node.

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { temp->prev->prev = temp->next; temp->next->next = temp->prev; free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { temp->prev->next = temp->prev; temp->next->prev = temp->next; free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { temp->prev->next = temp->next; temp->next->prev = temp->prev; free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { free(temp); temp->prev->next = temp->next; temp->next->prev = temp->prev; }

Show Answer

8

how to insert a node in a linked list: what is below function insert() doing? what kind of data structure it is? struct linkedlist{ int val; struct linkedlist *prev; struct linkedlist *next; }*head = NULL, *tail = NULL; void insert(int item){ struct linkedlist *temp = malloc(sizeof(struct linkedlist)); temp->val = item; temp->prev = tail; temp->next = NULL; if(head == NULL){ head = temp; tail = temp; }else{ tail->next = temp; tail = temp; } }

function insert() is trying to insert a new node to the linked list at the end. head is pointing to starting node, and tail is pointing to last node. if there are no nodes both head and tail are having null values. this is an example of doubly linked list.

function insert() is trying to insert a new node to the linked list at the end. head is pointing to starting node, and tail is pointing to last node. if there are no nodes both head and tail are having null values. this is an example of single linked list.

function insert() is trying to insert a new node to the linked list at the head node. head is pointing to starting node, and tail is pointing to last node. if there are no nodes both head and tail are having null values. this is an example of doubly linked list.

function insert() is trying to insert a new node to the linked list at the end. head is pointing to starting node, and tail is pointing to last node. if there are no nodes both head and tail are having null values. this is an example of double linked list.

Show Answer

9

Example code for traversing a linked list in c: what is below function disp() doing? what kind of data structure it is? struct linkedlist{ int val; struct linkedlist *prev; struct linkedlist *next; }*head = NULL, *tail = NULL; void disp(){ struct linkedlist *temp = head; while(temp != NULL){ printf("%d ", temp->val); temp = temp->next; } }

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list.

disp function is traversing through this doubly linked list, and printing the val of all the nodes present in this linked list, except for last node.

disp function is traversing through this single linked list, and printing the val of all the nodes present in this linked list, except for last node.

Show Answer

Show Answer

11

Will this below logic work for deleting a node in double linked list in c? struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { temp->prev->next = temp->next; temp->next->prev = temp->prev; free(temp); }

Yes it will work for all nodes.

It will not work for head node, but works for other nodes.

it will not work for tail node, but works for other nodes.

it will not work for head and tail node, but works for other nodes.

Show Answer

12

How to delete a given node from a doubly linked list in c, with out traversing? Which of the below code will work for all the nodes?

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { if(temp == head){ temp->prev->next = NULL; head = temp->next; }else if(temp == tail){ temp->next->prev = NULL; tail = temp->prev; }else{ temp->prev->next = temp->next; temp->next->prev = temp->prev; } free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { if(temp == head){ temp->next->prev = NULL; head = temp->next; }else if(temp == tail){ temp->prev->next = NULL; tail = temp->prev; }else{ temp->prev->next = temp->next; temp->next->prev = temp->prev; } free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { if(temp == head){ temp->prev->next = NULL; head = temp->prev; }else if(temp == tail){ temp->next->prev = NULL; tail = temp->next; }else{ temp->prev->next = temp->next; temp->next->prev = temp->prev; } free(temp); }

struct list{ int no; struct list *prev; struct list *next; }; void delete(struct list *temp) { if(temp == tail){ temp->next->prev = NULL; head = temp->next; }else if(temp == head){ temp->prev->next = NULL; tail = temp->prev; }else{ temp->prev->next = temp->next; temp->next->prev = temp->prev; } free(temp); }

Show Answer

13

To insert a new element at the starting position, Which data structure is faster? i. array [or] ii. linked list

Linked list is faster

array is faster

both will be same.

it depends.

Show Answer

Show Answer

15

To access a random element which data structure is faster? i. array [or] ii. linked list

Linked list is faster

array is faster

both will be same.

it depends.

Show Answer

16

Which data structure is faster to insert a new data? i. array [or] ii. linked list Assume that we are having the node pointer after which we have to inset extra node, and similarly we have index of an array after which we have to insert a new value, then which one can be done faster. Assume that linked list is not sorted.

Linked list is faster

array is faster

both will be same.

both will be slower.

Show Answer

17

Which data structure is faster: To insert a new element ? i. sorted single linked list [or] ii. sorted array

sorted array will be faster.

sorted linked list will be faster

we can't predict

both will be same

Show Answer

18

What is the time complexity of finding the length of a singly linked list by traversing?

O(n log n)

O(log n)

O(n)

O(n log n^2)

Show Answer

19

Which data structure is faster to find or search an element? i. sorted array [or] ii. sorted linked list

sorted linked list will be faster

both will be of same

sorted array will be faster.

we can't predict

Show Answer

20

Which data structure is faster to search a data item? i. array [or] ii. linked list

Linked list is faster

array is faster

both will be same.

both will be slower.

Show Answer