Postfix operation

Thread Solved

Join Date: Jul 2009
Posts: 3
Reputation: sumeetdesaeee is an unknown quantity at this point 
Solved Threads: 0
sumeetdesaeee sumeetdesaeee is offline Offline
Newbie Poster

Postfix operation

 
0
  #1
Jul 12th, 2009
I recently appeared for the entrance of cdac.
There I found a lot of questions about postfix.(I know the postfix operator commonly used in c.But it wasn't that way.)
Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
Please tell me how to deal with such questions???
And since I am a new user,if I have made any mistake in method of creating a new thread,pls forgive me for that.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Postfix operation

 
0
  #2
Jul 12th, 2009
> Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
You need to post some actual C code.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: praveenraj1987 is an unknown quantity at this point 
Solved Threads: 1
praveenraj1987's Avatar
praveenraj1987 praveenraj1987 is offline Offline
Newbie Poster

Re: Postfix operation

 
0
  #3
Jul 12th, 2009
are you talking about postfix operator as ++a or --a or you referring to postfix expression as in +ab will become a+b??
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: abhi.navale is an unknown quantity at this point 
Solved Threads: 2
abhi.navale's Avatar
abhi.navale abhi.navale is offline Offline
Newbie Poster

Re: Postfix operation

 
0
  #4
Jul 12th, 2009
it is not postfix / prefix in 'c' language i.e. it is not ++a (pre increment 'a') or b-- (post decrement 'b')

it a postfix/prefix which referes to conversion of human readable mathematical expression into computer readable mathematical expression.
when we see "solve a+b" then we just do a plus b
but computer dont understand what 'a+b' means
to let computer understand what 'a+b' means we convert it to postfix expresstion
prefix meas we arrange our expression in such a way that all operators(+,/,-,*) will come first and then oprands (i.e. a,b, etc.)

in same way postfix means operatos will be at end and operands will come first


example : solve a+b , then
conversion of above example in prefix: +ab
conversion of above example in postfix: ab+

there are some algo to do this conversion. also there are many application of postfix/prefix string expressiotn like stack, string reverse etc.
Last edited by abhi.navale; Jul 12th, 2009 at 6:18 am.
Abhi
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 110
Reputation: s_sridhar has a little shameless behaviour in the past 
Solved Threads: 11
s_sridhar's Avatar
s_sridhar s_sridhar is offline Offline
Junior Poster

Re: Postfix operation

 
0
  #5
Jul 12th, 2009
Postfix expression is used to aid the order of evaluation of a mathematical expression.
When higher level programming languages came into existence one of the major hurdles faced by computer scientists was to generate machine language instructions that would properly evaluate any arithmetic expression.
for eg. A*B/C is AB*C/ in postfix notation.
Notice three features of postfix expression:

-The operands maintain the same order as in the equivalent infix expression.
-Parantheses are notneeded to designate the expression unambiguously
-While evaluating the postfix expression the priority of the operators is no longer relevant.
Intel inside, mental outside
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Postfix operation

 
0
  #6
Jul 12th, 2009
Originally Posted by sumeetdesaeee View Post
Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
The expression contains only operands. Where are the operators?

If you have a string in infix, ie. in form A+B, and you wish to have it in the form AB+, you can use the Shunting Yard Algorithm
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: sumeetdesaeee is an unknown quantity at this point 
Solved Threads: 0
sumeetdesaeee sumeetdesaeee is offline Offline
Newbie Poster

Re: Postfix operation

 
0
  #7
Jul 12th, 2009
I am talking about postfix expression as in +ab will become a+b.
Can u pls explain it properly ???
And pls also tell me in which book i will get it so that I can have some more reference..
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Postfix operation

 
1
  #8
Jul 12th, 2009
That is just the reverse of the aforementioned algorithm.

Explanation- Scan the input string from left to right. Whenever you see an operand, just push it onto a stack. When you encounter an operator, pop two elements and concatenate the operator between the two operands and push it back to the stack. Perform this till the input string is fully parsed. The only element left in the stack (if the postfix expression is valid) will be the required infix expression.

eg- AB+

1. push A to stack
2. push B to stack
3. Next element is '+'. pop two elements, B and A apply the operator (A+B) and push it back to stack
4. Since you have fully examined the input string, the element left in the stack is the required expression.

This is just a very basic explanation, google for a more precise technique

ps- the thread name says 'postfix' but in your post, you have given a prefix string (+AB). In such a case just parse the input dtring from R->L in the algorithm.

Hope this helps
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: sumeetdesaeee is an unknown quantity at this point 
Solved Threads: 0
sumeetdesaeee sumeetdesaeee is offline Offline
Newbie Poster

Re: Postfix operation

 
0
  #9
Jul 13th, 2009
Ok friends....thanks a lot......I got it......
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

Re: Postfix operation

 
0
  #10
Jul 14th, 2009
postfix evaluation:
===================

question: AB+C-DE+*
steps:
1)group like this

(AB+) C-DE+*
-----
lets say AB+ (means A+B) is x then

2)(xC-)DE+*
-----
(k)

3)then

k(DE+)*
----
(z)

4)then
kz* means k*z is the answer.

postfix to infix convertion:
===========================
1) AB+C-DE+*

2)((AB+)C-)(DE+)*

put bracket like this where two operand and one operand should be there in this manner.

now change the operand in the last to middle.like

3)((A+B)C-)(DE+)*

4)((A+B)-C)(D+E)*

5)((A+B)-C)*(D+E) it will your final infix expression.

postfix to prefix convertion:
=============================
1) AB+C-DE+*

2)((AB+)C-)(DE+)*

put bracket like this where two operand and one operand should be there in this manner.
now bring the operation from the beginning to the end.

3)((+AB)C-)(DE+)*

4)*(-(+AB)C)(+DE)

5)now remove all the brackets.

6)*-+ABC+DE ====its the answer.

I have given your the fastest tips to solve these kind of problems.

In case of any problem you face let me know.

Thanks,
DP
Last edited by Dream2code; Jul 14th, 2009 at 7:51 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC