0% found this document useful (0 votes)
102 views7 pages

Biology Project On Dna Fingerprinting

This document discusses linear data structures stacks and queues. It defines stacks and queues, their operations, and applications. Stacks follow LIFO (last-in first-out) while queues follow FIFO (first-in first-out). Common stack operations are push and pop, while common queue operations are enqueue and dequeue. Examples of applications for each are given such as evaluating expressions for stacks and simulation for queues.

Uploaded by

Gowthami S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views7 pages

Biology Project On Dna Fingerprinting

This document discusses linear data structures stacks and queues. It defines stacks and queues, their operations, and applications. Stacks follow LIFO (last-in first-out) while queues follow FIFO (first-in first-out). Common stack operations are push and pop, while common queue operations are enqueue and dequeue. Examples of applications for each are given such as evaluating expressions for stacks and simulation for queues.

Uploaded by

Gowthami S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CS8391 – Data Structures

UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES

Stack ADT – Operations - Applications - Evaluating arithmetic expressions- Conversion of Infix to


postfix expression.
Queue ADT – Operations - Circular Queue – Priority Queue - DeQueue – applications of queues.
1. Give any four applications of stack. [Nov’09, Apr’10, Nov’12]
Evaluation of arithmetic expressions.
Balancing the symbols.
Function calls.
Tower of Hanoi.
Reversing a string.
8-Queen’s Problem.

2. What is an Abstract Data Type? What are all not concerned in an ADT? [Nov’10][Apr’15]
An ADT is a set of operation. A useful tool for specifying the logical properties of a datatype is the
abstract data type. ADT refers to the basic mathematical concept that defines the datatype.
Eg. Objects such as list, set and graph along their operations can be viewed as ADT's.

3. What is Last-In First-Out strategy? Which data structure follows this strategy? [Apr’11]
The order in which elements come off a stack gives rise to its alternative name, LIFO (last in, first
out). Considered as a linear data structure, or more abstractly a sequential collection, the push and
pop operations occur only at one end of the structure, referred to as the top of the stack. Stack data
structure follows this strategy.

4. Why is circular queue better than standard linear queue? [Nov’11]


A circular queue is better than single queue in terms of space utilization. In circular queue, utilizes
the left over space until the queue is not filled. Circular queue is a bounded queue which implements
arrays. It is better than a normal queue because in this, we can effectively utilize the memory space.

5. Give the applications of priority queues.


External sorting.
Greedy algorithm implementation.
Discrete event simulation.
Operating systems.

6. Define priority queue with diagram and give the operations.


Priority queue is a queue in which inserting an item or removing an item can be performed from any
position based on some priority. The implementation can be done in either array or linked list
structure. The basic operations are insertion and deletion.
Priority Queue H
Insert (H) DeleteMin(H)

7. List the applications of queue. [Nov’14] [May’14]


Batch processing in an operating system.
To implement priority queue.
Simulation.
Mathematics user queuing theory.
Computer networks where the server takes the jobs of the client as per the queue strategy.

8. Convert into postfix and evaluate the expression. (a+b*c)/d i.e a=2, b=4, c=6, d=2
Postfix: abc*+d/
Evaluation: 2 4 6 * +2/ =13

9. Write the push and pop routine for stack ADT.


/*routine for push*/
void push(ElementType X, Stack S)
{ PtrToNode TmpCell;
TmpCell=malloc(sizeof(struct Node));
If(TmpCell==NULL)
FatalError(“out of space!!!”);
else
{ TmpCellElement=x;
TmpCellNext=SNext;
SNext=TmpCell;
}}

/*Routine for pop*/


void pop(Stack S)
{ PtrToNode firstCell;
if(isEmpty(S))
Error(“Empty stack”);
else
{ FirstCell=SNext;
SNext=SNextNext;
free(firstCell);
}}

10. Define: a) dequeue b) circular queue c) priority queue [Nov’14][May’14]


a. Dequeue:
Dequeue is the Double Ended Queue in which insert and delete operations are performed at the both
the ends. There are two variations of a deque, namely, input restricted deque and output restricted
deque. The input restricted deque allows insertion at one end (it can be either front or rear) only.
The output restricted deque allows deletion at one end (it can be either front or rear) only.
b. Circular Queue:
Another form of linear queue in which the last position is connected to the first position of the list.
The circular queue is similar to linear queue has two ends, the front end and the rear end. The rear
end is where we insert elements and front end is where we delete elements. We can traverse in a
circular queue in only one direction ie) from front to rear.
c. Priority Queue:
Priority queue is a collection of elements, each containing a key referred as the priority for that
element. Elements can be inserted in any order (i.e., of alternating priority), but are arranged in order
of their priority value in the queue. The elements are deleted from the queue in the order of their
priority (i.e., the elements with the highest priority is deleted first). The elements with the same
priority are given equal importance and processed accordingly.

