BEST EXPLAINATION SEEN SO FAR, UR VIDEO IS GENERALLY THE LAST VIDEO I SEE BECAUSE IT MAKES ALL CLEAR, PLEASE CONSIDER CAPS AS A SALUTE TO YOU NOT HARSH!!!!!!!!!!!!!
I don’t know c++, but Java has treeset which can be used to solve the problem in O(n logn). We cannot achieve this time complexity using hash set. Tree set basically is an implementation of red black trees. Also using fenwick trees will take O(n log n) instead of O(n) as told in the video.
I think it's O(nlogn) for Fenwick trees too correct me if I'm wrong O(n) traversing -> O(logn) for quering the sum -> O(logn) for updating Overall O(nlogn)
by BIT method also it takes O(nlogN) where N is maximum no present in array. if anyone trying BIT method check for method where there are negative integers also. And if by chance its floating array then merge sort method is best.
@@aesthetic_vibes_404 Upper bound will give index and that can be used to calculate distance. So calculating distance is just O(log n) and we calculate the distance for 'n' elements. So O(nlogn)
I will make it once I cover BIT. For now I am covering graph. After that I can. Actually everyone is requesting to teach different stuffs, so it's becoming very difficult to switch. As soon as i upload some videos on graph interview prep then I will switch to your idea of BIT and other DS :) I hope you understand.
import java.lang.*; import java.io.*; class GFG { public static void main (String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i
No, because the distance function has linear complexity O(n), and we are calculating this for every index, so in the worst case time complexity will be O(n^2)
Code Using Merge Sort long long int inversionCount(long long arr[], long long n) { return mergeSort(arr,0,n-1); } long long int mergeSort(long long arr[],long long low,long long high) { long long res=0; if(low
I always thought it was an extremely hard problem. This explanation made it look so easy. Thanks.
Welcome :)
Best explanation I have seen so far
Thanks :)
This is the best video to understand the merge sort method for count inversion. Explanation was really very clear and straight forward. Thanks a lot 😊
Welcome :)
One best thing is that
U always take tough example which explain all the possible situation....
Awesome explanation..
Thanks sir...
Welcome :)
Clear and crisp explanation. Thankyou for creating such a good stuff.
Welcome :)
bhai 1 number....I always prefer your video when I get stuck on any problem.
Nice :)
After seeing this video this problem became a very easy problem. Thank you
Welcome :)
BEST EXPLAINATION SEEN SO FAR, UR VIDEO IS GENERALLY THE LAST VIDEO I SEE BECAUSE IT MAKES ALL CLEAR, PLEASE CONSIDER CAPS AS A SALUTE TO YOU NOT HARSH!!!!!!!!!!!!!
Nice to hear this :)
The best explanation for this problem 👏 👌
you are really tech dose....ur explanation is very good.
Crystal clear explanation..
Thanks :)
time complexity for BIT method is O(nlogn)
this is called explanation with good knowledge
The Best explanation ever... 🙏🙏🙏
Thanks
Best Channel Ever! You are doing good work. :)
Thanks :)
Very clear explained! Thanks. That's what I needed!
Welcome :)
Crystal clear explanation. Thanks a lot!!
Welcome :)
Picture explains everything, thanks.
In the 3rd method, the std::distance time complexity on std::multiset is O(n), so the overall time complexity is O(n^2)
I don’t know c++, but Java has treeset which can be used to solve the problem in O(n logn). We cannot achieve this time complexity using hash set. Tree set basically is an implementation of red black trees. Also using fenwick trees will take O(n log n) instead of O(n) as told in the video.
Hey Man!
How to access the indexOf an elem in TreeSet ..?
@@aeroabrar_31 treeSet.headSet().size
This was an amazing explanation! Thank you!
Welcome :)
Nice explanation sir....you are doing a great job
Thanks :)
I think it's O(nlogn) for Fenwick trees too correct me if I'm wrong
O(n) traversing
-> O(logn) for quering the sum
-> O(logn) for updating
Overall O(nlogn)
Clear explanation dude
Thanks for the explanation
Welcome
I think the time complexity of upper_bound in a multiset is log(n) so the third method can be O(nlogn). Not sure though!
@techdose can you explain the complexity of the 3rd method?
Ya exactly I have the same doubt ..
He used distance function which take O(n) time
Could you please provide its code. I am not able to find it anywhere
by BIT method also it takes O(nlogN) where N is maximum no present in array. if anyone trying BIT method check for method where there are negative integers also. And if by chance its floating array then merge sort method is best.
very nice explaination ever seen .thanks a lot
Welcome
very clear explanation thank you
You are genius :-) Thank You
😅 Welcome
very very good explanation
Thanks :)
Great explanation!
Thanks
Wow what a great explanation 👍
Thanks
Man I got understood everything, I saw there
Nice :)
RIP english
Thank You for the explanation. Where can I find Method - 5 explanation?
thankk you bhaiya!! amazing
Excellent Explanation
Thanks
Awesome Sir!
Sir please make a video on BIT also
Yea...will make it.
Thanks man, explaining step by step is the clearest method. Now I got this algorithm.
Nice 😃
Precise and too the point :)
Thanks
The multiset method doesn't satisfy the time constraint as the distance method takes O(n) for multisets.
Atlast understood ❤❤
Great :)
great explanation
Thanks
nice video ,really helpful
Thanks :)
Helped a lot!
Thank you!
Welcome :)
Why do we need to merge the partitions?
merge sort technique is the best for this problem
Awesome 👍
Sir in BiT updating value and getting prefix sum takes O(log(n)) time then how it is supposed to be O(n)
I think the MultiSet implementation is O(nlogn)
upper_bound => O(logn) in multiset
We do upper_bound 'n' times
Therefore, O(nlogn)
Thinking it N*Log(N)*Log(N) - to insert all element in a set is N*Log(N) - N-elements * Log N to insert * get the index for each insertion is LogN
N² bcz a loop is outside for insertion O(n) and distance stl gonna take O(n) for calucating distance.
Hence N²
@@aesthetic_vibes_404 Upper bound will give index and that can be used to calculate distance. So calculating distance is just O(log n) and we calculate the distance for 'n' elements. So O(nlogn)
I am very curious you make very good videos..what do you do full time?
Software Developement Engineer.
merge sort is very understandi all us
a[i]>a[j] and j>i , this is the inversion
i think your inversion is wrng
method 2-merge sort 4:30
method 3-multiset 14:30
Thanks for this my book didnt show this well
😁
So it's like checking if they are sorted or not?
Can you please tell me the Space Complexity of the 2nd method??
space complexity is actually O(n) like merge sort since you need extra array to store the numbers in sorted order
Nice explaination, BIT method too (:
Okay
It would be very good if you shown code also,by the way it is fabulous.
Yea I am doing it from March 2019.
best explanation
Thanks :)
Is the second method based on the merge sort called Piggybacking on merge sort also?
انت راقي احبك😘
😅
Superb
do u have any video on inversion in 2D array, in my code the time complexity is O(n^4), I want to reduce it
pls discuss the BIT method
Yes sure
Please make a video on AVL tree and BIT. It would be very helpful.
It will come later when I resume Segment tree and TREE.
THANK YOU SO MUUUUUUUUCH
really helped a lot
why is this solution not working for gfg and leetcode problems?
thank you so much
Sir I can't apply Fenwick tree properly. Please apply Fenwick tree to solve this problem .
I will do it after DP.
can you make a video for the inversion count using BIT??
I will make it once I cover BIT. For now I am covering graph. After that I can. Actually everyone is requesting to teach different stuffs, so it's becoming very difficult to switch. As soon as i upload some videos on graph interview prep then I will switch to your idea of BIT and other DS :) I hope you understand.
Last method was 💖
😂 Using multiset is the easiest :P
we can use stack also
Can you please explain this question in single file programming.
Awesome
Thanks
Which software do you use for the anntoations?
Ink2go :)
@@techdose4u thanks! may I ask which pad do you use to do the actual writing?
From where I get the code?
I dint provide code for this. This is an old video. Back then I was not sharing code. Sorry. But I provide all codes now.
could you give the code for method 2?
import java.lang.*;
import java.io.*;
class GFG {
public static void main (String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i
Sir can u pls provide the explanation for Binary indexed method for the same problem
Sure.... When I get time I will
@@techdose4u thanks sir
can you explain the BIT method
Yea....I will cover this problem when I cover BIT
Code Using Multiset
```
long long int inversionCount(long long arr[], long long N)
{
long long int ans=0;
multisetm;
for( long long int i = 0; i
Multiset😍
😅
thnx a lot
Hi please explain BIT method
Sure.
Thanks
Welcome
multiset me minus nhi hota h sir
Sir, can you please provide the code for all the methods and explain all the methods in another video. Please sir.
CODE LINK: www.geeksforgeeks.org/counting-inversions/
I will explain the methods in detail later.
@@techdose4u You are doing a great job sir. Could you please share your FB Id so that i can connect.
At 3:10 you accidentally said 4 is greater than 6 hence there is inversion.
Got confused for a bit 😛
:P
Great explanation!
Could you also make a video about how to get the number of inversions per element in the original array?
Sure.....but can you suggest me a proper title for that. That will be helpful to see if users need it or not.
How about "count of smaller numbers after self" ?
I guess I should have explained that in video itself 😅
3rd method should be O(nlogn) right? ( we dont need to use "distance")
sir please also provide a code of this problem
Please try to code yourself
Ok sir
getting TLE with set
Please explain BIT
difference kaise nikale
I think in the method 3 ,the time complexity should be o(nlogn).
No, because the distance function has linear complexity O(n), and we are calculating this for every index, so in the worst case time complexity will be O(n^2)
Sir can you share the source code
Please try to search in comment section
I know the solution but not the intuition that leads to merge sort.
you should change your name to Placement Cracker
Let it be techdose :P
@@techdose4u Thank you So much ,Sir you are a great help .
:)
maal
Code Using Merge Sort
long long int inversionCount(long long arr[], long long n)
{
return mergeSort(arr,0,n-1);
}
long long int mergeSort(long long arr[],long long low,long long high)
{
long long res=0;
if(low