Why can't we get teachers like this in college lol. I'm sure you're tired of hearing but thank you so much for all your videos, you explain everything so well.
@@HandledToaster2 this channel used to run by two individuals unfortunately one passed away in a tragic car accident (Indian roads you know) and other just stop will to continue the channel so he just go to work for google
OMG thank you so much! you explained it much better than my college teacher! Thanks for sharing this valuable information with us for free! thanks a lot!
Nice Video but you made a mistake in the video during "prefix" notation. You popped 5 & 4 and you multiplied them even though the symbol was + addition.
Code for prefix evaluation #include #include #include using namespace std; // Function to evaluate Porefix expression and return output int EvaluatePrefix(string expression); // Function to perform an operation and return output. int PerformOperation(char operation, int operand1, int operand2); // Function to verify whether a character is operator symbol or not. bool IsOperator(char C); // Function to verify whether a character is numeric digit. bool IsNumericDigit(char C); int main() { string expression; cout
In evaluation of prefix exp, atlast... If d operator comes, u hav two pop two elements...n here 2nd element is the 2nd operand.. So d final ans should be like -17 right???
Sir can you please tell how to convert complex expressions into postfix, for ex :- in my book a question is given i.e A*(B+D)/E-F-(G+H/K) and (A+ B ^ D)/(E-F)+G (^ IS NOT POWER). Please help!!
4 ปีที่แล้ว
hello i have 7 account to sub to your channel if u like but please solve some questions i have like 5. please👍👍👍👍👍👍 i didnt unerstand it
awesome ! so clear and understanding, thank you so much! the book for computer architecture just makes no sense. your videos are getting me through this class !
INTEGER STACK USED FOR POSTFIX ND PREFIX EXPRESSION EVALUATION public class IntStack { private int[] stack; private int top; private int size; public IntStack() {
this.stack = new int[10]; this.top = -1; this.size = 10; } public IntStack(int size) {
this.top = -1; this.size = size; this.stack = new int[this.size];
Sir,what is the need of writing s[i] - '0' in the call for push function in if block inside for loop in cal function. please help... #include struct Stack { int top; int cap; int*A; }; struct Stack* create(int n) { struct Stack* stack; stack->top=-1; stack->cap=n; stack->A=(int*)malloc(n*sizeof(int)); return stack; } main() { char s[100]; printf("Enter a postfix expression-"); scanf("%s",s); printf("The value is %d.",cal(s)); } void push(struct Stack* stack,char a) { stack->A[++stack->top]=a; } char pop(struct Stack*stack) { return stack->A[stack->top--]; } int cal(char *s) { int n=strlen(s),i,p1,p2; struct Stack*stack=create(n); for(i=0;i
Prefix expression evaluation source code in C++ : github.com/tridibsamanta/Data-Structures-and-Algorithms/blob/master/DS/PrefixEvaluation_Stack.cpp Postfix expression evaluation source code in C++ : github.com/tridibsamanta/Data-Structures-and-Algorithms/blob/master/DS/PostfixEvaluation_Stack.cpp
on evaluation of postfix, which one did u pop first? 26 or 9, since OP1 should be 9 because it is the first one to pop and OP2 is 26 (following LIFO), please clarify
9 was the first to pop and then 26 was popped. The way he has programmed, op2 holds the value of the element which was popped first and op1 holds the value of the element popped later. You can interchange what op1 and op2 mean when you write your own code.
I also got confused first but look 9 pops out first as op2 and then 26 pops out as op1. Now perform the operation op1- op2 that is 26- 9. I hope that makes sense.
Python implementation of postfix expression evaluation. Note: Parses single-digit numbers only. You may implement your preferred parser for input. #Stack class implementation class stack(): def __init__(self): self.headNode = None def trav(self): if(self.headNode): checkNode = self.headNode print checkNode.data while checkNode.next: next = checkNode.next print next.data checkNode = next def push(self,val): NN = Node(val) NN.next = self.headNode self.headNode = NN def pop(self): if(not self.headNode): return None CNode = self.headNode self.headNode = self.headNode.next return CNode def not_emp(self): if(self.headNode!=None): return True return False def top(self): return self.headNode #import operator module to match operator characters with Arithmetic functions import operator def postfix_eval(exp): #operator dictionary, pairing characters with arithmetic functions operators = {"+":operator.add,"-":operator.sub,"*":operator.mul,"/":operator.div} exp_stack = stack() for i in exp: #if not operator, i.e if operand, add to top of stack if(not i in operators): exp_stack.push(i) else: #if character operator, pop last two top elements in stack, be mindful of the order operand2 = int(exp_stack.pop().data) operand1 = int(exp_stack.pop().data) #call arithmetic operator with character as key in operators dictionary, and pass the last two popped elements as parameters result = operators[i](operand1,operand2) exp_stack.push(result) #when all done, return top(only) element left in stack return exp_stack.pop().data
A small correction in your code.... In else if(IsNumericDigit(expression[i])) don't do int operand = 0; Remove this line otherwise every time the control enters this else if statement it will assign the index of the string to 0 and start reading from the very beginning of the string.
why at the subtraction you place 26 as operand 1 instead of 9? isn't supposed to pop the topmost elements of the stack? 9 is the topmost and must pop out first then 26 so you will have 9-26, I'm confused.
why the hell in this world u started c++ codes it's not at all helping and more confusing no doubt the lecture is amazing but can u please provides the c based code
The prefix expression -+*23+549 is evaluating to 6, not 17... I even checked on online prefix analyzers. Correct me if I am wrong, Edit: Please ignore this, the actual expression is -+*23*549.
tried running the code as it is from gist.github.com/mycodeschool/7702441 and input as 23*54*+9-, The code it failing at runtime with BAD_ACCESS error AT while loop in EvaluatePostfix function and is prefix code available too? Also sir, would you please explain why do we need to reverse the expression for prefix evaluation? Thanks
Hi, Your explanation skills are way greater than any of the youtuber with data-structure videos. I recommend your channel to each of my colleagues whose base seem unclear in data-structures. You have did a great job. I have one query in this lesson. How can we convert an infix expression to pre/postfix expression, which contains an unary operator in it? Please edit your video with this content or please make a separate video for this. Thanks in advance.
Can anyone please tell me what is the problem with this code? Considering we are giving single digit value. #include #include #define MAX_SIZE 20 int top = -1; int stack[MAX_SIZE]; void push(int val) { stack[++top] = val; } int pop() { return stack[top--]; } int isEmpty() { if(top == -1) return 1; else return 0; } int isDigit(char x) { if(x >= '0' && x
ok 1_ strlen() need the string.h library 2_ this '^' operator in c is a bitwise operator non for the power of a number if you want to calculate the power of a number you can include the math.h library and use pow(x,y) 3_ atoi() takes a pointer as a parameter so instead of atoi(expression[i]) you should write atoi(expression + i)
@@davidevaccaro3760 thanks but 1. strlen() works just fine even without #include 2. atoi(expression [i]) was working fine too The problem I was facing was for input as 153, pow(1,3) was giving output 0, I don't know why
SARVESH KAUSHIK nope i dont think so both are differnet expressions on reversal but algo is nearly same ....just traversal is from last and operation...
Why can't we get teachers like this in college lol. I'm sure you're tired of hearing but thank you so much for all your videos, you explain everything so well.
Because Our Teachers doesn't belongs to Google. LOL
@@amanmishra-vt8hk I'm sorry, I don't know what you meant to say
@@HandledToaster2 He works at google.
@@amanmishra-vt8hk oooh I didn't know that! Makes sense.
@@HandledToaster2 this channel used to run by two individuals unfortunately one passed away in a tragic car accident (Indian roads you know) and other just stop will to continue the channel so he just go to work for google
give this man an oscar!
Isn't oscar is for entertainment industry he is teaching us not entertaining, doing much greater work than entertainment
@@arvindpanchal2721 :-bhawnao ko samjho!☺️☺️
@@arvindpanchal2721 then give him a Nobel for Education XD
Done
He is not alive 😭
Program for prefix evaluation
#include
#include
#include
using namespace std;
bool isOperand(char C)
{
if(C>='0' && C
@Maha- You can check the description for link to source code. Pasting it here too: gist.github.com/mycodeschool/7702441
mycodeschool it would be better if you post the prefix evaluation source code too sir!!
You helped a lot of students achieving their goals. You deserve huge respect. Indeed.
sir i want to hug you.i watched this video and now i am certain that i will perform better in my exam
xD
but really. He's got the best lectures of DS with crystal clear explanations.
holy
@NOTyoutuber no u
gay.
Great work sir
10:48 shouldn't it be 9 - 26 which would be -17? I don't understand which operand is the leader when it comes to subtraction.
thank you sir for such a wonderful ds experience i am seriously obliged thanks
OMG thank you so much! you explained it much better than my college teacher! Thanks for sharing this valuable information with us for free! thanks a lot!
Where u study
This was very helpful. You have my thanks, good sir.
alright, please add one more thank you to your list. And sir i can't express what kind of respect you owe in every students heart.
You saved me again, I have exam coming up where I have to evaluate these.
Nice Video but you made a mistake in the video during "prefix" notation. You popped 5 & 4 and you multiplied them even though the symbol was + addition.
printing mistake dear...
By the way answer should for the prefix be 6. If I am wrong please correct me.
You are awesome sir,
You taught me the whole postfix and prefix concept in just 14 minutes including algorithm.
Thank you sir
Code for prefix evaluation
#include
#include
#include
using namespace std;
// Function to evaluate Porefix expression and return output
int EvaluatePrefix(string expression);
// Function to perform an operation and return output.
int PerformOperation(char operation, int operand1, int operand2);
// Function to verify whether a character is operator symbol or not.
bool IsOperator(char C);
// Function to verify whether a character is numeric digit.
bool IsNumericDigit(char C);
int main()
{
string expression;
cout
Great video! How do we evaluate prefix/postfix expressions in case of *unary operators* ?
in case of prefix the operand immediately succeeding the unary operator.
and in case of postfix.
the operand immediately preceding the unary operator.
Your videos help a lot in building the logic !! Thanks a lot!!
This is so well done. Thank you so much for creating these videos.
sweet and simple...u make concepts looks so simple..Thanks a lot :)
In evaluation of prefix exp, atlast... If d operator comes, u hav two pop two elements...n here 2nd element is the 2nd operand.. So d final ans should be like -17 right???
Sir can you please tell how to convert complex expressions into postfix, for ex :- in my book a question is given i.e
A*(B+D)/E-F-(G+H/K) and (A+ B ^ D)/(E-F)+G (^ IS NOT POWER). Please help!!
hello i have 7 account to sub to your channel if u like but please solve some questions i have like 5. please👍👍👍👍👍👍
i didnt unerstand it
awesome ! so clear and understanding, thank you so much! the book for computer architecture just makes no sense. your videos are getting me through this class !
Hi guys. I have a technical interview at my dream company in 5 days. Pray for me please.
INTEGER STACK USED FOR POSTFIX ND PREFIX EXPRESSION EVALUATION
public class IntStack {
private int[] stack;
private int top;
private int size;
public IntStack() {
this.stack = new int[10];
this.top = -1;
this.size = 10;
}
public IntStack(int size) {
this.top = -1;
this.size = size;
this.stack = new int[this.size];
}
public boolean push(int item) {
if(!isFull()){
top++;
stack[top]= item;
return true;
}
else
System.out.println("Stack is full");
return false;
}
public boolean isFull() {
if(top== stack.length-1) {
return true;
}
else
return false;
}
public int pop() {
if(!isEmpty()) {
int value = stack[top];
top--;
return value;
}
else
return -1;
}
public boolean isEmpty() {
if (top == -1) {
System.out.println("Stack is empty");
return true;
}
else
return false;
}
}
Sir,what is the need of writing s[i] - '0' in the call for push function in if block inside for loop in cal function.
please help...
#include
struct Stack
{
int top;
int cap;
int*A;
};
struct Stack* create(int n)
{
struct Stack* stack;
stack->top=-1;
stack->cap=n;
stack->A=(int*)malloc(n*sizeof(int));
return stack;
}
main()
{
char s[100];
printf("Enter a postfix expression-");
scanf("%s",s);
printf("The value is %d.",cal(s));
}
void push(struct Stack* stack,char a)
{
stack->A[++stack->top]=a;
}
char pop(struct Stack*stack)
{
return stack->A[stack->top--];
}
int cal(char *s)
{
int n=strlen(s),i,p1,p2;
struct Stack*stack=create(n);
for(i=0;i
Prefix expression evaluation source code in C++ :
github.com/tridibsamanta/Data-Structures-and-Algorithms/blob/master/DS/PrefixEvaluation_Stack.cpp
Postfix expression evaluation source code in C++ :
github.com/tridibsamanta/Data-Structures-and-Algorithms/blob/master/DS/PostfixEvaluation_Stack.cpp
Sir, you are the best. If you thought in a University, I would totally go there.
You are an amazing teacher. Keep up the amazing work!
for the prefix example, could you not write it as: - 9 + * 5 4 * 2 3
this gives me the same final answer of 17
I have tried 3 days to solve this question but i can't why it is showing null value
on evaluation of postfix, which one did u pop first? 26 or 9, since OP1 should be 9 because it is the first one to pop and OP2 is 26 (following LIFO), please clarify
9 was the first to pop and then 26 was popped. The way he has programmed, op2 holds the value of the element which was popped first and op1 holds the value of the element popped later. You can interchange what op1 and op2 mean when you write your own code.
I also got confused first but look 9 pops out first as op2 and then 26 pops out as op1. Now perform the operation op1- op2 that is 26- 9. I hope that makes sense.
Really thanks a lot sir
Thank you! an awesomely detailed explanation, and the visualization was very informative too!
answer may me -17 because last last stage 9,26 are in the stack so 9-26=-17
Python implementation of postfix expression evaluation.
Note: Parses single-digit numbers only. You may implement your preferred parser for input.
#Stack class implementation
class stack():
def __init__(self):
self.headNode = None
def trav(self):
if(self.headNode):
checkNode = self.headNode
print checkNode.data
while checkNode.next:
next = checkNode.next
print next.data
checkNode = next
def push(self,val):
NN = Node(val)
NN.next = self.headNode
self.headNode = NN
def pop(self):
if(not self.headNode):
return None
CNode = self.headNode
self.headNode = self.headNode.next
return CNode
def not_emp(self):
if(self.headNode!=None):
return True
return False
def top(self):
return self.headNode
#import operator module to match operator characters with Arithmetic functions
import operator
def postfix_eval(exp):
#operator dictionary, pairing characters with arithmetic functions
operators = {"+":operator.add,"-":operator.sub,"*":operator.mul,"/":operator.div}
exp_stack = stack()
for i in exp:
#if not operator, i.e if operand, add to top of stack
if(not i in operators):
exp_stack.push(i)
else:
#if character operator, pop last two top elements in stack, be mindful of the order
operand2 = int(exp_stack.pop().data)
operand1 = int(exp_stack.pop().data)
#call arithmetic operator with character as key in operators dictionary, and pass the last two popped elements as parameters
result = operators[i](operand1,operand2)
exp_stack.push(result)
#when all done, return top(only) element left in stack
return exp_stack.pop().data
Awesome 🔥🌟🌟🌟🌟🌟
For prefix evaluation-
#include
#include
#include
#include
#define MAX 100
char a[MAX];
int top=-1;
void push(int s){
top++;
a[top]=s;
}
int pop()
{
int item;
item=a[top];
top--;
return item;
}
int perform(char c,int op1,int op2){
int z;
if(c=='+'){
z=op1+op2;
}
else if(c=='-'){
z=op1-op2;
}
else if(c=='*'){
z=op1*op2;
}
else if(c=='-'){
z=op1/op2;
}
return z;
}
int Top(){
return a[top];
}
void evaluatepostfix(char c[]){
int n=strlen(c);
int i=n;
int op1,op2,val;
char ch;
while(i--){
ch=c[i];
//printf("%c ",ch);
if(isdigit(ch)){
push(ch-'0');
}
else if(ch=='*' || ch=='/' || ch=='+' || ch=='-'){
op2=pop();
op1=pop();
val=perform(c[i],op2,op1);
push(val);
}
}
printf("%d
",pop());
}
int main()
{
char c[100];
printf("Enter string: ");
gets(c);
evaluatepostfix(c);
return 0;
}
A small correction in your code....
In else if(IsNumericDigit(expression[i]))
don't do int operand = 0;
Remove this line otherwise every time the control enters this else if statement it will assign the index of the string to 0 and start reading from the very beginning of the string.
why at the subtraction you place 26 as operand 1 instead of 9? isn't supposed to pop the topmost elements of the stack? 9 is the topmost and must pop out first then 26 so you will have 9-26, I'm confused.
You did absolutely wrong while evaluating prefix expression. You have considered '+' as '*' by mistake. So kindly correct it sir.
Can any one tell me the evaluation of postfix of 5 6 3 - + 10 5 - 12 2 -8 + /
I think it is not a valid postfix expression, my friend.
what if value of operand matches with ASCII value of operator or its value crosses 255.can anyone explain..
thank sir.. this is best video for post-fix which i met
why the hell in this world u started c++ codes it's not at all helping and more confusing no doubt the lecture is amazing but can u please provides the c based code
4:01 there is a mistake. The stack is 26 9 - at the end. It should be popped as 9 - 26 = -17 but it is popped as 26 - 9 = 17. Am I right?
in 13:16 , it was addition(+) but you multiplied however multiplication has not reached ! why ?
If we have single digit and there is +and - what we have to do next😅
hello sir, will u pls convert it into postfix n prefix eq is ( A - (B / C + ( D % E * F) / G) * H )
what if i want to write an expression without spaces or comas? 2+3*4-5? i get a error, i dont know why
in the pseudo code, why do we subtract a '0' from expression[i] while trying to get the value of the numerical digits? line 64.
Evaluate the following prefix expression " ++ 26 + - 1324" sir can u plz explain
thank u for this amazing video. u r doing a great job!!
ur method is too complicated atleast tell it in a easy manner -_-
Beautiful tutorial. Very good English. You saved me so much time.
The prefix expression -+*23+549 is evaluating to 6, not 17... I even checked on online prefix analyzers. Correct me if I am wrong,
Edit: Please ignore this, the actual expression is -+*23*549.
Well after 23 it's the multiplication operator and not '+'.
@@manistrikes Ohh god... and I was frustrated over why my answer is not 17 🤦🤦🤦
Amazing, thank you so much, for this kind of video. God bless you sir.
Sir your teaching speed is as perfect as it can be.
tried running the code as it is from gist.github.com/mycodeschool/7702441 and input as 23*54*+9-,
The code it failing at runtime with BAD_ACCESS error AT while loop in EvaluatePostfix function
and is prefix code available too?
Also sir, would you please explain why do we need to reverse the expression for prefix evaluation?
Thanks
its not 23 its 2,3 or 23 so you have to write extra line if(exp[i]==' '){ continue};
What a voice you got!!What an exaplanation skillsyou got!!
Loved it
dude this is the best video i've ever watched, i totally understood everything, you are really good at teaching.
if statement is that ( a=b=x=y=0) so what we do in postfix and prefix?
omg his voice doesn't annoy me at all :D Im sure it'll be great video
getting answer 9 from your source code.
Awesome explanation ❤️.
Thank you sir 🤩🤩✨.
great teaching, i hate this concept though sheesh
What code should i write to evaluate the expression from right ?
Great Explanation👍🏻👍🏻👍🏻👍🏻
awesome. Very clear explanation sir.Understood it totally
Hi,
Your explanation skills are way greater than any of the youtuber with data-structure videos. I recommend your channel to each of my colleagues whose base seem unclear in data-structures. You have did a great job.
I have one query in this lesson.
How can we convert an infix expression to pre/postfix expression, which contains an unary operator in it? Please edit your video with this content or please make a separate video for this.
Thanks in advance.
Nice Explanation, Thanks a lot
Good explanation sir... Thank you so muchhh
Thank you very much it was very helpful .
This is a very crystal clear explanation. Thank you for the video sir.
Can anyone please tell me what is the problem with this code? Considering we are giving single digit value.
#include
#include
#define MAX_SIZE 20
int top = -1;
int stack[MAX_SIZE];
void push(int val)
{
stack[++top] = val;
}
int pop()
{
return stack[top--];
}
int isEmpty()
{
if(top == -1)
return 1;
else
return 0;
}
int isDigit(char x)
{
if(x >= '0' && x
ok 1_ strlen() need the string.h library
2_ this '^' operator in c is a bitwise operator non for the power of a number if you want to calculate the power of a number you can include the math.h library and use pow(x,y)
3_ atoi() takes a pointer as a parameter so instead of atoi(expression[i]) you should write atoi(expression + i)
@@davidevaccaro3760 thanks but
1. strlen() works just fine even without #include
2. atoi(expression [i]) was working fine too
The problem I was facing was for input as 153, pow(1,3) was giving output 0, I don't know why
@@soumyajitdey5720 input 153? anyway your code work with postfix operation and you shuld give the input with a space like 1 3^
I'm so sorry 😆 I thought I was talking about Armstrong number, that was another issue. Thanks mate will rectify the errors now
Dear Sir,
I Could not find solution this infix solution evaluation
+*2+/14251
any idea?
Please advise
Thanks
Anes
are the numbers single digit?
It will be really good if you can explain Time and space complexity too with your videos.
Nte Siree, oru sambavam thane
Thank you so much for your video
You gave strength to my self taught programming journey
thanks, very helpful
can i have the codes in java? glad if u help me :)))
Best version of explanation
Saved my semester. Thanks
too OP man... You are the best teacher on the planet
fab u all did a fab job awesome explanations this has become one of my fav site and videos
thanks and keep it up u guys
You are absolutely genius
truly a godly video my dude
how we do evalution of infix notation??
Thanks a lot and RIP.
I heard he is no more, but he left such good videos, he lives with us as long as these videos help people like us.
He is alive. His partner and cofounder of mycodeschool is no more. You can google for "humblefool"
amazing..thanku sooo muchh... understood like never before
yeah ..absolutely So, what r u doing these days . job or studying
@@AmrendraKumar-ko8yf are chacha......kaahe itna...thoda sabr karo
Miss you man ............!!!!!
best video on the internet
thank you so much kumar.
For prefix can we reverse the string and then apply postfix operation ?
SARVESH KAUSHIK nope i dont think so
both are differnet expressions on reversal
but algo is nearly same ....just traversal is from last and operation...
thanks a lot for so much easy method .....GOD bless you man
come back mycodeschool
You are a good teacher