Segment Tree | Range Sum Query | Story To Code | Video 3
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 3rd video of our playlist "Segment Tree Concepts & Questions". Find the Details below :
Video Name : Segment Tree | Range Sum Query | Story To Code | Video 3
Video # : 3
đ Unraveling Segment Tree : A Journey into the Depths of Code
đ„ Welcome to the 3rd Video of my Segment Tree Concepts & Questions Playlist! đ In this enlightening video, we will see how segment trees help to do Range Sum Query operations efficiently.
đ What's Inside ?
đ We will see how segment trees help to do Range Sum Query operations efficiently.
đ©âđ» 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 how segment trees help to do Range Sum query operations efficiently. We will also see how in the "Range Sum Query" problem, the time complexity is O(log n). We will understand it from the tree diagram and also convert the story to code to write the Query function.
âââŠâââŠââââŠââŠâŠâŠâŠââââ
âââŁâââââŁââŁââŁââŁâââŁââŁ
â âââââââ ââââŁâââââââŁ
âââ©âââ©ââ©ââ©ââ©âââ©ââ©ââ
âš Timelinesâš
00:00 - Introduction
00:40 - Recap
01:31 - Range Sum Query
03:20 - Tree Diagram
12:42 - 3 Cases in Range Sum Query
21:00 - Story To Code
24:55 - Time Complexity
#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
super
Back to Back videos , please finish this segment tree series . As usual mza aaya , Segment tree ka darr khatam
Tysmâ€!! Btw How many videos can we expect in this playlist?
Thankyou SIr!
please upload more videos ,like more questions of segment tree
Sir mere kaafi concepts clear ho gaye...
Lekin sir companies mai shortlist nhi ho paa bss interview tak pauch jaau phir toh bss aapka hii concept bataunga interviewer ko...
Back to Back videos đ, please continue DP concept and questions series đ
guruji bahot bahot thank you aapko
Thanks a lot. When you are free , please upload more on this playlist
Will be forever grateful for all the work you are putting in thank you bhaiya
Loving the segment tree series keep going sir.
maza aaa gaya back to back videos
Thanks a lot bhaiya!!
THanks a lot bhaiya â€â€
Sir ji, Please kuch videos aur laa do na iss playlist pe
waiting for video 4
Thanks a lot â€â€
Thank you
Sir thanks a lot
â€â€â€
Waiting for some problem solving
ye raha bhiaya code.
class SGT {
public:
vector seg;
SGT(int n) {
seg.resize(4 * n);
}
void build(int idx, int l, int r, vector& arr) {
if (l == r) {
seg[idx] = arr[l];
return;
}
int mid = l + (r - l) / 2;
build(2 * idx + 1, l, mid, arr);
build(2 * idx + 2, mid + 1, r, arr);
seg[idx] = seg[2 * idx + 1] + seg[2 * idx + 2];
}
void update(int idx, int val, int i, int l, int r) {
if (l == r) {
seg[i] = val;
return;
}
int mid = l + (r - l) / 2;
(idx end || r < start) return 0;
if (l >= start && r build(0, 0, n - 1, nums);
}
int sumRange(int left, int right) {
return stree->query(left, right, 0, 0, n - 1);
}
~NumArray() {
delete stree;
}
};
/**
* Your NumArray object will be instantiated and called as such:
* NumArray* obj = new NumArray(nums);
* int param_1 = obj->sumRange(left, right);
* obj->update(index, val);
*/
C++ code for this question (Leetcode -- 307)
class NumArray {
int n;
vector input;
vectorsegment;
public:
void buildSegment(int ind , int l , int r){
if(l == r){
segment[ind] = input[l];
return;
}
int mid = (l+r)/2;
buildSegment(2*ind+1 , l , mid);
buildSegment(2*ind+2 , mid+1 , r);
segment[ind] = segment[2*ind+1] + segment[2*ind+2];
}
void updateSegment(int ind , int val , int i , int l , int r){
if(l == r){
segment[i] = val;
return;
}
int mid = (l+r)/2;
if(ind end or r=start and r update(index,val);
* int param_2 = obj->sumRange(left,right);
*/
waiting for fenwick tree
Bhai aage ki videos daalo please..
@mik bhaiya, please keep a resume review video also, when you get time. :)
bhai question krwao abb iss topic ke easy vale
leetcode and codeforces koi bhi chlegga
how to do if the query is sort till the particular index
Kitne video ka series h ye?
nxt video nhi aayi
Sir can you help in this question .
Write a C++ program to insert a new node at the beginning of a Singly Linked List with the values 13 11 9 7 5 3 1 . The node value to be inserted is 0.
Only test case 1 is passing , test case 2, 3 ,4 ,5 gets failed.
Please help me in this.
bhaiya size 2*n me runtime error de rha 4*n shai chal rha kyu?
Same dought
dp finish kijiye bhaiya please
Leetcode 307 solved using above approach with below java code:
class NumArray {
int n = 0;
int[] segmentTree = null;
int[] input = null;
public void builSegmentTree(int i, int l, int r) {
if (l == r) {
segmentTree[i] = input[l]; // l or r
return;
}
int m = (l + r) / 2;
builSegmentTree(2 * i + 1, l, m); // left subtree at 2i + 1
builSegmentTree(2 * i + 2, m + 1, r); // right subtree at 2i + 2
segmentTree[i] = segmentTree[2 * i + 1] + segmentTree[2 * i + 2];
}
public int rangeSum(int i, int l, int r, int s, int e) {
if (e < l || s > r) { // out of range
return 0;
}
if (l >= s && r
bhai code likha kro yar, live code, kal bhi comment kra tha, dont compromise on quality
Hello Abhinav,
Definitely I will write the code.
Actually I was planning to first introduce
1) Build segment tree
2) Update Query
3) Range Query
Now, we are good to go with code.
Next video will be containing the code as well. Thank you â€ïžâ€ïž
â@@codestorywithMIK Ok bhaiya !! Thanks for this series & your consistency is on next level...đđđ„đ„
@coddstorywithMik okayy sure, can you please upload the code of prefix sum array in your GitHub repo? Love your content as always , keep it upâ€ïž