Interview Problem: How to Build A Segment Tree?

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • Get COURSES For FREE Using This Scholarship Test. Register Here Now: www.codingninj... In this video, you will learn how to build a segment tree.
    0:30 Concept behind building a segment tree.
    2:26 Elements required to build a segment tree.
    5:39 Code for Building a segment tree.
    14:30 Explanation of output.
    ----------------------------------------------------------------------------------------
    Join our Coding Ninjas official telegram community here: t.me/codingnin...
    ----------------------------------------------------------------------------------------
    Coding Ninjas is one of the leading EdTech company providing India’s Highest rated programming courses in C++, Data Structures and Algorithms, Java, Python, Machine Learning, web development, Data Science, Android Development, Kotlin, React.
    To explore our courses, click here: bit.ly/2WWmdE1
    To explore our Free Trial Courses click here: bit.ly/2YqUL1Y
    -----------------------------------------------------
    To watch more exciting videos on programming, subscribe to our channel here: bit.ly/36n3g08
    ------------------------------------------------------
    Explore more on our social media platforms:
    Facebook: / codingninjas
    Instagram: / coding.ninjas
    Linkedin: / 1319…

КОМЕНТАРІ • 68

  • @CodingNinjasIndia
    @CodingNinjasIndia  3 роки тому

    Join our Coding Ninjas official telegram community here:
    t.me/codingninjas_official

  • @AshishKumar-gl2ur
    @AshishKumar-gl2ur 4 роки тому +2

    The size of the tree array is not always 2*N. It should be calculated by visualizing the number of nodes required in the complete binary tree. eg. h < log(N) < h+1. Then take size of the tree array as pow(2, h + 1). 2*N does not always work.

  • @CodingNinjasIndia
    @CodingNinjasIndia  4 роки тому +1

    Got queries related to segment tree, Let us know in the comments section.
    In this video, you will learn how to build a segment tree.
    0:30 Concept behind building a segment tree.
    2:26 Elements required to build a segment tree.
    5:39 Code for Building a segment tree.
    14:30 Explanation of output.
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    To explore our courses, click here: bit.ly/2WWmdE1
    To explore our Free Trial Courses click here: bit.ly/2YqUL1Y
    -----------------------------------------------------
    To watch more exciting videos on programming, subscribe to our channel here: bit.ly/36n3g08

  • @rahulrawat4265
    @rahulrawat4265 4 роки тому +16

    Nice explanation sir... For zero based indexing, left child is at 2*n+1 and right child is at 2*n+2... Not that it is not possible as you said in video

  • @shobhitsrivastava4496
    @shobhitsrivastava4496 4 роки тому +16

    Good Job, thank you for sharing it for FREE!!

  • @ashishbiswal456
    @ashishbiswal456 4 роки тому +3

    The best explanation one would ever see about segment trees. Thank you sir and coding ninjas .

  • @piyushnaithani7689
    @piyushnaithani7689 5 років тому +11

    Logic completely fails, array is not sufficient to cover the whole, segment tree

  • @adilkhatri7475
    @adilkhatri7475 6 років тому +15

    the code fails when input N = 6
    because 2*6 = 12
    and we are trying to store the value of [3 : 3] to index 12 and [4 : 4] to index 13.

    • @parikh1996
      @parikh1996 6 років тому +3

      Yes you are correct. In this video focus was on the logic behind building a segment tree. How each calling works and all.
      Size of the segment tree was not in focus in this video.

    • @praffulmittal28
      @praffulmittal28 6 років тому

      Yes if size is 6 and input is 1,3, 5,7,9,11
      Then in the output 0 is also coming and also size of tree is not even correct

    • @anmolmittal7320
      @anmolmittal7320 6 років тому +2

      shubhendra singh chauhan do this
      H = ceil(log2(size));
      H = (int)(2*(pow(2, H))-1);
      H is the required size....

    • @vimalpatel6340
      @vimalpatel6340 6 років тому +1

      Mid = pow(2, ceil(log(end-start)/log(2))-1)
      This would work for all sizes.

    • @vikalpbhandari2019
      @vikalpbhandari2019 6 років тому +3

      it will require atmost 4n indices

  • @mukulodd3122
    @mukulodd3122 4 роки тому +2

    Thanks for sharing this video ,it is very well explained but Program will not work for all test cases, Eg:- Consider an array with length 6.

  • @yashvarshney6761
    @yashvarshney6761 3 роки тому

    Thanks @Coding Ninjas. Shared to the CP group.

    • @CodingNinjasIndia
      @CodingNinjasIndia  Рік тому

      Thank you for the kind words! We hope that this video has helped you!
      Stay tuned to Coding Ninjas UA-cam channel for more such content! Do check our Coding Ninjas Studio, where you can upskill for free and become a Ninja Coder: www.codingninjas.com/studio/home?
      If reading is your preference, you can find top articles to upskill in your career here: www.codingninjas.com/studio/library?
      If you would like to opt for a Coding Ninjas course, you can check our courses here: www.codingninjas.com/?

  • @vinaychopra3512
    @vinaychopra3512 4 роки тому +2

    it took me hours to actually find a good explanation ,,,,thank yu so much...:)

  • @unfoldingcode
    @unfoldingcode 4 роки тому

    beautifully explained....Thank you.

  • @shivankgautam9079
    @shivankgautam9079 5 років тому +7

    Finally i understand ST

  • @rahulbhati3079
    @rahulbhati3079 4 роки тому +6

    look if you don't want to upload another video than its ok we have many other coders on you tube how desperately want to teach us. So i believe if you start any topic then it's your responsibility to complete it. plz while teaching put your business mind aside and teach completely what ever you teaching where is video 2???

  • @ashwiniabhishek1504
    @ashwiniabhishek1504 4 роки тому +1

    It will not work for all test cases for example consider [1,2,3,4,5,6]. It will work for the trees which are full of course but also last level nodes are as left as possible. Kindly correct your video. Otherwise the video was good.Nice explanation.

  • @MrAbhitv
    @MrAbhitv 4 роки тому

    Simplest explanation on UA-cam. Thank you so much

  • @p4s153
    @p4s153 4 роки тому +1

    This remember me my jee teachers...hahaha...lil bit annoyingly explained. But at the end any one can understand.

  • @kvinay7536
    @kvinay7536 3 роки тому

    Brilliant!!!

  • @gauravpahuja1114
    @gauravpahuja1114 4 роки тому

    Kya mast samjhata hai ye banda awesome video

  • @AmitSingh-1916
    @AmitSingh-1916 4 роки тому

    Does coding ninjas provide how to set up coding environment in sublime text or editor in competitive programming course?

  • @Igloo11
    @Igloo11 3 роки тому

    Amazing explanation!! Subscribed.

  • @bhavyapandey
    @bhavyapandey 4 роки тому

    Thank you so much bhaiya!! online Articles padhke nahi samajh a raha tha. Ab aa gaya, subscribed the channel after seeing this video!

  • @badassopenpolling
    @badassopenpolling Рік тому

    You have not kept whose range is the THIS node sum !!
    and where are the next vedios Update and Query ??? forgot ?

  • @puneetg788
    @puneetg788 6 років тому +1

    awesome tutorial. Good work bro. thanks.

  • @prashantchawdhary9727
    @prashantchawdhary9727 3 роки тому

    Best explanation , Thank you

  • @aj9706
    @aj9706 4 роки тому

    Superb Explanation..

  • @kvinay7536
    @kvinay7536 3 роки тому +1

    Please add the update part. It will be very helpful. Thanks in advance.

    • @CodingNinjasIndia
      @CodingNinjasIndia  Рік тому

      Thank you for the kind words! We hope that this video has helped you!
      Stay tuned to Coding Ninjas UA-cam channel for more such content! Do check our Coding Ninjas Studio, where you can upskill for free and become a Ninja Coder: www.codingninjas.com/studio/home?
      If reading is your preference, you can find top articles to upskill in your career here: www.codingninjas.com/studio/library?
      If you would like to opt for a Coding Ninjas course, you can check our courses here: www.codingninjas.com/?

  • @shaleenbansal5107
    @shaleenbansal5107 4 роки тому

    Great job!!

  • @Ritikjain9211
    @Ritikjain9211 4 роки тому

    very nice and interacting

  • @VishalKumar-kr9me
    @VishalKumar-kr9me 4 роки тому

    Why this code is not workng for this array {2,6,1,4,7,8}
    ?

  • @saravana6882
    @saravana6882 4 роки тому

    Is this competitive career track program course available in English lectures

  • @akaraze749
    @akaraze749 4 роки тому

    I think this segment tree wont work for array of size above 9

  • @ryndm
    @ryndm 4 роки тому

    thanks bro!!

  • @RahulSingh-ex2sm
    @RahulSingh-ex2sm 6 років тому

    VERY NICE EXPLANATION!!

  • @RAJPATEL-nm9nz
    @RAJPATEL-nm9nz 4 роки тому

    It is wrong implementation, this recursive implementation requires twice the next power of 2,there is one iterative implementation on codeforces which takes 2*n size.

  • @adityamorankar9930
    @adityamorankar9930 4 роки тому

    thanks a lot

  • @JaskaranSingh-hp3zy
    @JaskaranSingh-hp3zy 6 років тому

    Awesome!

  • @gauravkumarpandit7022
    @gauravkumarpandit7022 4 роки тому

    are root toh dikh hi nahi raha or kya garantee hai ki yeh tree fruit de ga

  • @rishikeshkumarsingh3283
    @rishikeshkumarsingh3283 4 роки тому

    where is the next part please upload

  • @ananysharma6879
    @ananysharma6879 6 років тому

    i would like to learn updating and complete query problemfrom you

    • @CodingNinjasIndia
      @CodingNinjasIndia  6 років тому

      Anany Sharma hey, you can drop us mail at contact@codingninjas.in or call us at toll free: 1800-300-28085

  • @MohitGupta-sh9hs
    @MohitGupta-sh9hs 4 роки тому

    Sir there will be (2*n)-1 nodes for sure but the index can be greater than (2*n)-1. So the size of tree should be 2*(2^(log2(n))) instead of (2*n)-1.

    • @ayushgarg5929
      @ayushgarg5929 4 роки тому

      Jitti nodes hoti hai wahi size hota hai tree ka

  • @bernardoborges8598
    @bernardoborges8598 4 роки тому

    can someone please add subtitles... i can`t understand hindi...

  • @nikhilkumawat1797
    @nikhilkumawat1797 6 років тому

    Awesome

  • @chip8222
    @chip8222 5 років тому

    Why is the title and description in English when you are speaking some other language?

    • @anitaggarwal7196
      @anitaggarwal7196 5 років тому

      this is an indian coding company bro using indian language

  • @codeguy21
    @codeguy21 4 роки тому +1

    Explain it in English sir !

  • @HimanshuSingh-ob9qo
    @HimanshuSingh-ob9qo 3 роки тому

    👌👌👌👌👌🙏

  • @atulvidyarthi133
    @atulvidyarthi133 4 роки тому

    fails for n=13 for some reason

    • @AshishKumar-gl2ur
      @AshishKumar-gl2ur 3 роки тому

      Probably you need to check the size of the bigger array, it won't be 2*13, try making it a power of 2 next to 26. ie. 32.

  • @jatinjeena7877
    @jatinjeena7877 5 років тому +1

    Wrong implementation

  • @bernardoborges8598
    @bernardoborges8598 4 роки тому

    can someone please add subtitles... i can`t understand hindi...