Latest News
|
|
UNIT 7
TOPICS TO BE COVERED IN THIS UNIT:
- Introduction to data structures
- Singly linked lists
- Doubly linked lists
- Circular list
- Representing stacks and queues in C using arrays and linked lists
- Infix to post fix conversion
- Postfix expression evaluation
TEACHING MATERIAL
Unit 7 Teaching Aids - Click Here
TUTORIAL MATERIAL
Tutorial-1
- Explain the algorithm to insert a node before a specified node in doubly linked list.
-
For storing the sorted data on which often insert and deletion operations are performed, the following data structure is better
- Array
- queue
- linked-list
- doubly linked-list
-
The concatenation of two lists is to be performed in O(1) time. Which of the following implementations of a list could be used?
- Singly linked list
- Doubly linked list
- Circularly doubly linked list
- Array implementation of list
-
Which of the following programming languages features require a stack-base allocation
- pointer
- Block-structure
- recursion
- dynamic scoping
-
Stacks can not be used to
- evaluate an arithmetic expression in postfix form
- implement recursion
- convert a given arithmetic expression in infix form to is equivalent postfix form
- allocates resources (like CPU) by the operating system
-
Declare a queue of integers. Write functions
- To insert an element in to queue
- To delete an element from queue
Tutorial-2
-
An item that is read as input can be either pushed to a stack or latter popped and printed, or printed directly. Which of the following will be the output if the input is the sequence of items-1,2,3,4,5?
- 3,4,5,1,2
- 3,4,5,2,1
- 1,5,2,3,4
- 5,4,3,2
-
Stack is useful for _ _ _ _ _ _ _
- radix sort
- breadth first search
- recursion
- quick sort
-
A stack is has the entries a,b,c,(with a on top). Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of stack B can only be printed. In this arrangement, which of the following permutations a,b,c is not possible?
- b a c
- b c a
- c a b
- a b c
-
Write an algorithm to insert an element in the linked list at the following positions:
- After a specified element
- At the end of a list.
-
Which of the following is essential for converting an infix expression to postfix form efficiently?
- An operator stack
- An operand stack
- An operator stack and an operand stack
- A parse tree
-
The postfix equivalent of the prefix * + a b - c d is
- ab + cd - *
- ab cd + - *
- ab + cd * -
- ab + - cd *
-
The postfix expression for the infix expression A + B* (C+D) / F + D*E is:
- AB + CD + F / D + E*
- ABCD + * F / + DE*
- A*B + CD / F*DE ++
- A+ BCD / F* DE ++
-
A telephone system which places cells to a particular number on hold can best represented by
- queue
- stack
- linked-list
- variable
Tutorial-3
-
The infix form of the postfix expression ABC-/D*E+ is
- A/B-C*D+E
- A-B/C*D+E
- (A-B)/C*D+E
- A/(B-C)*D+E
-
The equivalent of (a+b^c^d)*(e+f/d) in the post fix notation is
- aab+c^d^e &fd/
- abcd^+^efd/+*
- abcdefd/+*^^+
- abcd^^+efd/+*
-
If the sequence of operations push(1),push(2) ,pop, push(1),push(2),pop, pop, pop, push(2),pop,
are performed on a stack, the sequence of popped out values are
- 2,2,1,1,2
- 2,2,1,2,2
- 2,1,2,2,1
- 2,1,2,2,2
-
The disadvantage of the queue is
- when the item is deleted, the space for that item is not claimed
- when the item is deleted, the space for that item is claimed
- a non destructive
- increases the memory space
-
As the items from a queue get deleted, the space for item is not reclaimed in queue. This problem is solved by
- circular queue
- stack
- linked list
- doubly linked list
-
Queue can be used to implement
- radix sort
- quick sort
- recursion
- depth first search
-
A queue of characters currently contained a, b, c, d.
What would be the contents of queue after the following operation DELETE, ADD W, ADD X, DELETE, ADD Y
- A, B, C, W, Y
- C, D, W, X, Y
- W, Y, X, C, D
- A, B, C, D, W
-
Give an algorithm to reverse a singly linked circular list in place.
PRACTICE PROBLEMS
Beginner problems
-
Imagine we have empty stack S, draw the pictures of each stack after the following operation.
- push(20);
- push(40);
- push(30);
- push(50);
- pop( );
- pop( );
-
Imagine we have empty queue Q, draw the pictures of each queue after the following operation.
- Q_insert(20);
- Q_insert(30);
- Q_insert(50);
- Q_insert(30);
- Q_del();
- Q_del();
- Q_del();
-
Convert the following infix expressions into postfix expressions.
- X-Y+Z*W
- X+Y-X/W
- A/E*B-H+E/C*G
- W+X/T*T*Y/Z
-
What is value of the each of the following postfix expressions after evaluation?
- 1 2 4 3 + - *
- 1 2 5 4 3 / * + -
- 3 4 2 4 / * -
- 4 5 8 6 + - *
-
Imagine we have a general list shown in fig-1, show what happen if we apply the following statements to this general list.
- list1=list1->link;
- list1=list1->link;
-
Imagine we have a general list shown in fig-1, show what happen if we apply the following statements to this general list.
- list2=list1;
- list2->info=30;
- list2=list2->link;
Intermediate problems
-
What would happen if we execute the following code?
int main()
{
int i,j, arr[5];
for(i=0;i<5;i++)
scanf("%d",&arr[i]);
i= - - i - i++
for(j=i;j<5;j++)
printf("%4d",arr[j]);
}
-
Consider the fig-1, what would happen if we apply the following statements to two lists?
temp=list1;
while(temp->link!=NULL)
{
temp=temp->link;
if(temp->info==40)
break;
}
temp->link=list2;
-
Consider the fig-1, what would happen if we apply the following statements to two lists?
temp= list2;
while (temp->link!=NULL)
{
temp=temp->link;
if(temp->info==50)
{
temp->link=list1;
break;
}
}
temp=list2
while(temp->link!=NULL)
{
printf("%3d",temp->info);
temp=temp->link;
}
-
Consider the figure -1
What happens if we apply the following code to two lists?
temp= list1;
while (temp->link!=NULL)
temp=temp->link;
temp->link=list2;
Advanced problems
-
What would happen if we execute the following code?
int main()
{
int top=-1, arr[5];
arr[++top]=20;
arr[++top]=40;
arr[++top]=60;
arr[++top]=80;
top--;
top--;
while(top>=0)
printf("%4d",arr[top--]);
}
-
What would happen if we execute the following code?
int main()
{
int front=0,rear=0, arr[5];
arr[rear++]=20;
arr[rear++]=40;
arr[rear++]=60;
arr[rear++]=80;
front++;
while(frontlink=NULL;
temp1->info=20;
temp=temp1;
temp2=(int *)malloc(sizeof(struct node));
temp2->link=NULL;
temp2->info=30;
temp1->link=temp2;
temp3=(in *)malloc(sizeof(struct node));
temp3->link=NULL;
temp3->info=40;
temp2->link=temp3;
while(temp->link!=NULL)
{
printf("%3d",temp->info);
temp=temp->link;
}
}
-
What would happen if the following statements are executed, and draw the picture of each of the operation?
struct node
{
int info;
struct node *link;
};
int main()
{
struct node *temp=NULL,*temp1,*temp2,*temp3;
temp1=(int *)malloc(sizeof(struct node));
temp1->link=NULL;
temp1->info=20;
temp2=(int *)malloc(sizeof(struct node));
temp2->link=NULL;
temp2->info=30;
temp3=(int *)malloc(sizeof(struct node));
temp3->link=NULL;
temp3->info=40;
temp=teamp3
temp3->link=temp2;
temp2->link=temp1;
while(temp->link!=NULL)
{
printf("%3d",temp->info);
temp=temp->link;
}
}
-
Write a function stack_concate() that concatenates contents of one stack on top of another stack using arrays.
-
Write a function queue_concate() that concatenates contents of one queue at the end of another queue using arrays.
-
What would happen if the following statements are executed, and draw the picture of each of the operation?
struct node
{
struct node *left;
int info;
struct node *right;
}
int main()
{
struct node *temp=NULL,*temp1,*temp2;
temp1=(int *)malloc(sizeof(struct node));
temp1->left=NULL;
temp1->right=NULL;
temp1->info=20;
temp=temp1;
temp2=(int *)malloc(sizeof(struct node));
temp2->left=NULL;
temp2->right=NULL;
temp2->info=30;
temp1->right=temp2;
temp2->left=temp1;
while(temp->link!=NULL)
{
printf("%3d",temp->info);
temp=temp->link;
}
printf("%3d",temp->info);
}
This Page Is Designed By krishna Chaitanya
|