Square Root Decomposition with Code

  Рет қаралды 6,217

Kartik Arora

Kartik Arora

Күн бұрын

Gentle introduction to Square Root Decomposition.
implementation of the idea discussed in the video: ideone.com/eg4y3S
To solve the problem of answering range queries on an Array A[1..N].
Queries are of two types:
1. find function F applied on the range [L,R]. F can be sum, min, max or wide range of other functions.
2. point update. set A[i] = new_value V.
Algorithm:
1. Break Array A into X smaller chunks each with Y elements.
2. Find F applied over each chunk individually.
Why exactly root N chunks each with root N elements?

Пікірлер: 27
@dontony7071
@dontony7071 3 жыл бұрын
Bhaiya for numbers which are primes like 1e9+7 or numbers which are not perfect squared like 3^9 will this method work?
@AlgosWithKartik
@AlgosWithKartik 3 жыл бұрын
Yes it will. Imagine N the size of array is not a perfect square. There are two things you can do: 1. Add some extra elements to the array (equal to identity element, 0 incase of sum queries) to make the size a perfect square. 2. Make ceil(root(N)) chunks with each chunk having exactly ceil(root(N)) elements except for the last chunk which will have fewer elements and it's okay.
@dontony7071
@dontony7071 3 жыл бұрын
Got it bhaiya.Thanks for replying🙂.
@Asdfgadv33423
@Asdfgadv33423 3 жыл бұрын
@@AlgosWithKartik Hello. How hard is it to get an internship for a big company while being at university? Ty! edit: And if you know, can you give me some advice about it? What to work on, what types of problems should i solve, any advice would be great!
@hardikraj9469
@hardikraj9469 3 жыл бұрын
Thanks, I wanted an implementation of square root decomposition for a long time.
@ankitpandey3724
@ankitpandey3724 3 жыл бұрын
It really feels bad to see that the frequency of video uploads has reduced. But its understandable you have to work life too. Thanks a lot though 🎉🎉🎉.
@AlgosWithKartik
@AlgosWithKartik 3 жыл бұрын
Frequency might be low but I'll keep posting useful content and trying my best to add value :)
@ankitpandey3724
@ankitpandey3724 3 жыл бұрын
@@AlgosWithKartik that's all we need. Thanks a lot bhaiya.
@girishgarg2816
@girishgarg2816 3 жыл бұрын
Kya bawal chiz bana diye ho. Maza agaya
@mahbubulalamsabuj373
@mahbubulalamsabuj373 3 жыл бұрын
bhai you are amazing.keep doing this for us please
@AnkitJosh
@AnkitJosh 3 жыл бұрын
Bhai mauj kardi. Tum toh bade heavy explainer ho bhai
@abhijeetbasfore6816
@abhijeetbasfore6816 2 жыл бұрын
What about Mo's algorithm?
@subhashgupta7783
@subhashgupta7783 3 жыл бұрын
Very important concept kartik bhaiya ❤️
@subhashgupta7783
@subhashgupta7783 3 жыл бұрын
with too many applications *
@AyushGupta-mm4jg
@AyushGupta-mm4jg 3 жыл бұрын
Thanks for the videos :)
@saumilkapadia88
@saumilkapadia88 3 жыл бұрын
Lovely explanation!
@bawabigballer
@bawabigballer 3 жыл бұрын
what an explanation. amazing
@girishgarg2816
@girishgarg2816 3 жыл бұрын
Bhaiya expected value part 2 kab aayegi?
@AlgosWithKartik
@AlgosWithKartik 3 жыл бұрын
Abhi bandwidth kam h and time milne prr focussing on range query series. Will try ki expected value bhi jaldi continue krru :)
@girishgarg2816
@girishgarg2816 3 жыл бұрын
@@AlgosWithKartik Okay. I have been binge watching your videos. Gem content.
@vijaykumarlokhande1607
@vijaykumarlokhande1607 3 жыл бұрын
precise
@sahilbazard4273
@sahilbazard4273 Жыл бұрын
Please continue for segment and fenwick trees🙌
@jimjam9026
@jimjam9026 3 жыл бұрын
Hello bro your explanations are really great ( probably finest in all of youtube ) please make vedioes on segment trees and Fenwick trees also.
@abdullasulfikkar5282
@abdullasulfikkar5282 3 жыл бұрын
thank you bhaiya
@shubheshtiwari8525
@shubheshtiwari8525 3 жыл бұрын
bawaal ekdum
@codewithdev1375
@codewithdev1375 2 жыл бұрын
The best explanation, i love your teaching bro . Please do make videos on problem solving using these methods it will give us much better understanding.
@bodduaravind5843
@bodduaravind5843 3 жыл бұрын
Sir please start graph series
Disjoint Set Data Structures | Union Find | DSU | Range Query
21:24
Kartik Arora
Рет қаралды 1,7 М.
Range Queries with Mo's Algorithm
18:15
Algorithms Conquered
Рет қаралды 7 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 88 МЛН
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН
Oh, wait, actually the best Wordle opener is not “crane”…
10:53
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Range Query Problems and Data Structures
10:29
Kartik Arora
Рет қаралды 10 М.
Square Root Decomposition, Mo's Algorithm
1:29:36
Errichto Hard Algorithms
Рет қаралды 29 М.
Sparse Table | Range Minimum Query in O(1)
17:13
Kartik Arora
Рет қаралды 7 М.
The 3 Laws of Writing Readable Code
5:28
Kantan Coding
Рет қаралды 579 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 88 МЛН