0:00 Introduction and brief explanation of post,pre and infix 4:50 Infix to postfix 16:39 Infix to prefix 27:51 postfix to infix 35:28 prefix to infix 39:58 postfix to prefix 45:07 prefix to postfix
For all the people having confusion on 19:02 and pseudocode from 24:50, yes there was slight mistake in what he actual said but overall the code is correct and works perfectly fine, In case of reference you can also check (ua-cam.com/video/8QxlrRws9OI/v-deo.html) just a slight difference in that video where '(' and ')' is not interchanged but rest is cool and also you can your logic taught by striver to check if answer is correct or not and yes it will match.
49:52 Striver does not miss a thing! I thought of the same thing while watching the video because the whole concept of infix-prefix-postfix is based on remembering things. But it might come in college academic exams to write the code for any of these conversions.
we dont need to mug up this, there is simple logic behind this for infix to postfix , infix to prefix we need to learn it but for postfix to any (eg--> ab+) prefix to any (eg--> +ab) we try to move in the direction from where we get the both the operands before their operator , this helps us to move the operator where-ever we want like, to the start (+ab) for prefix (ab+) for postfix and (a+b) for infix example->postfix to prefix (ab+ to +ab) we move from front in postfix to put all operand in stack , then if we get an operand we pick up last 2 ele from stack put paranthesis and operator and put to stack top (ex-- operator top 2 top1) then at last return top example->prefix to infix (+ab to a+b) we move from back in the infix to get all operands push to stack, then if we get an operand we pick last 2 ele from stack put in paranthesis and operator ex-(top1 operator top2) then at last return stack top only thing is to remember here is for infix to postfix or infix to prefix and in above case what to push like first (top1 operator top2 ) or (top2 operator top1 ) for this we can use common sense
In the Infix to prefix problem, while evaluating the postfix of the modified input exp, To maintain right associativity of ^ operator: If the incoming character is ^ and the stack top is also ^, you should push the incoming ^ to the stack. If the incoming character is ^ and the stack top has an operator with greater precedence (which, in this context, there isn't any, as ^ has the highest precedence), you should pop the stack. But according to striver's code, @25:32, if the input is ^ and stack top is either ^ or something with greater priority... in both cases we are popping. Correct me if I'm wrong somewhere.
Infix to postfix class Solution { // Function to convert an infix expression to a postfix expression. static int precedance(Character c){ switch(c){ case '+': case '-': return 1;
case '*': case '/': return 2;
case '^': return 3; } return -1; } public static String infixToPostfix(String exp) { // Your code here String ans=""; Stack st = new Stack();
for(int i=0;i=0){ char ch = pre_exp.charAt(i); if(Character.isLetterOrDigit(ch)){ st.push(Character.toString(ch)); } else{ String t1 = st.peek(); st.pop(); String t2 = st.peek(); st.pop(); String str = t1+t2+ch; st.push(str); } i--; } return st.peek(); } } Postfix to Prefix class Solution { static String postToPre(String post_exp) { // code here Stack st = new Stack(); int i=0; int n = post_exp.length(); while(i
bhai pehle ke sare videos samajh me aate the is video me kuch samaj nhi aaya bas you told ki ye karna hai ye karna hai and nothing about kyu karna hai dissapointed
Bro i can understand easily after seeing your videos but when i am solving question for first time i am not able to do please give some advice or tips. Please striver bhaiya reply. By the way i love ur way of teaching❤
no one can able to solve first time if they didn't came across similar kind of logic previously. If some one solved in the first time we call him scientist, so don't take stress, try first at least for brute force if not, then watch video practice and come back after 15 days, and try to solve.
a lame question but how am I gonna know the operations to perform to convert them if asked in an interview? Like do i have to remember each of them since approach to every conversion is different.
In postfix to infix problem idk why string ans = "(" + top2 + c+ top1+ ")"; st.push(ans); did not work but st.push("(" + top2 + c+ top1+ ")"); worked can anyone explain ?
In Infix to prefix converter I tried to convert (A+B)*C-D+F^Z^s to prefix and got + - * + A B C D ^ ^ F Z s (in 2 different converter sites). However, according to striver's code I am getting +-*+ABCD^F^Zs. meaning I can't find the exception for ^ anywhere. I can't understand which one to follow.
For all the people having confusion on 19:02 and pseudocode from 24:50, yes there was slight mistake in what he actual said but overall the code is correct and works perfectly fine, In case of reference you can also check (ua-cam.com/video/8QxlrRws9OI/v-deo.html) just a slight difference in that video where '(' and ')' is not interchanged but rest is cool and also you can your logic taught by striver to check if answer is correct or not and yes it will match.
TLE in GFG in last test case string postToInfix(string exp) { // Write your code here int i=0; stack st; while(i='a' && exp[i]='A' && exp[i]='0' && exp[i]
Yes, you can even be asked to implement a stack using array during the interview. Although the technical round may not consist of such questions but the interviewer may still ask to test your understanding.
At timestamp 12:20 and 13:12 it should be not operator !st.empty() in while condition
exactly
that was what i was thinking, thanks
0:00 Introduction and brief explanation of post,pre and infix
4:50 Infix to postfix
16:39 Infix to prefix
27:51 postfix to infix
35:28 prefix to infix
39:58 postfix to prefix
45:07 prefix to postfix
thanu
Thankyou 🤎
thanks
At 25:53 it would be st.push instead of st.pop
For all the people having confusion on 19:02 and pseudocode from 24:50, yes there was slight mistake in what he actual said but overall the code is correct and works perfectly fine, In case of reference you can also check (ua-cam.com/video/8QxlrRws9OI/v-deo.html) just a slight difference in that video where '(' and ')' is not interchanged but rest is cool and also you can your logic taught by striver to check if answer is correct or not and yes it will match.
49:52
Striver does not miss a thing! I thought of the same thing while watching the video because the whole concept of infix-prefix-postfix is based on remembering things. But it might come in college academic exams to write the code for any of these conversions.
we dont need to mug up this, there is simple logic behind this
for infix to postfix , infix to prefix we need to learn it
but for
postfix to any (eg--> ab+)
prefix to any (eg--> +ab)
we try to move in the direction from where we get the both the operands before their operator ,
this helps us to move the operator where-ever we want like, to the start (+ab) for prefix
(ab+) for postfix and (a+b) for infix
example->postfix to prefix (ab+ to +ab)
we move from front in postfix to put all operand in stack , then if we get an operand we pick up last 2 ele from stack put paranthesis and operator and put to stack top (ex-- operator top 2 top1) then at last return top
example->prefix to infix (+ab to a+b)
we move from back in the infix to get all operands push to stack, then if we get an operand we pick last 2 ele from stack put in paranthesis and operator ex-(top1 operator top2) then at last return stack top
only thing is to remember here is for
infix to postfix or infix to prefix and
in above case what to push like first (top1 operator top2 ) or (top2 operator top1 ) for this we can use common sense
In the Infix to prefix problem, while evaluating the postfix of the modified input exp,
To maintain right associativity of ^ operator:
If the incoming character is ^ and the stack top is also ^, you should push the incoming ^ to the stack.
If the incoming character is ^ and the stack top has an operator with greater precedence (which, in this context, there isn't any, as ^ has the highest precedence), you should pop the stack.
But according to striver's code, @25:32, if the input is ^ and stack top is either ^ or something with greater priority... in both cases we are popping.
Correct me if I'm wrong somewhere.
same doubt he said before only ^ check priority else insert into stack
Do a dry run on a + b ^ c ^ e Right associativity is maintained in striver's code.
yes , you are correct, because ^ has associativity right to left
@@sahilrout2758bro is this playlist the best in UA-cam for DSA as I am following this but have doubt in my mind
@shashank_0807 same doubt
I love you striver you make things very simple ❤
heaps and strings too please...waiting for it from such a long time😭😭
Bro can eat 1000 coding questions in breakfast 🔥🔥🔥
instagramer spotted
@@KedarBhawthankar
@@KedarBhawthankar😂
Real✅
Infix to postfix
class Solution {
// Function to convert an infix expression to a postfix expression.
static int precedance(Character c){
switch(c){
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
case '^':
return 3;
}
return -1;
}
public static String infixToPostfix(String exp) {
// Your code here
String ans="";
Stack st = new Stack();
for(int i=0;i=0){
char ch = pre_exp.charAt(i);
if(Character.isLetterOrDigit(ch)){
st.push(Character.toString(ch));
}
else{
String t1 = st.peek();
st.pop();
String t2 = st.peek();
st.pop();
String str = t1+t2+ch;
st.push(str);
}
i--;
}
return st.peek();
}
}
Postfix to Prefix
class Solution {
static String postToPre(String post_exp) {
// code here
Stack st = new Stack();
int i=0;
int n = post_exp.length();
while(i
So for infix to prefix why we are having condition priority[s[i]]
Strings series please striver
Thanks I was waiting willingly for this
infix to postfix will give segmentation fault inunbalanced paranthesis as st.pop() is outside the condition of checking for !st.empty()
I think we have to check associativity of the operator after checking precedence before pushing in to the stack.
sir while converting from infix to postfix the test condition of while loop should be while(!st.empty() && priority(s[i]
thank you very much sir for helping us... sir please bring strings and heaps playlist also please sir
Reverse the string and convert the ( .
Add var to ans , if operator just add in stack
Reverse ans
In infix to postfix he maintains left associativity of ^ by using priority(s[i])
At 12:45 it should be !st.empty() instead of st.empty()
Great content, sir.
amazing lecture so far...!
at 10:48 it should be a and last for small z for second case
Little confusing Infix to Prefix conversion but the rest is crystal clear
Thank you striver .
STRIVER ❤🔥
Thank youu sir, love the way you teach
Striver is back ❤
GOAT is back
Thank You sir
A O(n/2) which u apply your brains😂 at 26:55
@striver Can you plz add notes as well for this video in your website in notes section
Nice explanation.
ye google ke interview mein poocha hai . If anyone out there is thinking to skip this or that mere bhaio mat chodo kuch bhi aa sakta
bhai pehle ke sare videos samajh me aate the is video me kuch samaj nhi aaya bas you told ki ye karna hai ye karna hai and nothing about kyu karna hai dissapointed
Bro i can understand easily after seeing your videos but when i am solving question for first time i am not able to do please give some advice or tips. Please striver bhaiya reply. By the way i love ur way of teaching❤
no one can able to solve first time if they didn't came across similar kind of logic previously. If some one solved in the first time we call him scientist, so don't take stress, try first at least for brute force if not, then watch video practice and come back after 15 days, and try to solve.
strings playlist please striver
Thankyou boss.
will the time complexity for
s is a string of size n
st.push(s) will be O(1) or O(n)?
Hi in infix to prefix pls explain why are you handling ^ separately ?
because ^ associativity is right to left
@@sahilrout2758 so? why then he didnt handled it separately in infix to postfix
thank you so much bhaiya❤❤
Virat kohli of DSA
No hitman
thanks bhaiya 😍
Utkarsh....you can keep those retakes....shows his dedication :)
who is utkarsh
@@KartikeyTT his editor
Understood !
in infix to postfix how does it handles if we encounter + and - or how is associativity of _ and + is checked
a lame question but how am I gonna know the operations to perform to convert them if asked in an interview? Like do i have to remember each of them since approach to every conversion is different.
now way around it
This is best one
Amazing sir
Isko update kardo atz series mey
sir please heap ki playlist laao jaldi se jaldi 🥺
In infix to postfix, where is the condition in the code where if we encounter a simple operator which is to be added to the stack , please answer
Thank you so much sir
a good video
GOAT
prefix to infix is giving TLE, can someone give some hint to optimize
Bhai kl aapne saari upload to ke the phir aaj dubara se Kyo?
In postfix to infix problem idk why string ans = "(" + top2 + c+ top1+ ")";
st.push(ans); did not work but st.push("(" + top2 + c+ top1+ ")"); worked can anyone explain ?
What if the coming operator i.e
S[i] have equal precedence with st.top()?
we had to pop all operators till we get the operator that is having precedence strictly less than that of incoming opt
ie. pri(s[i])>pri(st.top())
UNDERSTOOD;
Understood
Understood :)
Bhai help me na roj kar rahi hu but approach nhi aa raha kya karu mein😔😔
Understood
thanks sir
Thank you😊
STRIVER❤❤❤
In Infix to prefix converter
I tried to convert (A+B)*C-D+F^Z^s to prefix and got + - * + A B C D ^ ^ F Z s (in 2 different converter sites).
However, according to striver's code I am getting +-*+ABCD^F^Zs.
meaning I can't find the exception for ^ anywhere.
I can't understand which one to follow.
For all the people having confusion on 19:02 and pseudocode from 24:50, yes there was slight mistake in what he actual said but overall the code is correct and works perfectly fine, In case of reference you can also check (ua-cam.com/video/8QxlrRws9OI/v-deo.html) just a slight difference in that video where '(' and ')' is not interchanged but rest is cool and also you can your logic taught by striver to check if answer is correct or not and yes it will match.
striver's code is correct because it has maintain the right associativity ^ operator
Is this playlist of striver for dsa the best in utube as I am following this but have doubt in my mind plz give guidance anyone
yes for sure also practice leet code's daily contest
thumbnail different
Understood!!
TLE in GFG in last test case
string postToInfix(string exp) {
// Write your code here
int i=0;
stack st;
while(i='a' && exp[i]='A' && exp[i]='0' && exp[i]
st.push("(" + s2 + exp[i] + s1 + ")"); this will work
is video ka 6 alag video rehta to zyada shi rehta
understood
Are u teaching data structure in c or java
Striver teaches only pseudocode!!
Another approach for postfix to infix conversion:
const isOperator = (char) => {
return ['+', '-', '*', '/', '^'].includes(char);
};
class Solution{
postToInfix(postfix)
{
const stack = [];
for (let i = 0; i < postfix.length; i++) {
const char = postfix[i];
if (isOperator(char)) {
// Pop operands from stack
const operand2 = stack.pop();
const operand1 = stack.pop();
// Create infix expression and push it back to stack
stack.push(`(${operand1}${char}${operand2})`);
} else {
// Operand (variable or number), push to stack
stack.push(char);
}
}
}
❤
Do you really think Prefix, Postfix and Infix will be asked in a technical Interview ?
same doubt
Yes, you can even be asked to implement a stack using array during the interview. Although the technical round may not consist of such questions but the interviewer may still ask to test your understanding.
❤❤❤
7:30
16:45
Lego lego
First
Video quality is not good. Very blurry
What a legend man,
Striver 🫡
understood
Understood
First
Understood