11. How do you push and pop elements in a linked stack?


push(value) - Inserting an element into the Stack
We can use the following steps to insert a new node into the stack.
Step 1: Create a newNode with given value.
Step 2: Check whether stack is Empty (top == NULL).
Step 3: If it is Empty, then set newNode → next = NULL.
Step 4: If it is Not Empty, then set newNode → next = top.
Step 5: Finally, set top = newNode.

pop( ) - Deleting an Element from a Stack


We can use the following steps to delete a node from the stack.
Step 1: Check whether stack is Empty (top == NULL).
Step 2: If it is Empty, then display "Stack is Empty!!! Deletion is not possible!!!" and terminate the
function.
Step 3: If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.
Step 4: Then set 'top = top → next'.
Step 5: Finally, delete 'temp' (free(temp)).

12. Define stack. List the characteristics of stack.


A Stack is an ordered collection of items into which new items may be inserted and from which items
may be deleted at one end, called the top of the stack.

Characteristics:
Stack is an ordered list of similar data type.
Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
push() function is used to insert new elements into the stack and pop() function is used to remove
an element from the stack. Both insertion and removal are allowed at only one end of stack called
top.
Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state
if it is completely empty.

13. Define queue. Give the structure of queue model. [Nov’15]


A Queue is an ordered collection of items from which items may be deleted at one end called the front
of the queue and into which tems may be inserted at the other end called rear of the queue. Queue is
called as First –in-First-Out (FIFO).

Queue Model

14. What are the basic operations of Queue ADT?


The basic operations of Queue ADT are enqueue and dequeue.
Enqueue operation:
1. Check if the queue is full or not.
2. If the queue is full, then print overflow error and exit the program.
3. If the queue is not full, then increment the rear pointer and add the element.

Dequeue operation:
1. Check if the queue is empty or not.
2. If the queue is empty, then print underflow error and exit the program.
3. If the queue is not empty, then print the element at the front and increment the front
pointer.

15. Illustrate the purpose of enqueue and dequeue?


1. Enqueue-inserts an element at the end of the list called the rear.
2. Dequeue-delete and returns the element at the start of the list called as the front.

16. What is the use of stack pointer?


The Stack Pointer (SP) register is used to indicate the location of the last item put onto the
stack. When you PUT something onto the stack (PUSH onto the stack), the SP is incremented
before the item is placed on the stack. When you take something OFF of the stack (PULL from
the stack), the SP is decremented after the item is pulled from the stack. Before using a stack,
we have to initialize the SP to -1 i.e the empty condition specified.

17. What is meant by circular queue(Ring buffer)? State its advantages.


Another form of linear queue in which the last position is connected to the first position of the list.
The circular queue is similar to linear queue has two ends, the front end and the rear end. The rear
end is where we insert elements and front end is where we delete elements. We can traverse in a
circular queue in only one direction ie) from front to rear.

Advantages:
It takes up less memory than the linear queue. So efficient memory utilization.
A new item can be inserted in the location from where a previous item is deleted.
Infinite number of elements can be added continuously but deletion must be used.

18. State the exceptional conditions for stack.


Exception conditions for stack are overflow and underflow.
Overflow exception: happens when there is no more space left to store a data item that is pushed.
Underflow exception: happens when the stack is empty and the user executed a pop operation.

19. Differentiate between stack and queue.


Stack Queue
LIFO (Last in First out) concept. FIFO (First in First out) concept.
One end is used for insertion, i.e., rear end and
Same end is used to insert and delete
another end is used for deletion of elements,
elements.
i.e., front end.
Supports push and pop operations. Supports enqueue and dequeue operations.
It has variants like circular queue, priority
It does not have variants.
queue, doubly ended queue.
Simple implementation. Complex implementation.
Number of pointers – 1(stack pointer). Number of pointers – 2(front & rear).
Applications: Balancing Symbols, Applications: CPU task scheduling, handling of
Tower of Hanoi, 8 queens problem interrupts.
20. Write the similarities and variations between circular queue and dequeue.
Dequeue:
Dequeue is the Double Ended Queue in which insert and delete operations are performed at the both
the ends. There are two variations of a deque, namely, input restricted deque and output restricted
deque. The input restricted deque allows insertion at one end (it can be either front or rear) only.
The output restricted deque allows deletion at one end (it can be either front or rear) only.

Circular Queue:
Another form of linear queue in which the last position is connected to the first position of the list.
The circular queue is similar to linear queue has two ends, the front end and the rear end. The rear
end is where we insert elements and front end is where we delete elements. We can traverse in a
circular queue in only one direction ie) from front to rear.

