# Some problems in Data structure and algorithm.

0 like 0 dislike
85 views

edited

Here, you will know various types of numericals and solutions to it.

0 like 0 dislike
by (562 points)
selected

### Conversion of infix expression to prefix expression

P) (A+B) *C

Solution:

⇒[+AB]*C

⇒*+ABC

P:2) (A-B) *(C+D)

Solution:

⇒[-AB]*[+CD]

⇒*-AB+CD

P:3) (A+B) /(C+D) -(D*E)

Solution:

⇒[+AB]/[+CD]-[*DE]

⇒[/+AB+CD]-[*DE]

⇒-/+AB+CD*DE

1. ### Convert the expression given below into its equivalent prefix and postfix notation.

((A+B) ^C) -(D-E) ^(F+G))

Prefix notation:

(​​​​[+AB]^C-[-DE]^[+FG])

⇒-^ABC ^ -DE+FG

Postfix Notation:

⇒AB+C^DE-FG+^-

1. Evaluate the following postfix expressions for A=2, B=5, C=3, D=2, E=4

ABC+DE*/-

Show stack at each step.

Solution:

ABC+DE*/-

Given, A=2, B=5, C=3, D=2, E=4

So, putting values of A, B, C, D, E into the above expression , we get

2 5 3+2 4 * / -

 Symbol Scanned Stack (1)                 2 2 (2)                 5 2, 5 (3)                 3 2, 5,3 (4)                 + 2,8 (5)                 2 2, 8,2 (6)                 4 2, 8,2,4 (7)                 * 2, 8,8 (8)                 / 2, 1 (9)                - 1

So, the final number in stack is 1, which is the solution.

1. Transform the following expression into its equivalent postfix expression using stack.

A+(B*C-(D/E↑) *G) *H)

Solution:

 Symbol Scanned Stack Expression (1)         A ( A (2)         + (+ A (3)        ( (+( A (4)        B (+( AB (5)        * (+(* AB (6)        C (+(* ABC (7)       - (+(- ABC* (8)       ( (+(-( ABC* (9)        D (+(-( ABC*D (10)      / (+(-(/ ABC*D (11)      E (+(-(/ ABC*DE (12)      ↑ (+(-(/↑ ABC*DE (13)      F (+(-(/↑ ABC*DEF (14)     ) (+(- ABC*DEF↑/ (15)      * (+(-* ABC*DEF↑/ (16)      G (+(-* ABC*DEF↑/G (17)      ) (+ ABC*DEF↑/G*- (18)      * (+* ABC*DEF↑/G*- (19)     H (+* ABC*DEF↑/G*-H (20)     ) ABC*DEF↑/G*-H*+

The equivalent postfix expression of the above infix expression is:

ABC*DEF↑/G*-H*+

1. Calculate the position of element which is present in 7th row and 8th column for a 10×10 matrix . Here base address is 6010.

Solution:

By row major order: