Sort An array using Recursion

  Рет қаралды 242,884

Aditya Verma

Aditya Verma

Күн бұрын

Sorting and array using Recursion by using Induction-Hypothesis and Base condition Approach.
Pdf notes and code: / 38605857 .
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3kMohtd
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Пікірлер
@nityanandbhaskar2155
@nityanandbhaskar2155 4 жыл бұрын
I can't thank you enough for making these videos. I completed yours dynamic programming playlist and gained so much knowledge. I was once rejected in interview because i didn't know how to approach DP problems. But after watching your videos , I gained massive confidence and also got placed. Thanks a lot
@willturner3440
@willturner3440 4 жыл бұрын
Amazon
@amanjyotiparida5818
@amanjyotiparida5818 4 жыл бұрын
@Himalayan drifter google
@akashbhadouria6727
@akashbhadouria6727 3 жыл бұрын
@Himalayan drifter bhindi market
@Lalit_Shirsath
@Lalit_Shirsath 3 жыл бұрын
@@akashbhadouria6727 😂
@trackbackresearch
@trackbackresearch 3 жыл бұрын
@@Lalit_Shirsath System Administrator at Thakur Prasad Sao & Sons Pvt. Ltd.
@varungoel6981
@varungoel6981 3 жыл бұрын
Today I got selected in Flipkart all because of your videos Aditya! Besides learning technical stuff, I got to learn from you on how to handle and approach complex problems. Thanks a lot! I really owe you a lot, can't msg on LinkedIn since you haven't accepted my request but I'm gonna ping you as soon as I join to thank you :)
@TheAdityaVerma
@TheAdityaVerma 3 жыл бұрын
Welcome onboard buddy 😅❤️ Glad I could help you in our journey To Flipkart !!
@shinosukenohara.123
@shinosukenohara.123 2 жыл бұрын
pleae guide
@amiyamishra9858
@amiyamishra9858 2 жыл бұрын
@@TheAdityaVerma please make payslist on tree and graph as well ,Your teaching style helps to grasp the concept easily & to remember it for a long time.Thank you !!
@gametech7046
@gametech7046 2 жыл бұрын
Every man must bow, every tongue must confess, this is the best recursion tutorial and Aditya is the greatest teacher of all time.
@tarunstv796
@tarunstv796 2 жыл бұрын
Thank you brother!!!
@matrixtoogood5601
@matrixtoogood5601 3 жыл бұрын
At 17:44, we can also use a binary search (recursive/iterative) to find the position in O(logN) since the left subarray is sorted. This is the most optimized version of insertion sort using recursion. Amazing explanation!
@amitmahato4876
@amitmahato4876 3 жыл бұрын
Yet, the overall time complexity will be O(n^2)
@matrixtoogood5601
@matrixtoogood5601 3 жыл бұрын
@@amitmahato4876 Practically, complexity is only the first thing you check. You have to improve overall performance of the code and asymptotic complexity is only a broad-level analysis. My code is O(N^2) but it will still be much faster than yours :)
@practiceTech
@practiceTech 2 жыл бұрын
@@matrixtoogood5601 You r right bro
@vetlakvsatyanarayana746
@vetlakvsatyanarayana746 Жыл бұрын
@@matrixtoogood5601 share your code once bro
@trueresources3847
@trueresources3847 Жыл бұрын
no man if to insert an element, in the worst case you can have have to shift all elements to make place for the given element, this is not about finding an element, it is about inserting an element in-place in a array or vector.
@rishabhsahu3303
@rishabhsahu3303 4 жыл бұрын
Boss Graph ki playlist ayegi na to lagra apka channel alag hi level pai chala jayega (graph k hard questions include karna )
@vaisnavichirag
@vaisnavichirag 3 жыл бұрын
It has been one year may be you were placed somewhere but the playlist didn't come yet😅😅😅
@vishalramnani5884
@vishalramnani5884 3 жыл бұрын
@@vaisnavichirag aur bhai? xD
@ru2979
@ru2979 3 жыл бұрын
@@vaisnavichirag student of Sri Aurobindo Vidyamandir, U remember me ?
@111rhishishranjan2
@111rhishishranjan2 2 жыл бұрын
its been 2 yrs still that series didn't come . Aditya Verma bhiya where are you ???????
@gauravraj2604
@gauravraj2604 3 жыл бұрын
I don't have words to explain how I am feeling after going through this video. Never ever thought of sorting an array using recursion. I cannot thank you enough Aditya... Every video I watched of urs taught me a new concept...
@hiteshsondhi
@hiteshsondhi 3 жыл бұрын
I always struggled thinking about recursion and how it keep tracks of the variable state and kind of lost in that space. But the way you explained makes it look a hell easier now with focused mind. Thanks Aditya
@abhinandanmishra4391
@abhinandanmishra4391 Жыл бұрын
i think this is the best playlist of recursion i have seen i think this is last becoz explained this is very simple manner of how to think about any recursive function and how to implement that thank you sir for such a great video
@fuzi_blossom
@fuzi_blossom Жыл бұрын
//Thanku Aditya sir -----> for removing the fear of recursion from our head #include using namespace std; void insert(vector&a,int k){ int n=a.size(); //base case if(n==0 || a[n-1]
@udaypandey5659
@udaypandey5659 2 жыл бұрын
The best way to learn is : while Mr. Verma is teaching parallelly you also use pen paper and write . Then you will get very clear picture. I watched 2 times, but it was blur 50 -60 % .. I took pen paper and wrote then Trust me : in just one shot i typed the entire code. Thanks Aditya!
@hrishabhdigaari9140
@hrishabhdigaari9140 4 жыл бұрын
Hey Aditiya, love your content. It's very good. I have been following you for a month now. I have a suggestion for you, If it is possible then in the description of every video, you should put at least 5 similar questions, based on the concept that you taught, from geek for geeks. That would really enhance our practice multiple folds.
@NehaGupta-lf1sr
@NehaGupta-lf1sr 4 жыл бұрын
I agree
@devashishvyas9608
@devashishvyas9608 3 жыл бұрын
agreed that will definitely increase the outcome of the video. This will help us to apply the concept by ourself in various question. You don't have to put the questions in every video just put them in the videos which are very important.
@harshitbhatt5875
@harshitbhatt5875 3 жыл бұрын
Finally...a guy who knows what he's teaching.
@rajatjakhar3146
@rajatjakhar3146 2 жыл бұрын
@theprogrammer change array to vector
@habibhasanshakil9086
@habibhasanshakil9086 2 жыл бұрын
#include using namespace std; void Insert(vector &v, int temp){ if(v.size() == 0 || v[v.size()-1]
@nirbhaychopra7762
@nirbhaychopra7762 2 жыл бұрын
Thanks
@imPriyansh77
@imPriyansh77 Жыл бұрын
Thanks !
@abhinavennala9613
@abhinavennala9613 4 ай бұрын
Thanks man!
@rishabhsingh5816
@rishabhsingh5816 4 жыл бұрын
no paid content can also teach us this awesomely as u do.. bhai next series on backtracking
@123sigalit
@123sigalit 4 жыл бұрын
Aditya I like you explanations and thank you.. I noticed in this video that you started with the question of "sorting an ARRAY" and by the time you started discussing insert function you moved to speaking about sorting a vector.
@laxmangurjar4776
@laxmangurjar4776 3 жыл бұрын
bhai msst padhata hai tu sach mai. ek alag way mai sochna sikhaata hai . thanks yaar
@TeluguTekTeach
@TeluguTekTeach 2 жыл бұрын
After a long time .. after seeing this, maza aaya.. Thanks for teaching in a different way
@shishirchaurasiya3435
@shishirchaurasiya3435 2 жыл бұрын
Just wanna to say l0ve you Aditya Verma.... what confidence I gained in this question was just awesome......... BiG tHanks
@ashvinimeshram5242
@ashvinimeshram5242 3 жыл бұрын
Your way of teaching is just awesome. Thanks for your efforts.
@tanujkasal
@tanujkasal 3 жыл бұрын
thanks for such an amazing explanation, Here's the python code for this problem: def arr_insert(a,b): if len(a)==0 or b>=a[len(a)-1]: a.append(b) return temp=a.pop() arr_insert(a,b) a.append(temp) def arr_sort(a): if len(a)
@DivitMukhi
@DivitMukhi 2 жыл бұрын
how abt bubble sort or selection sort using length=len(are)
@sasiraj1594
@sasiraj1594 4 жыл бұрын
This is Insertion Sort using Recursion :)
@settyruthvik6236
@settyruthvik6236 3 жыл бұрын
yes
@sachetansabhahit6235
@sachetansabhahit6235 4 жыл бұрын
Java code for recursiely sorting an arrar: public class Main { public static void main(String[] args) { ArrayList arr = new ArrayList( Arrays.asList(3,2,1,4,5,6,7) ); arr = sort(arr); System.out.println(arr); } public static ArrayList sort(ArrayList arr){ if(arr.size()==1){ return arr; } int temp = (int)arr.get(arr.size()-1); arr.remove(arr.size()-1); arr = sort(arr); arr = insert(arr,temp); return arr; } public static ArrayList insert(ArrayList arr,int temp){ if(arr.size()==0 ){//|| (int)arr.get(arr.size()-1)temp){ arr.add(temp); return arr; }else if((int)arr.get(0)>=temp){ arr.add(0,temp); return arr; }else if((int)arr.get(arr.size()-1)
@ruduchabagamer5982
@ruduchabagamer5982 3 жыл бұрын
thanks
@vanditdubey8346
@vanditdubey8346 2 жыл бұрын
Thanks man video wasn't clear to me but I'll figure it out form the code
@livelypooja
@livelypooja 2 жыл бұрын
Thanks for this.now I got the clear picture 👍
@vishalghanghav748
@vishalghanghav748 2 жыл бұрын
Thanks I tried by myself ,and couldn't figure out if should use a list or not
@SILENT_4_M_6551
@SILENT_4_M_6551 Жыл бұрын
thank you bro
@carl4705
@carl4705 27 күн бұрын
Bro jo aapne smjhaaya hai na aaj using recursion by chunks Hatts off bro Thankyou so much
@yashsingavi5167
@yashsingavi5167 6 ай бұрын
leetcode ka example poora dry run karke khud se samajh aaya code ka logic thank you bhai !!
@thinkingmad1685
@thinkingmad1685 3 жыл бұрын
Bhai bohot bohot dhanyavaad, mujhe bohot ache se samaj aagaya yeh rha mera code . Yeh bas mere reference keliye kuch galat hoto crct karo bhaiya.... #include using namespace std; Void insert(vector &v, int val) { //base case if(v.size() ==0 || v[v.size()-1]
@kushalappaca5324
@kushalappaca5324 3 жыл бұрын
I implemented bubble sort in recursion.... Thanks to you sir..
@kumkumsharma5742
@kumkumsharma5742 4 жыл бұрын
Thanks for amazing explanation :) Kudos to learning recursion. Enclosed java Solution: package recursion; import java.util.ArrayList; import java.util.List; public class SortAnArray { public static void main(String[] args) { List l = new ArrayList(); l.add(1); l.add(0); l.add(5); l.add(2); l = sort(l); for(int i : l) System.out.println(i); } private static List sort(List l) { if(l.size() == 1) return l; //hypothesis Integer temp = l.get(l.size()-1); l.remove(l.size()-1); l = sort(l); //induction return l = insert(l, temp); } private static List insert(List l, int i) { if(l.size() == 0 || i >= l.get(l.size()-1)) { l.add(i); return l; } //hypothesis int val = l.get(l.size() - 1); l.remove(l.size()-1); l = insert(l, i); //induction l.add(val); return l; } }
@snigdhobhattacharya4697
@snigdhobhattacharya4697 4 жыл бұрын
This is one of the most conceptual videos I have ever seen. Kudos to you, man!
@creativegiant148
@creativegiant148 4 жыл бұрын
Bro i will never hesitate calling u the best teacher of recursion
@dimpleshah6538
@dimpleshah6538 3 жыл бұрын
I did got Time Limit Exceeded when I submitted the code for this approach on Leetcode. But the satisfaction lied in the fact that I understood recursion, implemented it and wrote the code on my own. Thanks a lot for an amazing content! :)
@sudarshansingh1072
@sudarshansingh1072 3 жыл бұрын
Recursion always need optimization..follow his DP series..
@adityakumarpandey5817
@adityakumarpandey5817 3 жыл бұрын
void insort(vector&v, int temp){ if(v.size()==0 || v[v.size()-1]< temp){ v.push_back(temp); return; } int value=v[v.size()-1]; v.pop_back(); insort(v,temp); v.push_back(value); } void sort(vector&v){ if(v.size()==0) return; int temp=v[v.size()-1]; v.pop_back(); sort(v); insort(v, temp); } int main() { vectorv; v.push_back(2); v.push_back(1); v.push_back(5); v.push_back(4); sort(v); for(int i=0; i
@shashankarora
@shashankarora Жыл бұрын
Aditya you really helped me to grasp the concept of recursion. I know recursion but after certain period of time I found myself in a position where I was not able to create a working code using recursion. Yes, I will continue to see your further lecture on recursion. I am sharing the code which you explained in this video, so that other people can visualize more by running code on terminal. Understand the recursion flow: #include using namespace std; void InsertElem(vector &v, int tmp) { cout
@123akash121
@123akash121 3 жыл бұрын
bro, you are god of programming
@SachinKumar-ut4gn
@SachinKumar-ut4gn 4 жыл бұрын
sir program k sath uska time complexity v discuss kr dia kro plz... rest all is awesome😍😍😍😍
@vishalc6658
@vishalc6658 4 жыл бұрын
What would be the time complexity of this problem? Anyone wants to guess?
@pleasesirmorevideos4684
@pleasesirmorevideos4684 4 жыл бұрын
@@vishalc6658 O(n^2) i guess
@shubhamrawat7895
@shubhamrawat7895 4 жыл бұрын
That's an insertion sort.. With recursion stack space complexity
@harmanpreetsingh8088
@harmanpreetsingh8088 3 жыл бұрын
God-Level Explanation
@sajankumarkar8237
@sajankumarkar8237 Жыл бұрын
I actually thought of another method to sort recursively and its relatively simpler. You work the other way round. you go sorting the array from the 1st element. So, the hypothesis becomes sort(a)-> a[0] + sort(a[1] to a[n-1]). Now in this case the base condition becomes the stage in which you hit the last element of the array cuz there are no more elements to sort. To form the induction you have the 1st and the 2nd element of the array. if the 1st elem > 2nd elem then before removing a[0] and sorting the rest of the array you swap a[0] and a[1] so that its sorted till the 1st position. void sortr(vector &a, int i){ if(i==a.size()-1) return; if(a[i]>a[i+1]) swap(a[i], a[i+1]); sortr(a, i+1); }
@annielouise1141
@annielouise1141 Жыл бұрын
it won't workk
@annielouise1141
@annielouise1141 Жыл бұрын
#include #include #include using namespace std; void sortr(vector &a, int i){ if(i==a.size()-1) return; if(a[i]>a[i+1]) swap(a[i], a[i+1]); sortr(a, i+1); } int main() { vectora={5,4,3,2,1}; sortr(a,0); for(auto it:a) cout
@sukdipkar8108
@sukdipkar8108 2 жыл бұрын
Your thinking is next level..highly appreciated
@sidharthpanda8557
@sidharthpanda8557 4 жыл бұрын
for those who are in need of Python code :- arr = [2, 3, 5, 4, 10, 3, 4, 5, 2, 1, -10, 0] class Sorting: def insert(self, arr, temp): if len(arr) == 0 or arr[len(arr) - 1]
@prativadas4794
@prativadas4794 3 жыл бұрын
this question may seem silly, but when i tried your code and made a change where i defined n=len(arr) and replace len(arr) with n, and i get the error: list index out of range. can you tell me why is that?
@adhirajmajumder
@adhirajmajumder 2 жыл бұрын
@@prativadas4794 class Sorting: def insert(self,arr,temp): n=len(arr) if n==0 or arr[n-1]
@rahulnagwanshi2348
@rahulnagwanshi2348 2 жыл бұрын
i have the same code but in gfg this in only passing two test cases :/
@deekshakarkaulia145
@deekshakarkaulia145 Жыл бұрын
hands down to your teaching skills🙌
@nishantgupta6902
@nishantgupta6902 Жыл бұрын
code: #include using namespace std; #include void insert(vector &v, int value){ if(v.size()==0 || v[v.size()-1]
@chetanraghavv
@chetanraghavv 10 ай бұрын
For anyone new here, if you don't want to solve the induction problem (inserting an element in a sorted array) using recursion, then you can use *Binary Search* to find its correct position in sorted array. This will boil down the time complexity from O(N^2) to O(NlogN) and space complexity from O(N^2) to O(N) (if we are considering recursive stack space in the solution, if we're not then it'll be O(1) for both cases)
@shreyasabd4974
@shreyasabd4974 3 жыл бұрын
Killer content. Man I regret being this late🥴
@deeproy7292
@deeproy7292 4 жыл бұрын
code for this in java(try to solve and then refer, also let me know if any error is there) import java.util.*; public class MyClass { public static void main(String args[]) { LinkedList ll = new LinkedList(); ll.add(2); ll.add(1); ll.add(-7); ll.add(5); ll.add(33); System.out.println(ll); sort(ll); System.out.println(ll); } static void sort(LinkedList ll){ if(ll.size() == 1) return; int lastEement = ll.removeLast(); sort(ll); insert(ll, lastEement); } static void insert(LinkedList ll, int element){ if(ll.size() == 0 || ll.getLast()
@aniketsthings
@aniketsthings 3 жыл бұрын
This was a tuff video, it means we are growing.🔥
@adarshsrivastava9428
@adarshsrivastava9428 3 жыл бұрын
"Increasing, Decreasing, Ascending, Descending Orders" are relative. That's a great point to note. Sometimes, we know these observations but neglect them solving the problem. Awesome Observation Sir...🙌🙌
@MilindGupta
@MilindGupta 3 жыл бұрын
Hey can you tell me in short what does hypothesis and induction means?
@sachinmaurya3259
@sachinmaurya3259 3 жыл бұрын
@@MilindGupta hypothesis is time when we write our main function and induction is where we decided how do we want to print our function example in "print the array from 1 to n" we solve it in two ways first printing from "1 to n" and then "n to 1" .... if you have watched both the video then you must have seen that just by changing the print position we were able to print it differently . So that's what the induction is Hope this help!
@nileshkumar9679
@nileshkumar9679 4 жыл бұрын
Happy Teachers days Bhaiya ❤️❤️❤️❤️❤️really you are one of best Teacher please make more video on graph and others stuff for placement
@abhilakhchaudhary5122
@abhilakhchaudhary5122 3 жыл бұрын
@abhilakhchaudhary5122
@abhilakhchaudhary5122 3 жыл бұрын
3
@ganeshkhirwadkar4127
@ganeshkhirwadkar4127 3 жыл бұрын
Excellent explanation with full patience !!!
@MilindGupta
@MilindGupta 3 жыл бұрын
Hey can you tell me in short what does hypothesis and induction means?
@ganeshkhirwadkar4127
@ganeshkhirwadkar4127 3 жыл бұрын
@@MilindGupta I will try my best to explain : Hypothesis - Call your function but with smaller valid input, you do it to make sure if your function works let suppose for N then it will work for N-1. Recursively it will work till that smallest valid input and gives you desired output. Induction - After your hypothesis returns you a valid output then you can logically do some other stuff in induction. Base Condition - This condition will ensure you reach that valid smallest input which you thought of and then you can start returning from there ! It is very crucial part in code, if you miss this then your code can end up in infinite recursive calls and can lead to memory overflow. Hope this will help to some extent otherwise @Aditya Verma is here to rescue :)
@simply_akh1l
@simply_akh1l 3 ай бұрын
Thanks, understood
@_HRhackjack
@_HRhackjack 2 жыл бұрын
Loved this, the flow 🌞
@_HRhackjack
@_HRhackjack 2 жыл бұрын
Thanks a lot...
@raviyadav2552
@raviyadav2552 5 ай бұрын
this really feels like magic
@azmirvali6205
@azmirvali6205 Жыл бұрын
When I see ur videos I will keep aside all my distraction calm that much intrest in ur vds
@viggicodes
@viggicodes Жыл бұрын
def insert(arr, temp): size = len(arr) # base - if arr is empty or we need to add in the end if size == 0 or arr[size -1 ] sorting the smaller array sort_arr(arr) # induction -> inserting the element in the right position insert(arr, temp)
@utsavseth6573
@utsavseth6573 Жыл бұрын
This is some next level content.
@imPriyansh77
@imPriyansh77 Жыл бұрын
One more possible iterative way is possible : We find the minimum element using 'for' loop & swap it with the 0th index. And then call the sort() function on the array of size = n - 1, where n is the size of the original array
@javi2082
@javi2082 4 жыл бұрын
Hi Aditya, your Videos are great and they are helping me a lot. Please keep on posting more content on your channel and interesting problems.
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thank you Vatsala, I will !!
@AnkushKumar-mk8ns
@AnkushKumar-mk8ns 4 жыл бұрын
Very very very informative and doubt clearing problem. Thank you aditya bhaiya😍
@lomeshdaheria9960
@lomeshdaheria9960 4 жыл бұрын
Thanks 😊😊 bhai itna sahi se samjhane ke liye
@shivam9201
@shivam9201 4 жыл бұрын
superb explaination.. I was able to write the perfect code in an single attempt.. Thanks for the lecture
@niteshchaurasia2053
@niteshchaurasia2053 4 жыл бұрын
Can you share the code here? I am getting some error
@GULLAPUDILIKITHBCE
@GULLAPUDILIKITHBCE 2 жыл бұрын
arr=[2,3,1,8,5] def sor(s,n): if n==0: return 1 #hypothesis sor(s,n-1) #induction a=max(s) print(a,end=" ") s.remove(a) sor(arr,5)
@GULLAPUDILIKITHBCE
@GULLAPUDILIKITHBCE 2 жыл бұрын
#updated as used recursion for finding max also:) arr=[2,3,1,8,5] def fun(a, i=0, largest=0): if i==0: largest=a[0] if i==len(a): return largest if largest
@mohit84604
@mohit84604 2 жыл бұрын
javascript code :- function insert(array, temp) { if (array.length == 0) { array.push(temp) return } else if (array[array.length - 1]
@RiteshYadav-rc1np
@RiteshYadav-rc1np 3 жыл бұрын
oh man you are genius thanx for this awesome explanation
@radium990
@radium990 2 ай бұрын
import java.util.ArrayList; import java.util.List; public class RecursiveSort { public static void recursiveSort(List array) { // Base condition: An array of size 0 or 1 is already sorted if (array.size()
@hemantmangwani1006
@hemantmangwani1006 4 жыл бұрын
31:29 Subscribe wagera karna he to kaar lena . He knows he is creating a difference.
@faizannasimhyder9011
@faizannasimhyder9011 2 жыл бұрын
Best part about your videos is that at least you try your best to explain...
@souravroy4701
@souravroy4701 4 жыл бұрын
bhai dp m ek topic add kardoge plzz..longest increasing subsequence..
@priyeshraj5910
@priyeshraj5910 3 жыл бұрын
Bhaiya please linked list ki series bhi le aao kaafi mushkil hoti hai.. Aap samjhate ho toh feel aa jati hai topic ki
@mansoords8857
@mansoords8857 2 жыл бұрын
Python Code: #a is array/list def sorta(a): if len(a)==1: return temp=a.pop() sorta(a) insert(a,temp) def insert(a,temp): if len(a)==0 or a[-1]
@jesmigeorge4936
@jesmigeorge4936 2 жыл бұрын
👍
@ashirbadbehera5544
@ashirbadbehera5544 4 жыл бұрын
please make a video graphs as well, your way of teaching is amazing
@deepanshuverma6237
@deepanshuverma6237 7 ай бұрын
Java code : public class SortArray { public static void main(String[] args) { List list = new ArrayList(Arrays.asList(3,2,1,4,5,6,7)); System.out.println(sort(list)); } public static List sort(List list) { if (list.size() == 1) return list; int temp = list.remove(list.size() - 1); sort(list); insert(list, temp); return list; } public static List insert(List list, int temp) { if (list.isEmpty() || list.get(list.size() - 1)
@prakashhaldar2425
@prakashhaldar2425 3 жыл бұрын
You are jitu bhaiya 🙌🏻 of kota factory
@gargprince1702
@gargprince1702 4 жыл бұрын
lghta h iss week my recursion series puree ho jayegyi pls bhaiya add some questions for us to solve in the end of video
@its__tj
@its__tj 4 жыл бұрын
i did the same thing, but in reverse, void arraySort(vector &arr, int n, int i){ // base condition if(i == n-1){ return ; } // hypothesis arraySort(arr, n, i+=1); // O(n) // induction if(arr[i-1] > arr[i]) swap(arr[i], arr[i-1]); // hypothesis arraySort(arr, n, i); // O(n) }
@madhuryareddy3994
@madhuryareddy3994 8 ай бұрын
class Solution: def sortArray(self, nums: List[int]) -> List[int]: self.sort(nums) return nums def sort(self,nums): if len(nums)==1: return temp = nums.pop() self.sort(nums) self.insert(nums,temp) def insert(self,nums,temp): if len(nums)==0 or nums[-1]
@VarunVishwakarma1
@VarunVishwakarma1 3 жыл бұрын
@AdityaVerma, Tree and graph lessons would be much appreciated. Recursion se to pyar ho hi gaya hai. Tree aur Grpah se bhi karwa do boss.
@karanraoexperiment
@karanraoexperiment 2 жыл бұрын
Working Code: #include #include using namespace std; void insertTemp(vector&v, int temp){ //base condition if(v.size()==0 || v[v.size()-1]>n; vectorarr; for(int i=0;i>d; arr.push_back(d); } sortArray(arr); for(int i=0;i
@abhigyansharma9108
@abhigyansharma9108 4 жыл бұрын
bhai bhot accha pdhaya .. Kuch smjh nhi arha tha kahan se start kru practise .. yh woh .... Maja aagya Bas please practise krne k lie Ques attach krdo sort of ki kahan ka h yh to yaaar Maja hi ajaye
@vikasvk9174
@vikasvk9174 4 жыл бұрын
Osm bhai bhot mst smjaya 👍👍
@SukhmanSinghSandhu
@SukhmanSinghSandhu Жыл бұрын
Very good explanation
@priyanshubharti5198
@priyanshubharti5198 4 жыл бұрын
The video explanation was very good🔥🔥
@kishan-d-gajjar
@kishan-d-gajjar 3 жыл бұрын
Just copying here in case anyone is wondering how to implement recursive on an array func main() { arr := []int{7, 5, 0, 1} sort(arr, len(arr)) fmt.Println("Sorted:", arr) } func sort(arr []int, n int) { if n = arr[pos-1] { arr[pos] = val return } t := arr[pos-1] insert(arr, val, pos-1) arr[pos] = t }
@himzp
@himzp 4 жыл бұрын
Dude switch back to DP playlist format. That suits your!.
@shreymehrotra5408
@shreymehrotra5408 4 жыл бұрын
kudos!!!!! very detail and beautifully explained.
@Weekly_Coder
@Weekly_Coder 4 жыл бұрын
your videos are awesome..these videos help me to improve my knowledge of recursion ...please make a videos on backtracking also.
@RaviYadav-t6c1y
@RaviYadav-t6c1y 6 ай бұрын
JavaScriptCode For Recursive SortArray:- function sortArray(arr, s, end) { if (s >= end) { return arr; } let lastVal = arr.pop(); sortArray(arr, s, end - 1); insertVal(arr, lastVal); } function insertVal(arr, lastVal) { if (arr.length === 0 || arr[arr.length - 1]
@muskangupta5873
@muskangupta5873 3 жыл бұрын
Thank you bhaiya for making these videos
@samirkhandekar4678
@samirkhandekar4678 10 ай бұрын
Thanks @Aditya Verma Java impl import java.util.ArrayList; import java.util.List; public class SortArray { void sort(List arr){ if(arr.size() == 1){ return; } int lastVal = arr.remove(arr.size()-1); sort(arr); insert(arr, lastVal); } void insert(List arr, int elem){ if(arr.isEmpty() || arr.get(arr.size()-1)
@thisisdenish
@thisisdenish 4 жыл бұрын
Great explanation
@subhamchoudhary9123
@subhamchoudhary9123 3 жыл бұрын
for O(1) space refer this : void SWAP(int &a,int &b){ int temp = a; a = b; b = temp; } void f(vector&arr,int N,bool swap){ if(N==-1 || (N==0 && !swap)) return ; if(swap) { if(arr[N]>arr[N+1]){ SWAP(arr[N],arr[N+1]); f(arr,N-1,true); } return; } f(arr,N-1,false); f(arr,N-1,true); }
@shreyash_17_
@shreyash_17_ 11 ай бұрын
coded on by understanding logic gives tle : is there any changes required ? class Solution { public: void insert(vector&nums,int ele){ // base case if(nums.size()==0 || nums[nums.size()-1]
@ashishk861
@ashishk861 4 жыл бұрын
bhai gajab hi explain kiya hai matlab...
@AmandeepSingh-ot6st
@AmandeepSingh-ot6st 4 жыл бұрын
Bhaiya time complexity bhi dicuss karliya karo 2min k liye ..... though these videos focuses on recursion
@vishakhachauhan6642
@vishakhachauhan6642 4 жыл бұрын
code in c: #include void insert(int *a,int temp,int size) { if(size==0|| a[size-1]
@surajprasad6012
@surajprasad6012 3 жыл бұрын
you are the best man
@Mind_Mechanics_
@Mind_Mechanics_ 2 жыл бұрын
Hi Aditya, I really enjoyed watching your video on [topic]. It was very informative and helpful. I have a suggestion that I think could make the video even more valuable to your viewers. Would you consider including some practice questions in the description of the video? This could be a great way for viewers to test their understanding of the material and reinforce their learning. It could also be helpful for those who are studying for a test or exam and want to see how well they can apply their knowledge. I think this would add an interactive and engaging element to the video, and I believe it would be beneficial for your viewers. Thanks for considering my suggestion! Best regards,MR_King_KK
@chandanbharti5207
@chandanbharti5207 Жыл бұрын
agree
@EngWorld-nr2ww
@EngWorld-nr2ww 4 жыл бұрын
Real education is not what to think , its how to think..that what is recursion (how to think) in coding , that what you taught here..
@mrinalmitra1
@mrinalmitra1 Жыл бұрын
Javascript code: const insert = (arr,temp) =>{ if(arr.length===0 || arr[arr.length-1] { if(arr.length===1){ return } let temp = arr.pop(); sort(arr); insert(arr,temp) } let arr = [1,5,0,2] sort(arr) console.log(arr) //[0,1,2,5]
@ps7072
@ps7072 4 жыл бұрын
12:14 Recursive leap of faith
@workandearnwithshubhi9050
@workandearnwithshubhi9050 3 жыл бұрын
Assasin's Creed ke side effects!!!!
@YashTrivedi-iq3ft
@YashTrivedi-iq3ft 8 ай бұрын
@@workandearnwithshubhi9050 nah its miles morals (spiderman)effect
@jyotijangid5243
@jyotijangid5243 4 жыл бұрын
Please include TOH and if you can add TC of the explained code at the end of the video it will be great.
@viditsinghbrahmania1476
@viditsinghbrahmania1476 4 жыл бұрын
Insert() wala part sahi se nhi samjhaya chief! Hypothesis likhne me dikkat ho rhi thi
@sarfarazalam6077
@sarfarazalam6077 3 жыл бұрын
Hypothesis : insert() will add the element in its correct position & resultant array will be sorted. One thing to observe that , insert() will always get sorted vector as its input.
@aftermath__7060
@aftermath__7060 5 ай бұрын
def insert_in_sorted_array(arr, n): # Base case: If n is the first element or the correct position is found if n
Reverse a Stack using Recursion
14:59
Aditya Verma
Рет қаралды 131 М.
Hypothesis-Induction-Base Condition
20:16
Aditya Verma
Рет қаралды 207 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Tower of Hanoi | Recursion
24:01
Aditya Verma
Рет қаралды 177 М.
Every Sorting Algorithm Explained in 120 minutes (full series)
1:57:33
Kuvina Saydaki
Рет қаралды 84 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,3 МЛН
ACCOUNTING THEORY FOR CLASS 11TH , B.COM, BCA, BBA.
50:02
CommerceMuni
Рет қаралды 58
Delete Middle Element of a Stack
16:49
Aditya Verma
Рет қаралды 114 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН