Font size
WorksheetsPrelims - LIST
Total questions: 20
Worksheet time: 11mins
(a) is defined as a mathematical model with a collection of operations defined on that model.
Benifits of ADT
Implementation of ADTs can be changed without requiring changes to the program that uses the ADTs
Modularity
Reuse
Code is easier to understand
How many DISTINCT types of LIST operation you can perform?
4
5
3
8
In a array implementation of list, before insertion i have to move elements to one direction, then i have to free the position and then i have insert. which of the following code does that?
for(i = n-1 ; i >= pos-1 ; i--)
list[i+1] = list[i];
for(i = n-1 ; i >= pos-1 ; i--)
list[i-1] = list[i];
for(i = n-1 ; i >= pos-1 ; i--)
list[i] = list[i+1];
for(i = n-1 ; i >= pos-1 ; i--)
list[i] = list[i-1];
Routine to delete element in an array implementation of List
for(i=pos-1;i<n-1;i++)
list[i]=list[i-1];
for(i=pos-1;i<n-1;i++)
list[i]=list[i*1];
for(i=pos-1;i<n-1;i++)
list[i]=list[i+1];
for(i=pos-1;i<n-1;i++)
list[i]=list[i+2];
Given below, code to display "n" elements in an array which is a list? Fill with appropriate values
for(i=___;i<____;i++)
printf("%d\t",list[i]);
0,n
n,0
0,n-1
n-1,0
(a) is an ordered collection of elements. Each element in the list is referred as a node.
Which of the following is/are the advantages of Linked list?
Insertion and deletion of elements can be done efficiently
It uses dynamic memory allocation
Memory utilization is efficient compared to arrays
Which of the following is/are not the dis-advantage of Linked list?
Linked list does not support random access
Memory is required to store next field
Searching takes time compared to arrays
None of the above
Give syntax to create a node for Single linked list?
newnode=(struct node *)malloc(sizeof(struct node*));
newnode=(struct node )malloc(sizeof(struct node));
newnode=(struct node *)malloc(sizeof(struct node));
newnode=(struct node )malloc(sizeof(struct node*));
Give routine to insert at the beginning in a linked list whose structure is by struct node, with list head as L and pointer variable as next
newnode->next=next;
L=newnode;
newnode->next=node;
L=newnode;
newnode->next=L;
L=newnode;
newnode->L=next;
L=newnode;
How to insert a node after a position P in singly linked list?
Newnode -> data = P ;
Newnode -> next = p ->next ;
P -> next = newnode ;
Newnode -> data = x ;
Newnode -> next = p ->next ;
P -> next = L ;
Newnode -> data = x ;
Newnode -> next = p ->node ;
P -> nextnode = next ;
Newnode -> data = x ;
Newnode -> next = p ->next ;
P -> next = newnode ;
Which of the following is application of Singly Linked List?
moving pages forward and backward in browser
Giving chance to each player in a multi player game
Implementing Stack
Which of the following is application of Doubly Linked List?
moving pages forward and backward in browser
Giving chance to each player in a multi player game
Implementing Stack
Which of the following is application of Cicularly Linked List?
moving pages forward and backward in browser
Giving chance to each player in a multi player game
Implementing Stack
Which of the following is correct way to create node structure for Doubly linked list?
struct node
{
int data;
struct node prev;
struct node next;
struct node link;
};
struct node
{
int data;
struct node next;
};
struct node
{
int data;
struct node prev;
};
struct node
{
int data;
struct node prev;
struct node next;
};
How to create very first node in a Doubly Linked List which is initially empty? Assume head pointer variable is L
newnode->data=X;
newnode->next=L;
newnode->prev=L;
newnode->data=X;
newnode->next=;
newnode->prev=NULL;
list. L=newnode;
newnode->data=X;
newnode->next=head;
newnode->prev=head;
newnode->data=X;
newnode->next=head;
newnode->prev=tail;
list. L=newnode;
how to insert a node at the end of Doubly Linked list?
while(p->next!=NULL)
p=p->next;
newnode->next=NULL;
p->next=newnode;
newnode->prev=p;
while(p->!=NULL)
p=p->next;
newnode->next=NULL;
p->next=newnode;
while(p->next!=NULL)
p=p->next;
newnode->next=NULL;
newnode->prev=p;
while(p->next!=NULL)
p=p->next;
newnode->next=NULL;
p->next=newnode;
newnode->prev=NULL;
Consider a list with head node as L, if one wants to search an element and find its position too, what code he has follow? Assume P is of the type of struct which defines the list.
for(P=L;P!=NULL;P=P->next)
{
if(P->data==a)
{ flag=1;
printf(“\nThe element is found”);
}
}
for(P=L;P!=NULL;P=P->next)
{ count++;
if(P->data==NULL)
{
printf(“\nThe element is found”);
printf(“\nThe position is %d”,count);
}
}
for(P=L;P!=NULL;P=P->next)
{ count++;
if(P->data==a)
{ flag=1;
printf(“\nThe element is found”);
printf(“\nThe position is %d”,count);
}
}
for(P=L;P!=data;P=P->next)
{ count++;
if(P->data==a)
{ flag=1;
printf(“\nThe element is found”);
printf(“\nThe position is %d”,count);
}
}
Design structure for Polynomial manipulation
struct poly
{ int coeff;
int power;
struct poly *next;
}
struct poly
{
int power;
int var;
int expo;
struct poly *next;
}
struct poly
{ int coeff;
int power;
}
struct poly
{ int coeff;
struct poly *next;
}
