Тёмный

Fenwick Tree or Binary Indexed Tree 

Tushar Roy - Coding Made Simple
Подписаться 245 тыс.
Просмотров 238 тыс.
50% 1

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 286   
@jyotikumari-bl2kf
@jyotikumari-bl2kf 8 лет назад
@Tushar Hey Tushar, it will be good if it is mentioned why 5 is expressed as 2^2 + 2^0 and not 2^0 + 2^2. The idea here is to go to the parent and then next x number of elements. I got confused when i saw the video. Then later i figured it out that it is expressed as parent index + some power of 2.
@saikatsarkar858
@saikatsarkar858 8 лет назад
Precisely,I was wondering about the exact same thing until i came across your comment.Thanks a ton! :)
@jitendranagar8962
@jitendranagar8962 7 лет назад
initially confused ....how updating a index i to index j some time 2^x + 0 and some time 0+2^x.....But you made it clear thanx
@kartikchauhan5498
@kartikchauhan5498 7 лет назад
You need to go up.
@SergeyGrebenkin
@SergeyGrebenkin 6 лет назад
I was also surprised unless I read your comment
@manhxxo
@manhxxo 6 лет назад
In this case, 2^2 will be the dad node and 2^0 is the rightmost bit 1. For example: 11 = 1011= 2^3 + 2^1 + 2^0 which is 2^3 + 2^1 will be its dad node(1010 = 10) and 2^0 is the value of rightmost bit 1 of the node (0001).
@CSSFACE
@CSSFACE 2 года назад
To get the parent of n, you can also find it by calculating n & (n-1) which is a little simpler than the 3 step process described in the video (2s complement, AND with original, then subtract from original)
@Marzex1x
@Marzex1x 5 месяцев назад
it is simpler but at the end of the day they're both 1 liners
@SergioS-ji1hv
@SergioS-ji1hv 5 месяцев назад
​@@Marzex1xbeing a one liner literally doesn't mean anything, use the one that's widely better understood
@Marzex1x
@Marzex1x 5 месяцев назад
@@SergioS-ji1hv doesn't really matter at the end of the day it comes down to personal preference
@amazingseries
@amazingseries 8 лет назад
Nice and short videos. Another simple way to obtain the parent of index x is x & (x -1)
@Hetp111
@Hetp111 5 лет назад
Yes, I was thinking the same...! More info: www.techiedelight.com/brian-kernighans-algorithm-count-set-bits-integer/
@PrateekRathore
@PrateekRathore 5 лет назад
Is the any cool trick to find the next number in fenwick tree ??
@stablesort
@stablesort 4 года назад
Well said. A more detailed explanation could be found in another tutorial: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-uSFzHCZ4E-8.html
@ishanraj5961
@ishanraj5961 4 года назад
@@PrateekRathore the next of i will be i+ (i&(-i) ).
@tarunkumar2269
@tarunkumar2269 4 года назад
@@ishanraj5961 that is what tushar said
@mysterymidas8574
@mysterymidas8574 6 лет назад
One of the best explanations I've ever come across for Fenwick Tree!
@AmanGarg95
@AmanGarg95 9 лет назад
Its nice that you actually focus on analysis and also point out the petty things that form the basis of the code eg. the next hop and the examples. This is in contrast to other algo preachers who just mutter out the process without specifications as if it were imminent. Thanks, and please don't stop making videos.
@bhavtejsingh
@bhavtejsingh 9 лет назад
Aman Garg agreed!
@farhadpagdiwala1789
@farhadpagdiwala1789 2 года назад
Very good explanation on the fenwick tree concept and how to create and update the tree.
@lavanya_m01
@lavanya_m01 Месяц назад
After watching a couple of BIT explanations from some good channels, I lost the hope of COMPLETELY understanding it. But you made it so easy and clear in 20min!! Legend you are! ❤
@juliettetworsey3060
@juliettetworsey3060 2 года назад
Thank you so much for this and thank you for breaking everything down to a level that makes it easy to understand a binary indexed tree. Awesome explanation!
@jinyang4796
@jinyang4796 2 года назад
This video is just too good! Thank you so much!!!!!!
@krokenstiv8777
@krokenstiv8777 2 года назад
finally i found a real expert on Fenwick Tree, I actually implemented it in Java using this lecture. Thank you very much!
@NextyTV
@NextyTV 9 лет назад
That's your second video that I watched and it was very helpful. Just came here to say thank you.
@FinanceStoryTime
@FinanceStoryTime 6 лет назад
One of the best explanations on Fenwick Tree on the internet. Well worth the 22 mins I spent on watching.
@amanpreetsingh8628
@amanpreetsingh8628 8 лет назад
I have heard a lot that this topic is very tough but you really made it easy for me . Thanks a lot.
@idiot7leon
@idiot7leon 4 года назад
Thanks, @Tushar. You don't know how great&helpful your videos&tutorials are to me!
@anatoliistepaniuk8217
@anatoliistepaniuk8217 7 лет назад
Wow, This is a really useful content! Thank you for the value you create!
@psurya3053
@psurya3053 Год назад
gotcha bro , u are the best one on the youtube , there are tons of creators who tried to explain same topic , i couldnt understand , u are the best. thank u so much
@Ronakrktanna
@Ronakrktanna 8 лет назад
Thank you so much for an amazing explanation of a complex data structure. :)
@cjoe1909
@cjoe1909 2 года назад
Hi, thanks very much for the instruction. I am now fully understand the algorithm and can implement myself during interview.
@VaibhavRaheja
@VaibhavRaheja 7 лет назад
Only some people have the talent to explain such complex concepts in such an easy manner. And Tushar is one of them.
@eryash15
@eryash15 6 лет назад
Perfect brother, if one wants to learns can learn from this lecture or cannot learn at all..... All concept perfectly covered in 20 min.
@lakshayvirmani5877
@lakshayvirmani5877 8 лет назад
Best Explanation. Simply Amazing. Thanks a lot! :D
@tahanimachowdhury
@tahanimachowdhury 8 лет назад
You are awesome as usual. I was struggling with Fenwick Tree for a long time and now it is clear. Thank You for your efforts. :) ^_^
@parthamishra09
@parthamishra09 3 года назад
lovely stuff. thanks for explaining it so patiently. much appreciated.
@mr6462
@mr6462 3 года назад
Thanks for the visualization and the explanation! I think Fenwick Tree is beautiful :)
@vineetsharma7287
@vineetsharma7287 3 года назад
One of the best videos on Fenwick Tree!!!
@prudvim3513
@prudvim3513 8 лет назад
Thank you very much for such a nice and lucid explanation.!!!
@ayushjindal4981
@ayushjindal4981 3 года назад
For filling up the tree, we can create a cummulative sum array and using that we can fill the nodes...it will take O(n) time to fill the entire tree.
@manthansheth880
@manthansheth880 8 лет назад
Awesome work! Thanks a lot and keep up the good work.
@catherinewang1191
@catherinewang1191 7 лет назад
Big fan of your video blogs.. Best explanation ever.
@koyalkardevanshu5146
@koyalkardevanshu5146 8 лет назад
Thank you for putting this up. Aap infi machate ho.......infi respect
@RohanLokeshSharma
@RohanLokeshSharma 9 лет назад
one of the best explanations of Fenwick Tree out there! Great work,
@AnkitKumar-zu7cn
@AnkitKumar-zu7cn 5 лет назад
Very clear explanation! Thanks for pulling this up!
@aisakyunhotahai8130
@aisakyunhotahai8130 3 года назад
Never seen him smiling, I guess he is Robot
@pengjin7912
@pengjin7912 8 лет назад
Thank you so much for this work! It really helped me to understand the BIT!
@OmarAhmedAbdulwahhab
@OmarAhmedAbdulwahhab 4 года назад
Excellent.... Excellent....Excellent ...Thank you very much
@amandeepsingh1730
@amandeepsingh1730 4 года назад
Amazing! You just remove my fear about fenwick tree. Thanks
@NehhalKalnadTheGreat41
@NehhalKalnadTheGreat41 5 лет назад
Good expln. those who are still confused, please read some article and then again refer the vdo
@shishirmohire9789
@shishirmohire9789 6 лет назад
I learnt lot of things from you man thanks.
@talalal-hamidi3093
@talalal-hamidi3093 9 лет назад
Thank you for this great job. Keep going Helped me so much
@mohit2072
@mohit2072 7 лет назад
You amazing man... When I saw some hackerearth notes..i just ignored it coz it was quite long and reading becomes useless..and here i saw ur video and i dun knw how just time passed and finally understood it...thnx and will go thru every video of urs coz these are the hottest topics in competitive coding world
@AlayDhagia
@AlayDhagia 3 года назад
you sir are a legend
@jineshdhruv6151
@jineshdhruv6151 6 лет назад
Because of your videos, my Data Structures concepts are getting clear and strong...... Thank you very much... please also post videos about how to apply data structure logic for any given problem. I don't know about others but sometimes I fail to understand which data structure I should use to solve a problem.
@KshitijJollyGuitar
@KshitijJollyGuitar 8 лет назад
Nicely explained. Thank you :)
@ayushsingh7987
@ayushsingh7987 2 года назад
Thank you sir it is very helpful video
@kidou123456
@kidou123456 6 лет назад
Thank you very much, Tushar. This helps a ton!
@ihtemad
@ihtemad 4 года назад
you can get parent in a bit easier way: Parent = n&(n-1)
@OmarAhmedAbdulwahhab
@OmarAhmedAbdulwahhab 4 года назад
n refers to what ?
@helinw
@helinw 6 лет назад
Thanks for the video, would be nice if you could explain more about how was the rules you mentioned generated, it helps memorizing the rule.
@hassanramadan2611
@hassanramadan2611 3 года назад
Thank You for this amazing tutorial!
@arhankundu2516
@arhankundu2516 4 года назад
Thanks for the awesome explanation!
@shubhamkapoor6954
@shubhamkapoor6954 4 года назад
we can find parent also by first subtracting number by 1 and then do bitwise and of this number with original number eg :- 10 is 1010 subtract 1 1001 now do bitwise and it with 10 1010 & 1001 = 1000(8), which is the result.
@xinranwan9390
@xinranwan9390 2 года назад
Just for heads-up, 15:04 he means add 1, not 2, to the original number.
@arijit48
@arijit48 8 лет назад
Thanks, Tushar ... Your videos r well-presented and a great help :) !!!!
@prasenjitmondal673
@prasenjitmondal673 9 лет назад
It would be great if some problems can be solved using BIT from competitive programming challenge.
@charvakpatel962
@charvakpatel962 9 лет назад
+Prasenjit Mondal codeforces.com/problemset/problem/597/C have fun
@atishayjain5912
@atishayjain5912 5 лет назад
Why would a segment tree take 4n space in the worst case? A tree with n nodes, has, n/2 leaf nodes, so shouldn't the worst case be 2n?
@al-aminhossain9534
@al-aminhossain9534 7 лет назад
Realy It was very helpful to me. Thanks boss.
@madhukiranattivilli2321
@madhukiranattivilli2321 3 года назад
FT creation takes linear time but not linearithmic time. This is the way to do in linear time : -- fill original array values at indices [0, n-1] into FT array indices [1, n]. FT is created of size n+1, and FT[0] is n/a -- Propagate values up in a cascading approach. 1 is 0001. 1+lsb(1)=1+1=2 (lsb: least significant bit, obtained as x & - x). So, 2 is responsible for 1. In other words, 2 stores the prefix sum of 2 array indices -- itself and 1 below. How? 2 is 0010. lsb(2)=2. lsb(x) represents the prefix sum of how many array indices it is responsible for. So, add FT[1] to FT[2]. Next, handle 2. 2+lsb(2)=2+2=4. Add FT[2] to FT[4]. 3+lsb(3)=3+1=4. Add FT[3] to FT[4]. 4+lsb(4)=4+4=8. Add FT[4] to FT[8]. -- Thus we don't propagate a number all over the FT in O(log2(n)) time. Instead we propagate only to the immediate higher number who is responsible for current number (example: 4 is 8's responsibility. 5 is 6's responsibility, etc) -- Thus we construct the FT from i/p array in O(n) linear time
@adhoc3018
@adhoc3018 3 года назад
You are an inspiration.
@SonuSonu-tk5pk
@SonuSonu-tk5pk 6 лет назад
awesome explanation sir ji ... u r great ...
@risureviewcompany
@risureviewcompany 9 лет назад
sir, wotever u r doing is awesome .. respect !! you always save my time with better explaination.. :)
@pritamchakraborty7163
@pritamchakraborty7163 9 лет назад
In order to do a range query [x,y], should we need to get prefix sum [0,y] and [0,x) and subtract them?
@hackermub2598
@hackermub2598 5 лет назад
well yes.. because BIT is just a prefix sum that can also be updated
@caret4812
@caret4812 5 лет назад
why asking, you already know the answer lmao
@rajatjain409
@rajatjain409 8 лет назад
superb explanation in a much simple way. :)
@readogamer3515
@readogamer3515 4 года назад
Great explanation
@user-pv1pb3tt3x
@user-pv1pb3tt3x 7 лет назад
great and clear explanation, thanks!
@muditkhandelwal2008
@muditkhandelwal2008 7 месяцев назад
@Tushar you should also explain how to get range sum for lower bound > 0. Eg. RangeSum(2, 6) Here is the snippets for finding range sum: int findSum(int low, int high) { if (low > high) throw new Error("Invalid range"); int index = high+1; int upperBoundSum = 0; while (index > 0) { upperBoundSum += tree[index]; index = getParent(index); } int lowerBoundSum = 0; if (low != high) { index = low; while (index > 0) { lowerBoundSum += tree[index]; index = getParent(index); } } return upperBoundSum - lowerBoundSum; }
@freezefrancis
@freezefrancis 8 лет назад
Great work Tushar :)
@nhan1503
@nhan1503 8 лет назад
Thank you so much. Keep up the good works :)
@akshayanm
@akshayanm 3 месяца назад
In the video, you said the TC of building the BIT is O(nlogn). If we use a prefix sum array just for making the tree, we can reduce it to O(n) right?
@shreyasshetty5051
@shreyasshetty5051 4 года назад
Thanks a lot sir
@Marzex1x
@Marzex1x 5 месяцев назад
much love brother
@themohameDkhalifa
@themohameDkhalifa 9 лет назад
in filling up the tree, why didn't you say that 3 = 0 + 2^1 + 2^0 and start from index 0 just like you did in 2?
@bhavukmathur2709
@bhavukmathur2709 8 лет назад
What I figured out is that for all the powers of 2 (2,4,8), he started from 0. Else he started in the descending order of powers of two. Just a rough guess.
@prasenjitmondal673
@prasenjitmondal673 9 лет назад
Very Nice Explanation.
@SmileyMPV
@SmileyMPV 7 лет назад
I'm certain you can create the tree in O(n) if you use a faster algorithm. I think I found a way to calculate the values one by one where they take O(1) time amortized.
@gamingbutnotreally6077
@gamingbutnotreally6077 Год назад
yes creating the initial tree can be done in O(n) this is quite well known.
@jamesqiu6715
@jamesqiu6715 2 года назад
convoluted explanation !
@victormarciliopeixoto
@victormarciliopeixoto 9 лет назад
wow! awesome, very didactic!
@halseywalker5015
@halseywalker5015 3 месяца назад
Thank you ,master
@theultratraveller2024
@theultratraveller2024 9 лет назад
b'coz of ur explanations..... i'm able to code way better for competitve prog......thankx!
@rockstar86374
@rockstar86374 4 года назад
what I figured out from the above video is. if you want to find the sum of the ith element, then go to its parent and from there take the smallest 2^power element present in I and take the sum of that much element. For example ,{ () represent power} for 1 = 2(0) parent is 0 take 2(0) elements from there that is (0,0) for 2 = 2(1) parent is 0 take 2(1) elements from there that is (0,1) for 3 = 2(1)+2(0) parent is 2 take 2(0) elements from there that is (2,2) for 4 = 2(2) parent is 0 take 2(2) elements from there that is (0,3) for 5 = 2(2)+2(0) parent is 4 take 2(0) elements from there that is (4,4) for 6 = 2(2)+2(1) parent is 4 take 2(1) elements from there that is (4,5)
@hanaagebril9795
@hanaagebril9795 3 года назад
I dont understand the part of index value evaluation, based on what? I mean the evaluation of each index in the fenwick tree for 1, 2, 3, .... and so on you started with 0 with some and 2 with others. also I can see that as an example the index 6 may have more than representation , the one you mentioned 3 = 2ofpower1+2ofpower0 not started by 0 as the 1 and 2, please can you make it clear more to me?
@hanaagebril9795
@hanaagebril9795 3 года назад
I got it. It depends on the binary bits count representation of the number in other words the number 4 represents by 100 in binary which has one active bit at position 3 with power 2 which equal 2 of power 2 then its value will start by 0 followed by the 4[2 of power 2] and for number 6 it represents by 110 which has more than one active bit at positions 2 and 3 or power of 1 and 2 respectively which equals to [2 of power 2] + [2 of power 1] and need to start from 0 for that number.
@gaoyansong5428
@gaoyansong5428 8 лет назад
very clear! thank you !
@诸葛俊伟
@诸葛俊伟 8 лет назад
Wow!!!!!! Amazing, I love u, Tushar!!!! From now on, every time I meet a new question or a new knowledge that I want to learn, I will come to your videos first!
@mohit2072
@mohit2072 7 лет назад
Also for range other than 0,y let say we need to get range from x,y then just we gotta do is (0,y)-(0,x-1) :p I hope many may thought abt it so likhdiya ;p
@lostgen36
@lostgen36 4 года назад
Thanks 😁
@Apptica
@Apptica 9 лет назад
It is the best explanation i think....every information is so clear and simply explained.....Do you have any tutorial regarding how to perform range updates in fenwick tree
@Apptica
@Apptica 9 лет назад
***** Yes updating all elements in given range
@mudithead
@mudithead 8 лет назад
Great video again. What are your thoughts on using Binary Indexed trees vs segment trees? I can use BIT for solving all problems which segment trees can? I find segment trees hard to implement in interviews..
@dluxhu
@dluxhu Год назад
This is technically not a binary tree, because one node can have multiple child nodes. But other than that, it's smart. Thanks for the explanation!
@mayurkulkarni755
@mayurkulkarni755 8 лет назад
Excellent tutorial!! Keep it up bro
@ninatsvetkova
@ninatsvetkova 9 лет назад
Thanks for making this video!
@ninatsvetkova
@ninatsvetkova 9 лет назад
***** And for the uploaded resources in github. Glad I found this channel :)
@gordonzhang5374
@gordonzhang5374 8 лет назад
crystal clear! Thanks a lot!
@174ashish
@174ashish 8 лет назад
great explanation sir !!
@jiyushi8678
@jiyushi8678 8 лет назад
Thank you it really helps!
@88LeeAlexander
@88LeeAlexander 4 года назад
Thank you for the clip. :)
@lucasfisher5862
@lucasfisher5862 7 лет назад
great video, very clear
@CodingIsEasy372
@CodingIsEasy372 8 лет назад
Excellent tutorial!! Will u please make a video on fenwick tree with range updates and range queries.
@achboldjugdersuren6883
@achboldjugdersuren6883 4 года назад
I signed into my account to say thanks.
@themagicianadamagic7830
@themagicianadamagic7830 8 лет назад
It was really useful. (If you have time and patience could you upload the efficient way of filling the tree up. I am really intrested in that.)
@taruneemeesala8052
@taruneemeesala8052 4 года назад
Get next element explanation is intuitive. If current element is represented as parent index + next x elements (as power of 2), we need to increase the range of next x element by power of 2. Example: 6 = 2^2+2^1 then next element=2^2+2^2=8
@DeepakGupta-yv8ft
@DeepakGupta-yv8ft 4 года назад
you are a hero
@Venkat2811
@Venkat2811 9 лет назад
Thanks man, simply gr8
@sambhavyadav8179
@sambhavyadav8179 8 лет назад
exquisite work ! :)
@ayushsethi1085
@ayushsethi1085 9 лет назад
heyy!! i must say that you are doing a great job!! i just wanted to confirm that if the number is a power of two then we take the summation from starting(ie index 0) to the number and in rest of the cases we are dividing the number in the decreasing power of 2s ?
@English_Vinglish-c9o
@English_Vinglish-c9o Год назад
this is the best video
Далее