Its because, in the body of for loop, we are comparing array[i] with array[i+1], if we go till array.length, at last iteration, we will get indexOutOfBound exception.
bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?
If question main task is not sorting but doing other job, then we can take help of in built sort method of Array class or collection class, but if the question itself ask to sort then we cannot use it.
Really? I guess most of the interviews are based on using user defined methods and not using much libraries to solve problems. And moreover sort method will sort in nlogn TC.
the best explination on this topic i've found - thanks so much!
tysm!! your explanation helped a lot!! 💖💖💖💖
Thank you
Thank you so much. such a simple explanation
thank you for your nice and valuable explanation🙏
Glad it was helpful!
Thank you for your concise explanation!
very nice explanation
excellent and precise
So beautifully explained. 🏆🏆🏆🏆🏆
Glad it was helpful!
good explanation be blessed
man your dam good at coding
i have subscribed , keep good work up
Thanks Vrashikesh for your appreciation and support.
very very nice explanation sir ....
Thanks for liking
Your explanation is really good and Already subscribed your channel too
Thank you so much 🙂
Great explanation
Glad you liked it 🙂
Thank you sir
Very nice👍🏻
Thank you 👍
Very good😊
Thanks 😊
Brilliant
Thank You
Why are we running loop till (i
Its because, in the body of for loop, we are comparing array[i] with array[i+1], if we go till array.length, at last iteration, we will get indexOutOfBound exception.
You're using nested loop... Btw nice for beginners
Yes you are correct. Logically it is using nested loop only and that's why the time complexity will be also n^2, but on paper it is one loop only.
please provides data structure and algorithms in java
Nice
So nice
Good
Thanks
Greetinngs sir why you are importing package
Greetings Venkata, just to print. It was not required anyway.
what will be its time complexity
It will be n square only
hi quick question - why could you not have reset the index to 0 instead of -1?
i++ in for loop is there to increment it
bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?
If question main task is not sorting but doing other job, then we can take help of in built sort method of Array class or collection class, but if the question itself ask to sort then we cannot use it.
Really? I guess most of the interviews are based on using user defined methods and not using much libraries to solve problems. And moreover sort method will sort in nlogn TC.
What is time complexity?
It will be of order of n^2 as we are resetting the index again and again.
the time complexity is still n2
Yes , you are correct. its is jus a trick o complete the program in one for loop.
sir what is the worst case time complexity of this sort
Its o(n^2) as we are resetting the index every time.
@@CodingEnv sir is their any algorithm to sort an array in O(N)time complexity
Yes, but their should not be any limitations on space complexity...
@@CodingEnv sir can u tell me which algorithm there is no need for limitations of space complexity
You can go through this link stackoverflow.com/questions/12240997/sorting-array-in-on-run-time#:~:text=Yes.,o(n)%20time%20complexity.
May i know the time complexity
Even though we are using single for loop, the time complexity will remain O(n^2) only.
@@CodingEnv Is it beacuse we using Arrays.toString(); function or what ?
No, because we keep on resetting the index inside the for loop
Can you send Tamil language pls
Good
So nice