Segment Tree | Introduction | Basics | Build Segment Tree | Video 1 | codestorywithMIK

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 27. 07. 2024
  • iPad PDF Notes - github.com/MAZHARMIK/Intervie...
    Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 1st video of our playlist "Segment Tree Concepts & Questions". Find the Details below :
    Video Name : Segment Tree | Introduction | Basics | Build Segment Tree | Video 1
    Video # : 1
    🔍 Unraveling Segment Tree : A Journey into the Depths of Code
    đŸŽ„ Welcome to the 1st Video of my Segment Tree Concepts & Questions Playlist! 🚀 In this enlightening video, we dive headfirst into the world of Segment Tree, demystifying its essence and unraveling its secrets. 🌐
    🔍 What's Inside ?
    🔗 Definition: Get ready to grasp the fundamental concept of Segment Tree - What is it ? Why do we need it ? How to build it etc.
    🚀 Why Segment Tree ? Uncover the beauty and power of segment tre in solving complex problems, making your code more elegant and efficient.
    đŸ‘©â€đŸ’» Who Should Watch ?
    This playlist is for everyone but best suited for Freshers who are new to Segment Tree.
    🚀 Embark on the Segment Tree Adventure Now!
    My DP Concepts Playlist : ‱ Roadmap for DP | How t...
    My Graph Concepts Playlist : ‱ Graph Concepts & Qns -...
    My Recursion Concepts Playlist : ‱ Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Summary : In this video, we will see what a segment tree is, why we need it. We will see with a simple example of "Range Sum Query". We will understand the details and
    basics of segment tree. Understand with a complete example dry run. Make the tree diagram and deduce the simple recursive code to build a segment tree.
    ╔═╩╗╔╩╗╔═╩═╩╩╩╩╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    ✹ Timelines✹
    00:00 - Introduction
    0:45 - Whe to use Segment Tree
    5:35 - How to visualise segment Tree
    15:30 - How many nodes in Segment Tree
    25:10 - Code for Segment tree from tree diagram
    37:46 - Complete Dry Run
    49:43 - Time & Space Complexity of Build Segment Tree
    52:46 - What’s Next ???
    #codestorywithMIK
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation
    #segmenttree #segment #rangequeries

