L3. Prefix, Infix, and Postfix Conversion | Stack and Queue Playlist

Поділитися
Вставка
  • Опубліковано 14 лис 2024

КОМЕНТАРІ • 123

  • @lingasaikiran2401
    @lingasaikiran2401 4 місяці тому +118

    At timestamp 12:20 and 13:12 it should be not operator !st.empty() in while condition

  • @sandhyaranijam2924
    @sandhyaranijam2924 3 місяці тому +53

    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

  • @AdityaRaj-wu2vg
    @AdityaRaj-wu2vg 2 місяці тому +19

    At 25:53 it would be st.push instead of st.pop

  • @atharvaraut8683
    @atharvaraut8683 3 місяці тому +10

    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.

  • @dhrroovv
    @dhrroovv 3 місяці тому +9

    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.

  • @Kshitijsingh-n7f
    @Kshitijsingh-n7f 2 місяці тому +5

    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

  • @shashank_0807
    @shashank_0807 3 місяці тому +9

    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.

    • @SurajKumar-ku1lg
      @SurajKumar-ku1lg 3 місяці тому

      same doubt he said before only ^ check priority else insert into stack

    • @valendradangi1822
      @valendradangi1822 3 місяці тому

      Do a dry run on a + b ^ c ^ e Right associativity is maintained in striver's code.

    • @sahilrout2758
      @sahilrout2758 2 місяці тому

      yes , you are correct, because ^ has associativity right to left

    • @11a-shivamsinghrawat33
      @11a-shivamsinghrawat33 2 місяці тому

      ​@@sahilrout2758bro is this playlist the best in UA-cam for DSA as I am following this but have doubt in my mind

    • @pBERA0_0
      @pBERA0_0 16 днів тому

      @shashank_0807 same doubt

  • @uchihaitachi5376
    @uchihaitachi5376 10 днів тому

    I love you striver you make things very simple ❤

  • @mansidubey3031
    @mansidubey3031 4 місяці тому +22

    heaps and strings too please...waiting for it from such a long time😭😭

  • @SagarGhate-o7n
    @SagarGhate-o7n 3 місяці тому +72

    Bro can eat 1000 coding questions in breakfast 🔥🔥🔥

  • @radhepatel6876
    @radhepatel6876 3 місяці тому +9

    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

    • @VarshaSingh-hi2sb
      @VarshaSingh-hi2sb 2 місяці тому

      So for infix to prefix why we are having condition priority[s[i]]

  • @bhuvaneswarjakka
    @bhuvaneswarjakka 4 місяці тому +16

    Strings series please striver

  • @deepanshudahiya8966
    @deepanshudahiya8966 4 місяці тому +4

    Thanks I was waiting willingly for this

  • @kushjain1986
    @kushjain1986 3 місяці тому +1

    infix to postfix will give segmentation fault inunbalanced paranthesis as st.pop() is outside the condition of checking for !st.empty()

  • @Chinniveeravalli
    @Chinniveeravalli 3 місяці тому +2

    I think we have to check associativity of the operator after checking precedence before pushing in to the stack.

  • @shreyasrk6465
    @shreyasrk6465 3 місяці тому +5

    sir while converting from infix to postfix the test condition of while loop should be while(!st.empty() && priority(s[i]

  • @234shrutigupta9
    @234shrutigupta9 4 місяці тому +2

    thank you very much sir for helping us... sir please bring strings and heaps playlist also please sir

  • @kidoo1567
    @kidoo1567 18 годин тому

    Reverse the string and convert the ( .
    Add var to ans , if operator just add in stack
    Reverse ans

  • @valendradangi1822
    @valendradangi1822 3 місяці тому +5

    In infix to postfix he maintains left associativity of ^ by using priority(s[i])

  • @darkwarrior6767
    @darkwarrior6767 2 місяці тому +1

    At 12:45 it should be !st.empty() instead of st.empty()

  • @mittal_aaditya
    @mittal_aaditya Місяць тому

    Great content, sir.

  • @lucifersamrat6280
    @lucifersamrat6280 3 місяці тому

    amazing lecture so far...!

  • @RAVIKUMAR-ue4ot
    @RAVIKUMAR-ue4ot Місяць тому

    at 10:48 it should be a and last for small z for second case

  • @aryasharma69
    @aryasharma69 Місяць тому

    Little confusing Infix to Prefix conversion but the rest is crystal clear

  • @apmotivationakashparmar722
    @apmotivationakashparmar722 2 місяці тому

    Thank you striver .

  • @chirag71269
    @chirag71269 27 днів тому +1

    STRIVER ❤‍🔥

  • @arushahabib5673
    @arushahabib5673 4 місяці тому

    Thank youu sir, love the way you teach

  • @ayaaniqbal3531
    @ayaaniqbal3531 4 місяці тому +1

    Striver is back ❤

  • @simanraj8278
    @simanraj8278 4 місяці тому

    GOAT is back

  • @shalinikumari6050
    @shalinikumari6050 13 днів тому

    Thank You sir

  • @raaviumasusmitha937
    @raaviumasusmitha937 3 місяці тому +4

    A O(n/2) which u apply your brains😂 at 26:55

  • @daksh203
    @daksh203 Місяць тому

    @striver Can you plz add notes as well for this video in your website in notes section

  • @anddevsahil
    @anddevsahil 2 місяці тому

    Nice explanation.

  • @abhishekshukla5747
    @abhishekshukla5747 2 дні тому

    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

  • @abhishekagrawal3730
    @abhishekagrawal3730 3 місяці тому +6

    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

  • @shetty-m4d
    @shetty-m4d 4 місяці тому

    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❤

    • @sagarhiremath4899
      @sagarhiremath4899 3 місяці тому +2

      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.

  • @kunal5077
    @kunal5077 2 місяці тому

    strings playlist please striver

  • @yoddha621
    @yoddha621 Місяць тому

    Thankyou boss.

  • @BoredToDeath2357
    @BoredToDeath2357 Місяць тому

    will the time complexity for
    s is a string of size n
    st.push(s) will be O(1) or O(n)?

  • @charuprabha8714
    @charuprabha8714 3 місяці тому +2

    Hi in infix to prefix pls explain why are you handling ^ separately ?

    • @sahilrout2758
      @sahilrout2758 2 місяці тому

      because ^ associativity is right to left

    • @pBERA0_0
      @pBERA0_0 15 днів тому

      @@sahilrout2758 so? why then he didnt handled it separately in infix to postfix

  • @kartikverma6412
    @kartikverma6412 4 місяці тому

    thank you so much bhaiya❤❤

  • @AnmolShekhawat-w8m
    @AnmolShekhawat-w8m Місяць тому +2

    Virat kohli of DSA

  • @oyeesharme
    @oyeesharme Місяць тому

    thanks bhaiya 😍

  • @ydtcod3489
    @ydtcod3489 4 місяці тому

    Utkarsh....you can keep those retakes....shows his dedication :)

    • @KartikeyTT
      @KartikeyTT 3 місяці тому

      who is utkarsh

    • @ydtcod3489
      @ydtcod3489 3 місяці тому

      @@KartikeyTT his editor

  • @chirag71269
    @chirag71269 27 днів тому

    Understood !

  • @soothinghumms7019
    @soothinghumms7019 2 місяці тому

    in infix to postfix how does it handles if we encounter + and - or how is associativity of _ and + is checked

  • @hamzarehman7057
    @hamzarehman7057 2 місяці тому +1

    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.

    • @Nishxnt_Y
      @Nishxnt_Y 2 місяці тому

      now way around it

  • @ShubhamGarg-f6w
    @ShubhamGarg-f6w 3 місяці тому

    This is best one

  • @AnushkaGupta-x6w
    @AnushkaGupta-x6w 4 місяці тому

    Amazing sir

  • @abhaykumarsingh3884
    @abhaykumarsingh3884 3 місяці тому

    Isko update kardo atz series mey

  • @KaranSoni-uj4oq
    @KaranSoni-uj4oq 4 місяці тому

    sir please heap ki playlist laao jaldi se jaldi 🥺

  • @FutureForge-ir7xc
    @FutureForge-ir7xc 3 місяці тому

    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

  • @rongalamanindra5279
    @rongalamanindra5279 4 місяці тому

    Thank you so much sir

  • @moneeb-ur-rahman7
    @moneeb-ur-rahman7 16 днів тому

    a good video

  • @somriktapaswi7003
    @somriktapaswi7003 3 місяці тому

    GOAT

  • @Rahul-kw6zf
    @Rahul-kw6zf 2 місяці тому

    prefix to infix is giving TLE, can someone give some hint to optimize

  • @bhavyasharma3500
    @bhavyasharma3500 4 місяці тому

    Bhai kl aapne saari upload to ke the phir aaj dubara se Kyo?

  • @saravananrao2156
    @saravananrao2156 3 місяці тому

    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 ?

  • @NaIbTcIdNGupta
    @NaIbTcIdNGupta 2 місяці тому

    What if the coming operator i.e
    S[i] have equal precedence with st.top()?

    • @thechampiiit
      @thechampiiit 2 місяці тому

      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())

  • @DeadPoolx1712
    @DeadPoolx1712 Місяць тому

    UNDERSTOOD;

  • @SibiRanganathL
    @SibiRanganathL 3 місяці тому +1

    Understood

  • @nayankhuman1043
    @nayankhuman1043 Місяць тому

    Understood :)

  • @komalvaishnav5828
    @komalvaishnav5828 4 місяці тому

    Bhai help me na roj kar rahi hu but approach nhi aa raha kya karu mein😔😔

  • @bappigorain1066
    @bappigorain1066 4 місяці тому +1

    Understood

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 3 місяці тому

    thanks sir

  • @sanikadesai1812
    @sanikadesai1812 4 місяці тому

    Thank you😊

  • @RajNamdev_19
    @RajNamdev_19 4 місяці тому +1

    STRIVER❤❤❤

  • @anupamtiwary4265
    @anupamtiwary4265 3 місяці тому +2

    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.

    • @atharvaraut8683
      @atharvaraut8683 3 місяці тому +1

      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.

    • @sahilrout2758
      @sahilrout2758 2 місяці тому

      striver's code is correct because it has maintain the right associativity ^ operator

  • @11a-shivamsinghrawat33
    @11a-shivamsinghrawat33 2 місяці тому

    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

    • @vedantdange1379
      @vedantdange1379 28 днів тому

      yes for sure also practice leet code's daily contest

  • @_abhinav.gangwar
    @_abhinav.gangwar 4 місяці тому +1

    thumbnail different

  • @sauravfarkade7032
    @sauravfarkade7032 4 місяці тому

    Understood!!

  • @nikhil_squats
    @nikhil_squats 3 місяці тому +1

    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]

    • @nikhil_squats
      @nikhil_squats 3 місяці тому

      st.push("(" + s2 + exp[i] + s1 + ")"); this will work

  • @AkOp-bf9vm
    @AkOp-bf9vm 2 місяці тому

    is video ka 6 alag video rehta to zyada shi rehta

  • @MJBZG
    @MJBZG 3 місяці тому

    understood

  • @ranjuzz123
    @ranjuzz123 3 місяці тому

    Are u teaching data structure in c or java

    • @cyanideyt9579
      @cyanideyt9579 3 місяці тому

      Striver teaches only pseudocode!!

  • @shikha9482
    @shikha9482 3 місяці тому

    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);
    }
    }
    }

  • @sureshalabani1780
    @sureshalabani1780 4 місяці тому

  • @ganesh2887
    @ganesh2887 3 місяці тому +4

    Do you really think Prefix, Postfix and Infix will be asked in a technical Interview ?

    • @subhajitdey135
      @subhajitdey135 3 місяці тому +2

      same doubt

    • @meghnaduttakha6758
      @meghnaduttakha6758 3 місяці тому +2

      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.

  • @vinit_notfound
    @vinit_notfound 4 місяці тому

    ❤❤❤

  • @IBMX65
    @IBMX65 День тому

    7:30

  • @IBMX65
    @IBMX65 Місяць тому

    16:45

  • @aryavinayak4160
    @aryavinayak4160 4 місяці тому

    Lego lego

  • @horizon9370
    @horizon9370 4 місяці тому

    First

  • @chanchalsinghal5973
    @chanchalsinghal5973 3 місяці тому

    Video quality is not good. Very blurry

  • @chiragdusad2015
    @chiragdusad2015 3 місяці тому

    What a legend man,
    Striver 🫡

  • @saurabhnishad9631
    @saurabhnishad9631 3 дні тому

    understood

  • @shaiksoofi3741
    @shaiksoofi3741 2 місяці тому

    Understood

  • @bappigorain1066
    @bappigorain1066 4 місяці тому +1

    First

  • @rutujashelke4208
    @rutujashelke4208 2 місяці тому

    Understood