21. Convert the infix expression (a+b*c-d)/(e*f-g). (Using stack-step by step)


Postfix: a b c * + d – e f * g - /

22. Write a routine to return the top element of stack.


Routine:( Array Implementation)
int poptop(int st[ ])
{ if(top==-1)
{
print(“Stack Empty”);
return -1; }
else
{
return st[top]; }

23. What are the two basic types of data structures?


1. Primitive Data Structure Eg., int, char, float
2. Non Primitive Data Structure
i. Linear Data structure Eg., Lists, Stacks, Queues
ii. Non linear Data structure Eg., Trees, Graphs

24. What are the four basic operations of data structures?


1. Traversing
2. Searching
3. Inserting
4. Deleting

25. State the features of balancing symbols.


1. It is clearly linear.
2. Makes only one pass through the input.
3. It is online and quite fast.
4. It must be decided what to do when an error is reported.

26. How to avoid frequent overflow conditions and wastage of memory in stack?
The concept of multiple stacks will provide a better solution to avoid frequent overflows and waste
of memory issues in stack.

0 1 2 3 …………………………………………….. n-4 n-3 n-2 n-1


StackA StackB
Multiple Stacks

27. Convert the following infix expression into prefix and postfix expression: (Using stack)
(i) (A - B) * (C+D)
Prefix: * - A B + C D
Postfix: A B – C D + *

(ii) (A + B) / (C + D) - (D * E)
Prefix: - / + A B + C D * D E
Postfix: A B + C D + / D E * -

(iii) (A + B) * C
Prefix: * + A B C
Postfix: A B + C *

(iv) A - (B / C + (D % E * F) / G) * H
Prefix: - * H + / G % * F E D / C B A
Postfix: A B C / D E F * % G / + H * -

28. Evaluate the expression ( 9 – (( 3 * 4 ) + 8 ) / 4 using stack.


Infix: ( 9 – (( 3 * 4 ) + 8 ) / 4
Postfix: 9 3 4 * 8 + 4 / -
Character Read Stack
9 9
3 9, 3
4 9, 3, 4
* 9, 12
8 9, 12, 8
+ 9, 20
4 9, 20, 4
/ 9, 5
- 4

29. Define backtracking.


It is concerned with finding a solution by trying one of several choices. If the choice proves incorrect,
computation backtracks or restarts at the point of choice and tries another choice.
Ex: 8-Queens Problem – Find a solution to place 8 queens in an 8 X 8 board i.e each row should have
one queen to be placed without attacking scenario.

30. Illustrate the purpose of using multiple queues.


The purpose of using multiple queues is to provide a better solution to deal with two problems
specified below:
Problem 1: If queue is allocated with less space, frequent overflow conditions would occur.
Problem 2: If queue is allocated with more space, waste of memory may evolve due to less utilization
rate.

31. Give the infix expression of the following prefix expressions.


(i) * - + A B C D
Infix: ((A+B)-C)*D
(ii) + - A * B C D
Infix: (A-(B*C))+D

32. State the general rule for processing the elements of a priority queue.
The general rules for processing the elements of a priority queue are as,
Rule 1: An element with higher priority is processed before an element with a lower priority.
Rule 2: Two elements with the same priority are processed on First Come First Serve(FCFS) basis.
33. List the types of dequeue and its purpose.
Basically, there are two variants such as,
Input restricted dequeue – Insertion can be done at only one end of the queue while deletions
can be done at both ends.
Output restricted dequeue - Deletion can be done at only one end of the queue while
insertions can be done at both ends.

34. State the different ways of representing expressions.


Infix Notation or standard form.
Prefix Notation.
Postfix Notation or reverse polish notation.
Ex:
Infix : a + b
Prefix: + a b
Postfix: a b +

35. What is static linked list? Give any two applications. [Apr’15]
Static linked lists share following characteristics:
Faster access to elements (when compared with dynamic data structures).
Add, remove or modify elements is not directly possible. If done, it is a resource consuming
process.
Fixed size.
Resources allocated at creation of data structure, even if elements are not contain any value.
Applications:
 Stack, Queue implementations
 Implementation of graphs, hash tables
 Undo functionality in photoshop or word processing.

36. Write the algorithm for balancing symbols.


1) Declare a character stack S i.e initially empty.
2) Now traverse the expression i.e string expression.
a) If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.
b) If the current character is a closing bracket (‘)’ or ‘}’ or ‘]’) then pop from stack and if the
popped character is the matching starting bracket then fine else parenthesis are not balanced.
3) After complete traversal, if there is some starting bracket left in stack then “not balanced”.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy