0% found this document useful (0 votes)
44 views11 pages

Data Structures: Radhamadhab Dalai Asst. Professor CSE BIT Mesra, Ranchi

Uploaded by

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

Data Structures: Radhamadhab Dalai Asst. Professor CSE BIT Mesra, Ranchi

Uploaded by

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

Data Structures

Radhamadhab Dalai
Asst. Professor
CSE
BIT Mesra, Ranchi

29-09-2020 1
Stack

D TOP Push Pop

29-09-2020 2
Expressions
• Infix: A+B-C
• Prefix : -+ABC
• Postfix: AB+C-
• Example : A+B+C and A+B*C
• AB+C+ and ABC*+

29-09-2020 3
Postfix to Prefix
• Scan the postfix input string from left to right.
• If ‘ch’ is an operand push it to stack
• 1. If ‘ch’ is an operator pop two
elements(operand1 ,operand2).
2. Make a string like str = operator + operand2 +
operand1.
3.Push whole string (str) back to stack
• Repeat untill end of string
• Top of stack will contain whole string as output,
pop.

29-09-2020 4
Postfix to Prefix
• Post fix : ABC*+
Character Stack operation Stack
A PUSH A
B PUSH AB
C PUSH ABC
* POP 2, APPEND, A*BC
PUSH
+ POP 2, APPEND, +A*BC
PUSH

29-09-2020 5
Questions
• What are the applications of circular queue ?
• Revisit queue and singly linked lists and
doubly linked lists.

29-09-2020 6
Polynomial addition
• Addition of two polynomial expressions using
singly linked lists.
• anxn + an-1xn-1 + …….+ a2x2 + a1x +a0
• bnxn + bn-1xn-1 + ……. + b2x2 + b1x +b0
• Cn = an + bn, Cn-1= an-1+bn-1, c0 = a0 + b0

29-09-2020 7
Polynomial addition
• Polynomial representation in linked lists
head1

an next an-1 next a1 next a0 next

head2

bn next bn-1 next b1 next b0 next

29-09-2020 8
Polynomial addition
• Scenarios:
• Degree of first polynomial (m) and degree of
second polynomial (n) are not same. m != n
head3

cn next cn-1 next c1 next c0 next

29-09-2020 9
Polynomial addition
• Implementation
• Approach ? A good input set and an output.
• while( ?)
• Time complexity.

29-09-2020 10
Questions
• Questions ?

29-09-2020 11

You might also like