Komentáƙe • 95

  • @SatyamYadav-oz5ge
    @SatyamYadav-oz5ge Pƙed měsĂ­cem +26

    ab maza aayega na bidu❀

  • @abhishekrai3
    @abhishekrai3 Pƙed měsĂ­cem +16

    Finally ab to leetcode ke contest ke 4 swal solve honge ab.
    Ab aayega n maza 😃.
    Thank you for the playlist bhaiya.

  • @musaddikkhan9720
    @musaddikkhan9720 Pƙed měsĂ­cem +20

    Bhai Kal Hi Descide kia tha ki segment tree sikhna padega accha resource dhundna hoga nd Allhamdulillah you start this â€đŸ«‚ Thank You So Much 💗

  • @VishalKumar-ru5gz
    @VishalKumar-ru5gz Pƙed měsĂ­cem +8

    One more weapon in the arsenal . Segment Tree . THANK YOU SIR

  • @anubhawprajapati3769
    @anubhawprajapati3769 Pƙed měsĂ­cem +5

    Love you bhai(sir) so much , I was thinking of doing this topic from somewhere and got confused from where but you made my work easy, now I don't have to go anywhere else. Thanks a lot and appreciate your efforts.

  • @nirmalgurjar8181
    @nirmalgurjar8181 Pƙed měsĂ­cem +14

    Thanks

  • @arpitrathore354
    @arpitrathore354 Pƙed měsĂ­cem +6

    By far the most clear segment tree explanation...đŸ”„đŸ”„đŸ”„đŸ”„

  • @tanmoysaha8994
    @tanmoysaha8994 Pƙed měsĂ­cem

    Can't wait more for the second part. Please please upload it soon :')

  • @pratiksharma8632
    @pratiksharma8632 Pƙed měsĂ­cem +1

    goated lecture bhaiya

  • @22gauravkumar70
    @22gauravkumar70 Pƙed měsĂ­cem

    Eid Mubarak !! , Please iss series ko continue kijiye

  • @gui-codes
    @gui-codes Pƙed měsĂ­cem

    so much Respect and love to you mik for hearing to our requests in comments.
    thanks a lot. is video se ye to lag raha ki segment tree easy hai ab. waiting for video 2, thank you so much

  • @roushankumar3532
    @roushankumar3532 Pƙed měsĂ­cem +3

    most waited series for me thanku MIK bhaiya

  • @jeehub041
    @jeehub041 Pƙed měsĂ­cem +9

    Jiska tha humko khub intezaar wo gadhi aa gayi 😅 Thanks sir for this

  • @CodeMode9313
    @CodeMode9313 Pƙed měsĂ­cem

    IMPORTANT!!! bro i was just thinking to start segment tree today and found this awesome video thanks... pls segment tree ka baki videos jaldi laana ASAP

  • @rv5778
    @rv5778 Pƙed měsĂ­cem +5

    Bas aj leetcode last question dekh kr hi socha tha ke ab segment tree sikhna hai.
    And here we go ❀

  • @tusharrajput983
    @tusharrajput983 Pƙed měsĂ­cem +3

    are guruji ye Hui na baat

  • @TusharRaja3009
    @TusharRaja3009 Pƙed měsĂ­cem +9

    14:40 iss property ko i guess bolte hai :- self balancing property/balancing factor/ AVL tree mein padhaya tha ki balancing factor 0 or 1 hi hogi , (Maybe)..Thanks

  • @rudrasharma7496
    @rudrasharma7496 Pƙed měsĂ­cem +3

    Your videos are amazing and helping me so much in understanding the concepts.. Thank you so much❀❀

  • @aws_handles
    @aws_handles Pƙed měsĂ­cem

    Insane teaching skills

  • @pankajkashyap2892
    @pankajkashyap2892 Pƙed měsĂ­cem

    waiting for more videos to come😍😍

  • @anjanasahay2172
    @anjanasahay2172 Pƙed měsĂ­cem +3

    I was already having the intuition that Segment Tree is on the way ❀❀❀

  • @anuppatankar4294
    @anuppatankar4294 Pƙed měsĂ­cem +1

    Great video đŸ‘ŒđŸ»

  • @mukulverma9238
    @mukulverma9238 Pƙed měsĂ­cem +3

    It is finally here! Let's go!

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i Pƙed měsĂ­cem +1

    Thankyou sir!

  • @bhuppidhamii
    @bhuppidhamii Pƙed měsĂ­cem +2

    With MIK all my DSA dar is over.
    Eid Mubarak

  • @AshuAnu-ec9ko
    @AshuAnu-ec9ko Pƙed měsĂ­cem +2

    pls further videos asap

  • @insidious_681
    @insidious_681 Pƙed měsĂ­cem +1

    best explanation sir being beginner i also understood it

    • @shashankvashishtha4454
      @shashankvashishtha4454 Pƙed měsĂ­cem

      Bro, segment tree is not for beginner, you will never be able to use it in any contest.

  • @gauravbanerjee2898
    @gauravbanerjee2898 Pƙed měsĂ­cem +1

    Thank you so much bhaiya ❀❀

  • @akhildonthula6160
    @akhildonthula6160 Pƙed měsĂ­cem +2

    Too much underrated !... hatsoff to u... just do some marketing and u can kill it ! trust me

  • @TusharRaja3009
    @TusharRaja3009 Pƙed měsĂ­cem +1

    Thanks :) Watched complete video ,Will practice tomorrow morning. Please start discussing some LC questions on this topic

  • @pratik.784
    @pratik.784 Pƙed měsĂ­cem +1

    thanks bhaiya

  • @lofireverbz-wy7go
    @lofireverbz-wy7go Pƙed měsĂ­cem +1

    bhaiya maza aagya saare concept clear hogye!!❣❣

  • @riturajprasad3060
    @riturajprasad3060 Pƙed měsĂ­cem

    completed this video.....waiting for next video sir, please upload soon

  • @namangupta-ko7kv
    @namangupta-ko7kv Pƙed měsĂ­cem +4

    Some Questions on segment Tree
    Range Sum Query - Mutable (Medium)
    Modify elements and calculate the sum in a specific range.
    Range Sum Query 2D - Mutable (Hard)
    A 2D version of the range sum query where you need to handle updates and sum calculations in a 2D matrix.
    Count of Smaller Numbers After Self (Hard)
    Count the number of smaller elements to the right of each element in an array.
    The Skyline Problem (Hard)
    Given buildings in the form of (left, right, height), find the skyline formed by these buildings.
    Falling Squares (Hard)
    Given a list of squares that drop onto the x-axis, return the height of the tallest square after each drop.
    Kth Largest Element in an Array (Medium)
    Find the kth largest element in an array, where updates to the array can occur.
    Range Frequency Queries (Medium)
    Handle queries on the frequency of elements within a specific range.

  • @technologicalvivek7510
    @technologicalvivek7510 Pƙed měsĂ­cem +1

    Thank you bhaiya .Ye concept CP ke liye important hai .
    Aapke deep drive lecture se CP me help hogi thanks

  • @prajwalshaw9217
    @prajwalshaw9217 Pƙed měsĂ­cem +2

    Thanks sir. It was much needed. Ajkal ke contest main segment tree bahut zyada aa raha hain.

    • @priyanshkumariitd
      @priyanshkumariitd Pƙed měsĂ­cem

      Haa 4th problem leetcode ke contest ka segment tree ka hii hota h

  • @footballcreativeeverywhere260
    @footballcreativeeverywhere260 Pƙed měsĂ­cem +2

    Eid Mubarak Bhai!!!!!!!!!!!

  • @user-pg2ce9jp6j
    @user-pg2ce9jp6j Pƙed měsĂ­cem +1

    Much needed sir....please do solve some of the famous leetcode seg tree question.....I think it will be very helpful....mostly the 4th question in leetcode contests is seg tree or fenwick tree.....thanks a lot for this❀

  • @lostcyrus8578
    @lostcyrus8578 Pƙed měsĂ­cem +1

    Completely understood the concept. We need more parts of it frequently please❀

  • @souravjoshi2293
    @souravjoshi2293 Pƙed měsĂ­cem

    maza agaya bhai.

  • @arvin2362
    @arvin2362 Pƙed měsĂ­cem +1

    Wowww đŸ„łđŸ„ł

  • @user-ub2is4rs4x
    @user-ub2is4rs4x Pƙed měsĂ­cem

    Yesssss ❀❀❀❀❀
    Finally. Thanks a lot for making the playlist in Parts ❀❀❀

  • @dhairyachauhan6622
    @dhairyachauhan6622 Pƙed měsĂ­cem +1

    Indeed very important.

  • @wearevacationuncoverers
    @wearevacationuncoverers Pƙed měsĂ­cem

    wow

  • @ropurifiedwater
    @ropurifiedwater Pƙed měsĂ­cem +1

    sir dp ka playlist bhi complete kar dijiye ho sake to, aap bohot accha padhate hai

  • @Sumit-wy4zp
    @Sumit-wy4zp Pƙed měsĂ­cem

    finally 4 question se dar nahi lagega😊😊😉

  • @manishkumarprajapati6280
    @manishkumarprajapati6280 Pƙed měsĂ­cem +1

    Too good yaar. Thank you soooo much for this awesome gift ❀❀❀❀ You really are doing a great job. Keep it up sir ji

  • @newglobal2056
    @newglobal2056 Pƙed měsĂ­cem +1

    Thanku ❀

    • @newglobal2056
      @newglobal2056 Pƙed měsĂ­cem +1

      401 and 402 contest ka 4th wala Q's bhi karva dena pls ❀

  • @ugcwithaddi
    @ugcwithaddi Pƙed měsĂ­cem

    Finally 😍
    Bahot ache se samajh agay.
    Waiting for 2nd video

  • @ishika1090
    @ishika1090 Pƙed měsĂ­cem +1

    Bhaiya iske questions CSES problemset se krwana Please . CSES problemset ke solutions kisi ne bhi nhi krwae hue h ache se .. Bas ab aapse hi umeed h .Please jldi se krwa do Placement season start hone wala h next month se

  • @jitesh_khurana
    @jitesh_khurana Pƙed měsĂ­cem

    love you sir❀

  • @EB-ot8uu
    @EB-ot8uu Pƙed měsĂ­cem

    love you sir

  • @shivam875S
    @shivam875S Pƙed měsĂ­cem +1

    understood clearly thanks sir for such a nice explanation

  • @yashpaunikar671
    @yashpaunikar671 Pƙed měsĂ­cem +1

    Yeahhhh❀❀❀

  • @upcoming_Engineer_
    @upcoming_Engineer_ Pƙed měsĂ­cem

    Wow! ❀❀❀ Thank you so much Bhaiya ❀❀❀❀❀

  • @RishabhChatterjee-fg2gz
    @RishabhChatterjee-fg2gz Pƙed měsĂ­cem +1

    Explanation is really awesome 👌

  • @priyanshkumariitd
    @priyanshkumariitd Pƙed měsĂ­cem +1

    Watched the entire video. Thank you bhaiya.

  • @bhaktisharma9681
    @bhaktisharma9681 Pƙed měsĂ­cem +1

    Bhaiya, aap pls contest ke solutions bhi banaya karo na pls.. aap jaisa koi nahi samjha sakta and bahut ache problems hote hain contest main. it would be very very helpful bhaiya. Agar aapko time mile toh pls bana saktein hain?

  • @pulkitsharma2304
    @pulkitsharma2304 Pƙed měsĂ­cem

    thank you bhayia ❀❀❀

  • @22gauravkumar70
    @22gauravkumar70 Pƙed měsĂ­cem +2

    next video lao bhaiyya

  • @kajalhargunani6757
    @kajalhargunani6757 Pƙed 11 dny

    Can you please explain when to use difference array and when to use segment tree? Or any video on difference array.

  • @anjanasahay2172
    @anjanasahay2172 Pƙed měsĂ­cem

    Great Work ❀❀❀❀

  • @tarunpatel1457
    @tarunpatel1457 Pƙed měsĂ­cem

    â€â€đŸ™

  • @riturajprasad3060
    @riturajprasad3060 Pƙed měsĂ­cem

    sir please complete this segment tree first leaving all other dsa series lecture..

  • @Akashkumar_12
    @Akashkumar_12 Pƙed měsĂ­cem

    Bhaiya please complete the graph playlist ❀

  • @VedBrahmbhattBEE
    @VedBrahmbhattBEE Pƙed měsĂ­cem

    Thanks for this informative video sir. One request to you please make a video of Leetcode problem 2910 . Minimum number of groups to create a valid assignment as it's a OA question and I'm not able to understand the solutions

  • @ashish3487
    @ashish3487 Pƙed měsĂ­cem

    Ab bas sir iske other parts me or detailed with question solving leao jaldi se jaldi

  • @karanmehta2890
    @karanmehta2890 Pƙed měsĂ­cem +2

    Build segment tree me problem hai..
    For example: [-28,-39,53,65,11,-56,-65,-39,-43,97]
    Iss array ka segment tree build karo toh aapke hisaab se 10+5+2+1=18 elements hone chahiye but actual me usse jyaada honge
    This is because tree ka harr leaf node same depth pe ho aisa zaruri nahi hai.. which is happening in the above case...
    Since it is a balanced binary tree, height ka difference at max 1 ho sakta hai which is why your GP of N, N/2, N/4 should begin from 2N
    Total nodes => 2N, N, N/2, N/4... 1 = 4N
    So instead of 2N nodes in a segment tree, there should be 4N nodes.

    • @codestorywithMIK
      @codestorywithMIK  Pƙed měsĂ­cem

      I totally agree. I was planning to add this in my next video.
      When the size of the input array
      n is not a power of 2, the segment tree may need more nodes to handle the uneven distribution of elements. Using 4n
      ensures that there is always enough space to build the tree without running into indexing issues. The worst-case size of the segment tree for any array size can be up to 4n due to how the tree is balanced and structured internally.

  • @technologicalvivek7510
    @technologicalvivek7510 Pƙed měsĂ­cem

    Bhaiya time complexity segment tree ki O(log n) hona chahiye na ,kyuki apn toh height wise ja rhe na.

  • @a3rdtierguy864
    @a3rdtierguy864 Pƙed měsĂ­cem +1

    Bhaiya please make solution of leetcode 3186 solution humble request

  • @udaygupta1
    @udaygupta1 Pƙed měsĂ­cem

    can u post the second video today itself??

  • @saranshkasliwal8681
    @saranshkasliwal8681 Pƙed měsĂ­cem

    But generally we take size of segment tree array as 4*n why is that can you explain that?

  • @chitranshjain9714
    @chitranshjain9714 Pƙed měsĂ­cem

    Bhaiya dp ki concept playlist khtm krwa dijiye

  • @SahilGupta-cd8lc
    @SahilGupta-cd8lc Pƙed měsĂ­cem

    next video kb aegi bhai

  • @22gauravkumar70
    @22gauravkumar70 Pƙed měsĂ­cem

    please leetcode 3187 for explaining segment trees

  • @DipakKawale
    @DipakKawale Pƙed měsĂ­cem

    Oye hoye aye haye , moka mile kaddi kaddi

  • @mbm.editzz
    @mbm.editzz Pƙed měsĂ­cem

    pls sir je jldi krado plcaement start hore

  • @queenshijain3089
    @queenshijain3089 Pƙed měsĂ­cem

    Please share the code link

    • @gui-codes
      @gui-codes Pƙed měsĂ­cem

      Here is the code for building segment tree.
      void buildSegmentTree(int i, int l, int r) {
      if (l == r) {
      segmentTreeArray[i] = nums[l];
      return;
      }
      int mid = (l + r) / 2;
      buildSegmentTree(2 * i + 1, l, mid);
      buildSegmentTree(2 * i + 2, mid + 1, r);
      segmentTreeArray[i] = segmentTreeArray[2 * i + 1] + segmentTreeArray[2 * i + 2];
      }

  • @I_amNoob
    @I_amNoob Pƙed měsĂ­cem

    I understood the Segment Tree l but While contruct.
    2*n Size segment Tree is Giving out of range issue.
    4*n Solve the issue, Can you explain more about this?
    Code
    arr=[0,3,3,5,7,6]
    n=len(arr)
    segmentTree=[-1]*(4*n)
    def buildTree(indx,low,high):
    if low==high:
    segmentTree[indx]=arr[low]
    return
    mid=low+(high-low)//2
    buildTree(2*indx+1,low,mid)
    buildTree(2*indx+2,mid+1,high)
    segmentTree[indx]=segmentTree[2*indx+1]+segmentTree[2*indx+2]
    buildTree(0,0,n-1)
    print(segmentTree)

  • @abhinavnarang4369
    @abhinavnarang4369 Pƙed měsĂ­cem

    Video jaldi jaldi laana is playlist ki bhai. Great content

  • @RishabhChatterjee-fg2gz
    @RishabhChatterjee-fg2gz Pƙed měsĂ­cem

    Notes de do mik bhai

    • @gui-codes
      @gui-codes Pƙed měsĂ­cem +1

      description me link hai iPad pdf notes karke jo likha hai. It was not opening yesterday, now it's opening.

  • @Lucifer0872
    @Lucifer0872 Pƙed měsĂ­cem +1

    dp ka khatam kijiye please

  • @rev_krakken70
    @rev_krakken70 Pƙed měsĂ­cem

    Thanks