DS T VIVA Mid Moinul

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1) A Stack: or LIFO (last in, first out) is an abstract data type that serves

as a collection of elements, with two principal operations:


 push adds an element to the collection;

 pop removes the last (top of the stack) element that was added.

2) A Queue: is a FIFO (First In First Out) data structure where the element
that is added first will be deleted first.

 A queue is a sequence of data elements

 Items can be added only at the rear

 Items can be removed only at the other end, front

3) Circular Queue: is a linear data structure in which the operations are


performed based on FIFO (First In First Out) principle and the last position is
connected back to the first position to make a circle. It is also called 'Ring Buffer'

4) Difference between linear queue and circular queue:


5) Difference between STACK and QUEUE:
a) in stack Objects are inserted and removed at the same end.
In queue Objects are inserted and removed from different ends.

b) In stacks only one pointer is used. It points to the top of the stack.
In queues, two different pointers are used for front and rear ends.

c) Stacks follow Last In First Out (LIFO) order.


Queues following First In First Out (FIFO) order.
d) Stack operations are called push and pop.
Queue operations are called enqueue and dequeue.

6) Applications of Stack & Queue


 Syntax parsing, Parenthesis check, Banking Transaction, Backtracking and
implementation of recursive function, calling function, Towers of Hanoi [Stack]
 Keeping Track of Printing Jobs [Queue]

7) Infix, Postfix and Prefix Expressions

INFIX: Jodi operator operand er majhe takhe.


The expressions in which operands surround the operator, i.e. operator is in between
the operands. e.g. x+y, 6*3 etc.

POSTFIX: Also Known as Reverse Polish Notation (RPN). The operator comes after
the operands, i.e. operator comes post of the operands, so the name postfix. e.g. xy+,
xyz+* etc. (i++)

PREFIX: Also Known as Polish notation. The operator comes before the operands,
i.e. operator comes pre of the operands, so the name prefix. e.g. +xy, *+xyz etc. (i++)

8) INFIX to PREFIX:
Symbol stack prefix
সব কিছুই serially Operator & Rules apply করার আগে শুধু Operand গুলা যাবে,,
থাকবে Bracket আর, Rules apply করার পরে Operator গুলা যাবে
থাকবে
rule-1: bracket er vitore Jodi + or * ashe tahale popout hoye jay.

Rule-2: Jodi same priority r operator duita eksathe thakhe tahle tara eksathe takhte parbe
jotokhon porjonto onno operator na ashe.
Rule-3: age kono operator Jodi takhe ebong seitar priority Jodi notun jei operator ashbe eitr
tekhe beshi hoy tahle jara age tekhe chilo tara keu r takhbe na..

9) Operator Precedence and Associativity:


Operator precedence: Precedence hocche jodi multiplication or division (mane jei
operator boro seitr kaj age hbe) kono expression e takhe tahle oigula kaj age hbe. (right to
left).

A) Associativity: hocche left to right..mane jeta age ashbe setr e kaj hbe
age (left to right).
Associativity defines the order in which operators of the same precedence are evaluated
in an expression. Operators that appear in the same group have the same precedence

10) Parenthesis If a symbol is an opening parenthesis, push it on the


stack as a signal that a corresponding closing symbol needs to appear later. If, on the
other hand, a symbol is a closing parenthesis, pop the stack. As long as it is possible to
pop the stack to match every closing symbol, the parentheses remain balanced.
Parenthesis Check Using Stack: We will read the
expression as a string and for each character we will do the following three
things:
a) Whenever we get an opening parenthesis, we will push it into the stack.
b) When we get a closing parenthesis we will check that with the top of the
stack. If the top of the stack has the same type of opening parenthesis, we
will pop it.

11) Stack Logics:


a)

b)
c)

d)

e)
f)

12) Pseudo code of Queue Implementation:


13) Pseudo code of Circular Queue Implementation:

You might also like