Quick Sort For Beginners | Strivers A2Z DSA Course

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

Комментарии • 490

  • @takeUforward
    @takeUforward  Год назад +185

    Let's march ahead, and create an unmatchable DSA course! ❤
    The worst case complexity will be O(N ^ 2) if we end up choosing the largest or smallest element as the pivot always. We will add this in the notes in the description. I missed this in the video.

    • @yashhokte1020
      @yashhokte1020 Год назад +10

      Yes striver , even i was thinking same that you didn't explain this thing , btw thankyou so much for this much crystal clear explaination ..

    • @anookimmidisetty2939
      @anookimmidisetty2939 Год назад +1

      Hi striver @takeUforward ,
      when are you going to release video solutions for string type problems and heaps?

    • @yaswanthmitta8983
      @yaswanthmitta8983 Год назад +10

      There is a minor mistake in your algo at 23:54 in while loop condition must be arr[i]

    • @teen_python_go9947
      @teen_python_go9947 8 месяцев назад +2

      Since, we are always choosing pivot to be the first element of the array, we can always avoid the O(n^2) case by pre-checking if the array is pre-sorted (with O(n) Time Complexity) and if it is not then only feed it into the quick sort function.

  • @yashsharma6112
    @yashsharma6112 Год назад +206

    I have to state it that "I tried to learn all sorting techniques various time. I learned but after a few days I forgot. But when you just added the real meaning of each sorting techniques. Like why it is called as selection sort and so on.... SO now I just remember their meanings and write the algorithm on my own." Thank you very much. Loved your teaching style

  • @deepanshuthakur140
    @deepanshuthakur140 Год назад +63

    I tried to learn this from every yt channel but striver is the one i got it from, respect++

    • @navagharkiran5769
      @navagharkiran5769 3 месяца назад +1

      then you haven't tried Abdul Bari

    • @deepanshuthakur140
      @deepanshuthakur140 3 месяца назад +2

      @@navagharkiran5769 sadly I did, its not that abdul bari is not good, its me who is dumb uk but striver made me understand it anyhow

    • @parshuramry1657
      @parshuramry1657 2 месяца назад

      @@navagharkiran5769 abdul bari is better for college academics but striver is for campus selections

  • @kingreja5894
    @kingreja5894 Год назад +16

    //for descending
    while (arr[i]>=pivot && i

  • @omkarsawant9267
    @omkarsawant9267 Год назад +34

    Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced.
    Time Complexity:
    Best Case: O(n log n) when the pivot choices consistently lead to balanced partitions.
    Average Case: O(n log n)
    Worst Case: O(n^2) when the pivot choices consistently lead to unbalanced partitions. However, with good pivot selection strategies (e.g., using the median element), this can be mitigated.
    Space Complexity:
    O(log n) auxiliary space for the recursive call stack in the best and average cases.
    O(n) in the worst case when the partitioning is highly unbalanced.
    Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced.
    Quick Sort tends to perform well in practice and is often faster than other O(n log n) algorithms, but its worst-case time complexity is worse than Merge Sort.
    Merge Sort's space complexity makes it less memory-efficient compared to some other sorting algorithms, but its stable performance and guaranteed O(n log n) time complexity in all cases make it a preferred choice for certain scenarios.
    Space Complexity:
    O(n) additional space is required for the temporary arrays during the merging process.
    It has a space complexity of O(n) due to the need for additional space for merging.

    • @Jinntechive
      @Jinntechive 8 месяцев назад +1

      Appreciate the effort you put for writing this comment 😇❤

    • @nayankhuman1043
      @nayankhuman1043 6 месяцев назад +1

      Thanks for the comment. i was looking for it.

    • @dreamer12n
      @dreamer12n 4 месяца назад

      Hey can you give me the code for pivot = median element pls??

    • @onlyone7209
      @onlyone7209 Месяц назад

      ​@@dreamer12nwhat kind of code do you want

    • @itsmehere8285
      @itsmehere8285 Месяц назад

      ​@@dreamer12nJust set pivot = (low + high)/ 2 or in a better way to deal with larger numbers make it low +(high -low)/2

  • @Kaushik846
    @Kaushik846 11 месяцев назад +24

    Probably one of the crisp and to the point explanation of quick sort algorithm available online!!

  • @ParasSharma-mf8or
    @ParasSharma-mf8or Год назад +46

    Thanks for this amazing lecture,this is my humble request please complete this course as soon as possible.

  • @ADITYASRIVASTAVA-hk3bw
    @ADITYASRIVASTAVA-hk3bw 13 дней назад

    00:06 - Quick sort is a sorting algorithm with time complexity of n log n and space complexity without using an extra temporary array.
    04:36 - Pick up elements and place them in their correct place in a sorted array.
    09:07 - The quick sort algorithm works by picking a pivot, placing it in its correct place, and recursively sorting the left and right arrays.
    13:48 - Sorting an array using the partition index
    18:43 - Quicksort algorithm explained in a simple way
    22:51 - The algorithm involves partitioning an array based on a pivot element.
    27:23 - Implementing the Quick Sort algorithm
    31:23 - Quick sort algorithm has a time complexity of n log n and a space complexity of O(1).

  • @FunkyPanda6263
    @FunkyPanda6263 Год назад +30

    1 video every 2 days...
    Seems TRUE ❣️

  • @Manishgupta200
    @Manishgupta200 Год назад +12

    Here is my Assignment question solution :
    #include
    using namespace std;
    int partition(vector &arr, int low, int high){
    int pivot = arr[low];
    int i = low;
    int j = high;
    while(i < j){
    while(arr[i] >= pivot && i = low + 1) j--;
    if(i < j) swap(arr[i], arr[j]);
    }
    swap(arr[low], arr[j]);
    return j;
    }
    void qs(vector& arr, int low, int high){
    if(low < high){
    int pIndex = partition(arr, low, high);
    qs(arr, low, pIndex - 1);
    qs(arr, pIndex + 1, high);
    }
    }
    int main(void){
    // vector v = {4, 3, 2, 1};
    vector v = {4, 3, 2, 1, 4, 7, 5, 6};
    int n = v.size();
    qs(v, 0, n-1);
    for(auto it : v) cout

  • @adityamaheshwari4250
    @adityamaheshwari4250 Год назад +20

    Really you make everything a cakewalk!
    Thank you so much sir, it takes a big heart to do such a lot for the community for free❤

  • @manish_mnnit
    @manish_mnnit Год назад +2

    For Descennding Order Sorting ->
    //Just Reverse the inequality sign in partition function :-
    #include
    int partition(vector&arr,int low,int high){
    int pivot =arr[low];
    int i=low ,j=high;
    while(i

  • @AdityaSharma-hs8os
    @AdityaSharma-hs8os Год назад +6

    please upload full course you are douing a good job bhaiyaaa ,you are really a honest teacher other youtubers who has million subscribers just make us fool on name of dsa course ,they just tell the problem and paste the soultion but you solve every aspect -f our doubt please cpmplete this and dont worry of views and watch time,time will come when everyone will know who is the best teacher on youtube for dsa

  • @tasneemayham974
    @tasneemayham974 Год назад +10

    CODE FOR DESCENDING (JAVA):
    public void quickSort(int[] arr, int low, int high){
    if(low low){
    j--;
    }
    if(i

    • @DineshKumar-pw7qb
      @DineshKumar-pw7qb Год назад

      When I try to run this code(using array), I getting no output and the code runs for infinite time. When I try with ArrayList, I am getting output.
      Explain why? This put me into severe headache

    • @tasneemayham974
      @tasneemayham974 Год назад

      @@DineshKumar-pw7qb Heyy!! You mean my code?
      Either way, can you send me the code you are working on. I want to try it. How about that? Maybe we can fix it together?

    • @DineshKumar-pw7qb
      @DineshKumar-pw7qb Год назад

      @@tasneemayham974bro are sure about your code is working well with array?

    • @tasneemayham974
      @tasneemayham974 Год назад

      @@DineshKumar-pw7qb Hey, mate! I copied my code, and yes it works with arrays. It doesn't give me errors or infinite loops, but...
      this line:
      while(arr[i] > pivot && i < high)
      I missed the =. I am so sorry. I should be:
      while(arr[i] >= pivot && i < high)
      Check it out now. But as I understand, the problem with your code is the array itself, yes? Not the output? If you want you can send the code. Because mine works well with array.
      P.S.: I will edit the original comment, and put the equal.

  • @alessandrocamilleri1239
    @alessandrocamilleri1239 Год назад +7

    Excellent explanation as usual. Thank you.
    I am posting the iterative version which should further save on recursion call stack space. I have used a queue as the data structure but stack works just as well.
    void quickSort (vector &nums)
    {
    int n = nums.size();
    queue q;
    q.push({0, n-1});
    int low, high, pivot, i, j;
    while(!q.empty())
    {
    low = q.front().first;
    high = q.front().second;
    q.pop();
    if (low >= high) continue;
    pivot = nums[low];
    i = low; j = high;
    while (j > i)
    {
    while (nums[i] pivot && j > 0)
    j--;
    if (j >= i)
    swap(nums[i], nums[j]);
    }
    swap (nums[low], nums[j]);
    q.push({low, j-1});
    q.push({j+1, high});
    }
    }

    • @balakrishnanr648
      @balakrishnanr648 Год назад

      So Yah u tried the iterative version of Quick Sort but still you are using the space what the Recursive func calls use in func call stack in the QUEUE FORM. O(logN) Queue takes as extra space.
      Like the point is Quick sort no matter what -> You can further optimize. Func Stk Space or in Iterative normal stack or queue space is needed.
      As we need to store it somewhere -> what are the next range of places where it is unsorted.
      Either use the system's func call stack or make ur own.

  • @parthmangalkar
    @parthmangalkar Год назад +4

    Understood!
    Thank you!! You are the best!
    Thanks a lot for making this DSA playlist! It really is helping me a lot!

  • @tanmaykarmakar6224
    @tanmaykarmakar6224 Год назад +22

    Quick sort in Descending order-(PYTHON)
    arr=[25,1,8,7,32,2,5]
    def piviot(arr,high,low):
    piviot=arr[high]
    i=high
    j=low
    while(i=piviot and i

    • @sumitapathak2900
      @sumitapathak2900 Год назад +6

      Hey I haven't done a dryrun of your code but as i has index of high how can in increment in the while loop?

    • @jayaveersai1446
      @jayaveersai1446 Год назад +1

      yes make sense and have to chnage the while (i

    • @nirmaljyotibiswas752
      @nirmaljyotibiswas752 2 месяца назад

      shouldn't it be while(i > j) ?

  • @pranshuatrey
    @pranshuatrey Год назад +4

    This is gold... Plz keep doing this..

  • @isaacreyes7563
    @isaacreyes7563 4 месяца назад +1

    Damn, I have been looking at sort, recursion, etc forever. I was first confronted with merge/quicksort back in 2019. Been looking at them from various other sources over the years but nobody ever explained it like you do. You are absolutely amazing at this stuff. Idk where you are in life but I hope you go onto make amazing things because someone with this in depth knowledge shouldn't be stuck teaching!

    • @tanmayjivnani865
      @tanmayjivnani865 4 месяца назад

      Don't worry he is working at Google. Doing great in life :)

  • @shubhamagarwal1434
    @shubhamagarwal1434 4 месяца назад +9

    #Free Education For All...... # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.......

  • @ShivamGupta-xw6gh
    @ShivamGupta-xw6gh Год назад +1

    best explanation of quick sort on youtube

  • @animeshmishra6280
    @animeshmishra6280 Год назад +27

    how do you know which doubts are going to come in my mind. GREAT LECTURE SIR 🔥

    • @edisane8763
      @edisane8763 Год назад +6

      Because once he was also in the same place as we are now and he worked hard to reach this point now he is helping us

  • @SharathS-s9i
    @SharathS-s9i 3 месяца назад

    for the assigment problem just change the condition while (i < j) {
    while (arr[i] > pivot && i

  • @darkelixir2517
    @darkelixir2517 Год назад +2

    Understood, will be a quick way to remember the algorithm, well taught!! Thanks

  • @makerNg1817
    @makerNg1817 Год назад +2

    it's very understandable way you teach. thank you for this amazing lecture

  • @DeepakKumar-xj4ul
    @DeepakKumar-xj4ul 9 месяцев назад

    for decreasing Quick Sort:-
    int partition(vector &arr, int low, int high) {
    int pivot = arr[low];
    int i = low;
    int j = high;
    while (i < j) {
    while (arr[i] >= pivot && i = low + 1) {
    j--;
    }
    if (i < j) {
    swap(arr[i], arr[j]);
    }
    }
    swap(arr[low], arr[j]);
    return j;
    }
    void quickSort(vector &arr, int low, int high) {
    if (low < high) {
    int pIndex = partition(arr, low, high);
    quickSort(arr, low, pIndex - 1);
    quickSort(arr, pIndex + 1, high);
    }
    }
    vector sortArray(vector &arr) {
    quickSort(arr, 0, arr.size() - 1);
    return arr;
    }

  • @ArunKumar-sk9jl
    @ArunKumar-sk9jl 5 месяцев назад

    A great man with the best of the best teaching skills and a kind attitude to make it free is awesome ❤

  • @sugarfreecode
    @sugarfreecode Год назад +1

    Quick Sort in Descending Order (C++):
    int partitionArray(int input[], int start, int end) {
    int pivot = input[start];
    int i = start;
    int j = end;
    while (i < j) {
    while (input[i] >= pivot && i < end) {
    i++;
    }
    while (input[j] < pivot && j > start) {
    j--;
    }
    if (i < j) {
    int temp = input[i];
    input[i] = input[j];
    input[j] = temp;
    }
    }
    input[start] = input[j];
    input[j] = pivot;
    return j;
    }
    void quickSort(int input[], int start, int end) {
    if (start >= end) return;
    int partition = partitionArray(input, start, end);
    quickSort(input, start, partition - 1);
    quickSort(input, partition + 1, end);
    }

  • @rayyanrahim7413
    @rayyanrahim7413 Год назад +2

    love from pakistan we need these type of legend to teach progamming

  • @keshariaman
    @keshariaman Год назад +5

    Thanks a lot for Quick Short. Feels easier to understand 🥰

  • @mityamkumar1158
    @mityamkumar1158 Год назад +3

    Understood.... 💯💯 Excited for Arrays playlist❤

  • @active_akasa8429
    @active_akasa8429 Год назад +3

    striver you are the best out of best....this tutorial is just amazing and you are like god for us A big thank you so much for your effort 🙂

  • @WellbeingWarior
    @WellbeingWarior 4 месяца назад

    Quick sort in Descending order in Python:
    def qS(array):
    if len(array) pivot]
    return qS(elm_grater_than_pivot) + elm_equal_pivot + qS(elm_less_than_pivot)

  • @nikhild.20
    @nikhild.20 Год назад

    Code for descending order :-
    #include
    int fn(vector &arr,int low, int high){
    int pivot = arr[low];
    int i = low;
    int j = high;
    while(i=pivot && i

  • @ahssanakhtar5746
    @ahssanakhtar5746 7 месяцев назад

    Excellent content about DSA .I am follwing you A-Z coarse and improve my self in DSA day by DSA Thanks for making such a amazing content

  • @Manoj_IIC-Admin
    @Manoj_IIC-Admin Год назад +22

    at time 23:52 it should be pivot not ar[pivot] thanks bhaiya

  • @samarthpai5359
    @samarthpai5359 3 месяца назад

    Understood sir.
    For descending order:
    int partitionFunction(int arr[], int low, int high){
    int i = low, j = high, temp;
    int pivot = arr[low];
    while(ipivot and i

  • @zyzzbrah9429
    @zyzzbrah9429 6 месяцев назад +1

    int partition (int arr[], int low, int high)
    {
    int p=arr[low];
    int i=low,j=high;
    while(i=p && i

    • @shailesh3348
      @shailesh3348 6 месяцев назад

      I also completed 2 steps can we connect?

  • @Abhishek-vc5bp
    @Abhishek-vc5bp 4 месяца назад +1

    For Decending order
    #include
    using namespace std;
    int pick_place_pivot(int arr[],int low,int high){
    int pivot=arr[low];
    int i=low,j=high;
    while(i= pivot && i=low+1) j--;
    if(i> n;
    int arr[n];
    for(int i=0;i> arr[i];
    quick_sort(arr,0,n-1);
    for(int i=0;i

  • @abdulwahabshaik1686
    @abdulwahabshaik1686 Год назад

    Understanding everything u r teaching to us u r magician striver

  • @ShivanshSingh-os5nd
    @ShivanshSingh-os5nd 4 месяца назад +7

    16 Aug 2024, 2:00 a.m.🎯🔥

  • @tusharkhandave374
    @tusharkhandave374 Год назад

    Thanks for giving this content for free it helps me a lot

  • @CodeBoost8375
    @CodeBoost8375 Год назад +4

    Thanks for recursive effort brother.And till now all your lectures are absolutely awesome 🔥🔥

  • @madhumithaakula7666
    @madhumithaakula7666 Месяц назад +1

    Thank You anna because of u I have learned something new today🙂

  • @gurudev8543
    @gurudev8543 Год назад +3

    Best explanation ever ❤️❤️❤️
    Thanks bhaiya

  • @diversestream66
    @diversestream66 5 месяцев назад

    for descending order
    const partition = (arr, low, high) => {
    let pivot = arr[low];
    let i = low;
    let j = high;
    while (i < j) {
    while (arr[i] >= pivot && i < high) {
    i++;
    }
    while (arr[j] low) {
    j--;
    }
    if (i < j) {
    let temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    }
    let temp = arr[low];
    arr[low] = arr[j];
    arr[j] = temp;
    return j
    };
    const quickSort = (arr, low, high) => {
    if (low < high) {
    let partitionIndex = partition(arr, low, high);
    quickSort(arr, low, partitionIndex - 1, high);
    quickSort(arr, partitionIndex + 1, high);
    }
    console.log(arr)
    };

  • @twopiebytwo
    @twopiebytwo Год назад

    Quicksort in python.
    def partition(L,lower,upper):
    i=lower
    pivot=L[lower]

    for j in range(lower+1,upper+1):
    if(L[j]

  • @rajkumarvb5197
    @rajkumarvb5197 Год назад +1

    Manhhhh 🥵, you are awesome. I can see the effort you are putting in! Thanks a lot! ❤

  • @meshkatuddinahammed
    @meshkatuddinahammed Год назад

    Can't thank you more. Great lectures. Appreciate it.

  • @student_03
    @student_03 3 месяца назад

    checking for out of bounds like this makes it simple and natural
    while (i pivot) {
    j--;
    }

  • @cinime
    @cinime Год назад +1

    Understood! Super amazing explanation as always, thank you very much!!

  • @satishsgm0157
    @satishsgm0157 Год назад +1

    class Solution {
    public static void quickSort(int[] arr,int low,int high) {
    if(low

  • @scoc55vora15
    @scoc55vora15 Год назад

    Best , Detailed and Crisp

  • @shubhamsahu492
    @shubhamsahu492 Месяц назад

    Your explanations are the best 💕👌👌

  • @OmPrakash-268
    @OmPrakash-268 3 месяца назад

    awesom explanation , love it learning DSA .

  • @AniketSingh-gm9nh
    @AniketSingh-gm9nh 5 месяцев назад

    u r just amazing. keep educating man u r blessing for us.❤

  • @AbhishekKumar-cd4gg
    @AbhishekKumar-cd4gg Год назад

    // for descending order
    just we have to do the tweaks in the how we are selecting elements when which we are stopping when we are finding element smaller in left and stop when we find the element greater the pivot then we just we swap it
    than it goes in the recursion stack
    public class Quicksort {
    static int partiton(int arr [] , int low , int high ){
    int pivot = arr[low];
    int i= low;
    int j = high;
    while (i < j ) {
    while (arr[i] >= pivot && i = low + 1 ) {
    j--;
    }
    if(i < j ){
    int temp = arr[i];
    arr[i] = arr [j];
    arr[j] = temp;
    }
    }
    int temp = arr[j];
    arr[j] = arr[low];
    arr[low] = temp;
    return j ;
    }
    static void quicksort(int arr [] , int low , int high){
    if(low < high ){
    int PartionIndex = partiton(arr,low,high) ;

    quicksort(arr, low , PartionIndex-1);
    quicksort(arr, PartionIndex+1 , high);
    }

    }
    public static void main(String[] args) {
    int arr [] = {10, 80, 30, 90, 40};
    int n = arr.length-1;
    quicksort(arr, 0, n);
    for (int i : arr) {
    System.out.print(i + " ");
    }
    }
    }

  • @rajkumarvb5197
    @rajkumarvb5197 Год назад

    Java Code:
    public class QuickSort {
    public static void main(String[] args) {
    int [] nums = {3,4,2,1,5,0};
    quickSort(nums, 0, nums.length -1);
    for(int element : nums){
    System.out.print(element + " ");
    }
    }
    public static void quickSort(int[] nums, int low, int high) {
    if(low >= high) return ;
    int partitionIndex = partition(nums,low,high);
    quickSort(nums,low,partitionIndex-1);
    quickSort(nums,partitionIndex +1, high);
    }
    public static int partition(int[] nums, int low , int high){
    int pivot = nums[low];
    int i = low, j = high;
    while(i < j ){
    while(i pivot) j--;
    if(i < j) swap(nums, i, j);
    }
    swap(nums,low,j);
    return j ;
    }
    public static void swap(int [] nums, int i , int j){
    int temp = nums[i];
    nums[i] = nums[j];
    nums[j]= temp;
    }
    }

  • @subhadeepghosh2813
    @subhadeepghosh2813 Год назад +1

    Kaha se sikha hai aise padana?
    vai koi vi nahi hai tumhare jaisa.
    Maza aa gaya

  • @venkatesasrikanthdhulipala9486
    @venkatesasrikanthdhulipala9486 Год назад +2

    //Code for reversing the sorted array using quick sort
    // feel free to review
    class ReverseSortedArray {
    public static void main(String[] args) {
    int[] arr = {1,3,5,2,7,6,8,10};
    Qsort(arr,0,arr.length - 1);
    for(int i :arr){
    System.out.print(i + " ");
    }
    }
    public static void Qsort(int[] arr,int low,int high){
    if(low < high){
    int partition = parrtitionArrray(arr,low,high);
    Qsort(arr,low,partition - 1);
    Qsort(arr,partition + 1,high);
    }
    }
    static int parrtitionArrray(int[] arr,int low,int high){
    int val = arr[low];
    int i = low,j = high;
    while(i < j){
    while(val = low - 1){
    j--;
    }
    if(i < j){
    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    }
    int temp = arr[low];
    arr[low] = arr[j];
    arr[j] = temp;
    return j;
    }
    }

  • @SwatiSingh-ys6hm
    @SwatiSingh-ys6hm Год назад

    Damn it, i have learnt sorting algorithms a lot of times, but i aways manage to somehow forget.But after seeing this video now i understand it in so much more detail and depth which i earlier didn't even notice. thanks you soo much striver !

  • @yashlakade179
    @yashlakade179 12 дней назад +1

    Thanks Striver :)

  • @pradeep6635
    @pradeep6635 7 месяцев назад

    understood Bhayya.The best explanation in youtube😎

  • @guttulavybhav1030
    @guttulavybhav1030 7 месяцев назад

    descending order code:
    from typing import List
    def partition(arr,low,high) -> int:
    r=arr[low]
    i=low
    j=high
    while(i=r and i

  • @hareshnayak7302
    @hareshnayak7302 8 месяцев назад

    Understood,Thanks striver for this amazing video.

  • @bonammadankumar681
    @bonammadankumar681 9 месяцев назад

    You rocks the DSA

  • @shivamcanada
    @shivamcanada 4 месяца назад

    very well explained brother appreciate your efforts

  • @rohanraj2604
    @rohanraj2604 Год назад

    Crystal clear bhaiya 😍

  • @rishabhkumar-qs3jb
    @rishabhkumar-qs3jb 7 месяцев назад +1

    Excellent explanation :)

  • @soumelee5661
    @soumelee5661 Год назад

    Awesome explanation! TYSM for the videos

  • @ProgrammerSalman031
    @ProgrammerSalman031 5 месяцев назад +1

    public:
    // Function to sort an array using quick sort algorithm in descending order.
    void quickSort(int arr[], int low, int high)
    {
    if (low < high) {
    int pIndex = partition(arr, low, high);
    quickSort(arr, low, pIndex - 1);
    quickSort(arr, pIndex + 1, high);
    }
    }
    public:
    int partition(int arr[], int low, int high)
    {
    int pivot = arr[low];
    int i = low;
    int j = high;
    int temp;
    while (i < j) {
    while (arr[i] >= pivot && i = low + 1) {
    j--;
    }
    if (i < j) {
    temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    }
    temp = arr[low];
    arr[low] = arr[j];
    arr[j] = temp;
    return j;
    }
    }

  • @RANJANKUMARPANDIT-fd9ox
    @RANJANKUMARPANDIT-fd9ox 6 месяцев назад +1

    //for Descending order
    #include
    using namespace std;
    int partition(vector &arr, int low, int high){
    int pivot = arr[low];
    int i = low;
    int j = high;
    while(i= pivot && i n;
    // int arr[n];
    // for (int i = 0; i < n; i++)
    // {
    // cin >> arr[i];
    // }
    vector arr = { 3, 9, 4,1};
    int n = arr.size();
    vector result= quick_sort(arr, n);
    for (int i = 0; i < n; i++)
    {
    cout

  • @yhbarve
    @yhbarve Год назад +1

    Understood bhaiya! Thank you

  • @Gurunat16
    @Gurunat16 5 месяцев назад +4

    26:58 That will be |1 3 2| 4. Right?

  • @rohitmanohar2733
    @rohitmanohar2733 Год назад

    Quick Sort Descending order : java Code
    private static void sort(int arr[],int low, int high) {
    if(low

  • @sid17_cgdyt
    @sid17_cgdyt Год назад +2

    // condition i

    • @ShawnGrant-t9k
      @ShawnGrant-t9k 4 месяца назад

      Yes you are right, it should evaluate this first as a precaution.

  • @Yash75585
    @Yash75585 6 месяцев назад

    home work question (to print in decreasing order)-
    #include
    using namespace std;
    int partition(vector &arr, int low, int high){
    int pivot=arr[low];
    int i=low;
    int j=high;
    while(i=arr[low] && i

  • @studynewthings1727
    @studynewthings1727 Год назад

    # code for reverse sorted i.e. descending sort
    def quickSort(self,arr,low,high):
    if low < high:
    p_index = self.partition(arr,low,high)
    self.quickSort(arr,low,p_index-1)
    self.quickSort(arr,p_index+1,high)

    def partition(self,arr,low,high):
    # modified
    pivot = arr[high]
    i = low
    j = high
    while i < j:
    #modified
    while arr[i] >= pivot and i = low+1:
    j -= 1
    if i < j:
    arr[i], arr[j] = arr[j], arr[i]
    arr[low], arr[j] = arr[j],arr[low]
    return j

  • @Kirito045
    @Kirito045 Год назад

    Understood
    Striver on TOP!

  • @sakshamtyagi2969
    @sakshamtyagi2969 10 месяцев назад

    Completely Understood 👍👍

  • @sanskargour6673
    @sanskargour6673 7 месяцев назад +1

    C++ Code :
    #include
    using namespace std;
    int partition (vector& arr, int low, int high){
    int i = low;
    int j = high;
    int pivot = arr[low];
    while(i low) j--;
    if(i= high){
    return;
    }
    int pt = partition(arr,low,high);
    quickSort(arr,low,pt-1);
    quickSort(arr,pt+1,high);
    return;
    }
    int main() {
    vector arr={4,2,8,5,6,7,0,1,3,9};
    quickSort(arr,0,9);
    for(auto i:arr){
    cout

  • @Hipfire786
    @Hipfire786 8 месяцев назад

    understood everything sir so far all sorting techniques

  • @preetisahani5054
    @preetisahani5054 Год назад +1

    Its a great video, but you should also explain the cases where complexity for quick sort can result to O(n^2) in the case where all elements of array are same and when array is already sorted, in those cases partition will always be 1, n-1.

    • @krishnendughosh2368
      @krishnendughosh2368 Год назад

      sorted or even if sorted in descending order complexity will be n^2

  • @nyx1284
    @nyx1284 3 месяца назад

    by the way, there exist some examples where the code shown can return in out of vector subscript error because the partition index might be returned as 0 and when we try to access pIndex-1 it will of course crash. so put an extra little check where the code just returns if pIndex is 0.

  • @sonalikharwar4269
    @sonalikharwar4269 Год назад +5

    Instead of 3,2,1 it should be 1,3,2 coz we have done swapping b/w 4 & 1 like swap(arr[low], arr[j]) right ?

  • @manavsingh5919
    @manavsingh5919 Год назад

    Understood sir.....u r the best👍💞

  • @AyushSur-s3s
    @AyushSur-s3s 11 месяцев назад +1

    Java code for QuickSort in descending order with comments
    public class Quick_Sort {
    //descending
    public static int pivotloc(int []arr,int low,int high){
    int pivot=low; //choosing arr[low] as pivot element
    //greater or equal on left, less on right
    int i=low,j=high,t;
    while(i=arr[pivot] && i

  • @mbkbishwokarma
    @mbkbishwokarma Год назад

    After checking all lectures on internet...None has explained better than you

  • @Gcoder18
    @Gcoder18 Месяц назад

    nice way of explaination

  • @yamini436
    @yamini436 Год назад +1

    little tweaks in partition function for descending case
    int partition (vector &arr, int low, int high){
    int pivot = arr[low];
    int i = low;
    int j = high;
    while (i=pivot && i

  • @centrotv1056
    @centrotv1056 5 месяцев назад

    class Solution
    {
    public:
    //Function to sort an array using quick sort algorithm.
    void quickSort(int arr[], int low, int high)
    {
    if(low

  • @AbdullahKhan-et6qo
    @AbdullahKhan-et6qo Год назад

    Was eagerly waiting for your videos 🙌

  • @KrishnaSagar02
    @KrishnaSagar02 Год назад

    Reverse Sort need only 2 changes from original code :
    while(arr[i]>=pivot && i

  • @poojaraman6663
    @poojaraman6663 5 месяцев назад

    Understood...thank u sir🙂

  • @Pawankumar-i8c
    @Pawankumar-i8c 2 месяца назад

    thank you so muchbhiaya for this masterpiece

  • @THE-MYSTIC
    @THE-MYSTIC Год назад +1

    Thanks striver this video helped me ❤

  • @ankit-yj7hk
    @ankit-yj7hk 6 месяцев назад

    understand bhaiya !!!
    thank uh so much

  • @yashpandey7
    @yashpandey7 6 месяцев назад

    understood , Step 2 completed :)

  • @MohammadEhshan-ve6uz
    @MohammadEhshan-ve6uz 5 месяцев назад

    Everything will be same , only we have to do some changes in partition function to get array in decreasing order:
    int decendingPartition(int arr[],int low,int high){
    int pivot=arr[low];
    int i=low;
    int j=high;
    while(i=pivot && i

  • @himanshupatel1053
    @himanshupatel1053 6 дней назад

    FYI - Quick sort takes O(n^2) in worst case so obviously merge is best sorting algorithm out there.