{"id":11620,"date":"2023-01-10T07:01:54","date_gmt":"2023-01-10T07:01:54","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11620"},"modified":"2023-04-17T12:39:32","modified_gmt":"2023-04-17T12:39:32","slug":"quick-sort-program-in-java","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/","title":{"rendered":"Quick Sort Program in Java"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\" alt=\"\" \/><\/p>\n<p>Quick Sort program in Java has been introduced because it is an efficient sorting algorithm that can quickly sort large datasets. It has a time complexity of O(n log n) and is widely used in many programming applications.<\/p>\n<h2>Introduction to Quick Sort Program in Java<\/h2>\n<p>Quick Sort program in Java is a fast and efficient sorting algorithm in Java, which works by recursively dividing and sorting sub-arrays. It selects a pivot element and then partitions the array based on whether elements are greater or lesser than the pivot.<\/p>\n<h2>Quick Sort Algorithm in Java<\/h2>\n<p>Here,is the quick sort algorithm in Java. Consider the array shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221581-Quick%20Sort%20Program%20in%20Java1.png\" alt=\"\" \/><\/p>\n<p>Here, We have to partition the given array. Partitioning an array around a value pivot means that we arrange the array in such a way that the pivot is in its sorted position. And we don\u2019t consider the rest of the array. The pivot element will be at a position in which it will be if we sort an array. This means that the elements before the pivot element i.e. the elements to the left of the pivot will be smaller than the pivot and the elements after the pivot element i.e. the elements to the right of the pivot element will be larger than the pivot.<\/p>\n<p>For instance, consider the array shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221581-Quick%20Sort%20Program%20in%20Java2.png\" alt=\"\" \/><\/p>\n<p>Here 10 is at its sorted position. The elements to the left of the value 10 are smaller than 10 and the elements to the right of element 10 are larger than 10. Their respective order does not matter i.e. we can see that the left part is not sorted and the right part is also not sorted itself. <\/p>\n<p>So, let\u2019s come back to our example, we have the initial condition as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221581-Quick%20Sort%20Program%20in%20Java3.png\" alt=\"\" \/><\/p>\n<p>The pivot value here is 5. We have assumed that the pivot will always be the last element of the array. The partitioning technique in which the last element of the array is always chosen as the pivot is called the <strong>Lomuto partition.<\/strong><\/p>\n<p>There are 2 pointers l and r at the top of the first element. The ticks below every element represent that all the elements are unexplored at the current moment. See, to partition the array, we have to divide the array into 2 regions, one where the elements will be smaller than the pivot and the other where the elements will be larger than the pivot. However, currently, all the elements are divided into 3 regions. <\/p>\n<p>The 3 regions are; <strong>greater than the pivot, less than the pivot, and unexplored elements.<\/strong> Currently, there are no elements in the first 2 regions and all the elements are in the unexplored region. As we go on and move the pointers l and r, we will keep on adding the elements to one of the first 2 regions.<\/p>\n<p>If the number of elements in the array is N, the following image shows the ranges of all the 3 regions.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221592-Quick%20Sort%20Program%20in%20Java4.png\" alt=\"\" \/><\/p>\n<p>So, we have to work according to this. Let\u2019s see the first step shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221593-Quick%20Sort%20Program%20in%20Java5.png\" alt=\"\" \/><\/p>\n<p>We were at element 7 and pivot = last element = 5. So, 7 is greater than 5. We know that the region for the elements greater than the pivot is from l to r-1. So, l=0 which is correct as 7 is at index 0. However, r-1=0-1=-1. This is incorrect. So, to validate the range l to r-1, we need to move r one step forward. So, we do r++. <\/p>\n<p>Now r is at index 1. So, we can see that the range for the elements greater than the pivot has been satisfied. Also, the other 2 ranges have automatically been validated as the unexplored region is now from index 1 onwards and less than equal to pivot is currently a non-existing region after exploring just 1 element.<\/p>\n<p>With this, we have also come to the conclusion that if arr[r] &gt; pivot, we do r++.<\/p>\n<p>Next, we have element 9. So, perform the same operation and r will be at index 1. (Do it yourself to get the concept clearly).<\/p>\n<p>Now, we are at index 2 i.e. element 4. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221673-Quick%20Sort%20Program%20in%20Java6.png\" alt=\"\" \/><\/p>\n<p>As shown above, the previous 2 elements have now come under the &gt;pivot region. Element 4 is, however, less than the pivot i.e. 5. So, to validate the ranges mentioned above, we will swap the elements at the l and r indices and increment both l and r as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221674-Quick%20Sort%20Program%20in%20Java7.png\" alt=\"\" \/><\/p>\n<p>Now, we can see that the ranges are validated automatically. So, we have come to the conclusion that if arr[r] &lt; pivot, we swap arr[l] and arr[r] and do l++ and r++.<br \/>\nSo, you can follow the same steps yourself for the remaining array. The array after r goes out of bound is shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221681-Quick%20Sort%20Program%20in%20Java8.png\" alt=\"\" \/><\/p>\n<p>So, we can see that the array has been partitioned. Throughout the partition procedure, the left pointer or l denotes the first element of the &gt;pivot region and the right pointer or r denotes the first element of the unexplored region.<\/p>\n<p>Now that we have understood the complete partition procedure, let us write the code for the same.<\/p>\n<h3>Partition Procedure Program in Java<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11579 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11579 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11579 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11579 .wpsm_nav-tabs > li.active > a, #tab_container_11579 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11579 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11579 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11579 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11579 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11579 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11579 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11579 .wpsm_nav-tabs > li > a:hover , #tab_container_11579 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11579 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11579 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11579 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11579 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11579 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11579 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11579 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11579 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11579 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11579 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11579 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11579\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11579\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11579_1\" aria-controls=\"tabs_desc_11579_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11579\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11579_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">import java.util.*;\r\n\r\npublic class Main {\r\n    \r\n    public static void swap(int[] arr, int i, int j) {\r\n        int temp = arr[i];\r\n        arr[i] = arr[j];\r\n        arr[j] = temp;\r\n    }\r\n    \r\n    public static void partition(int[] arr, int pivot) {\r\n        int l = 0;\r\n        int r = 0;\r\n        \r\n        while(r &lt; arr.length) {\r\n            if(arr[r] &gt; pivot) r++;\r\n            else {\r\n                swap(arr,l,r);\r\n                l++;\r\n                r++;\r\n            }\r\n        }\r\n    }\r\n    \r\n    public static void display(int[] arr) {\r\n        \r\n        for(int i=0;i&lt;arr.length;i++) {\r\n            System.out.print(arr[i] + \" \");\r\n        }\r\n    }\r\n    \r\n    public static void main(String[] args) {\r\n        int[] arr = {7,9,4,8,3,6,2,5};\r\n        partition(arr,5);\r\n        display(arr);\r\n    }\r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11579 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11579 a\"),jQuery(\"#tab-content_11579\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Time Complexity of Partition Procedure:<\/strong> The time complexity of the partition procedure is O(N) as we have to traverse the entire array.<\/p>\n<p><strong>Space Complexity of Partition Procedure:<\/strong> The auxiliary space is O(1) as we have not used any extra space. <\/p>\n<p>So, now that we have understood the partition procedure completely, we can now write the quick sort program in Java.<\/p>\n<h2>Quick Sort Program in Java<\/h2>\n<p>The quick sort algorithm in Java is based on the partitioning technique. The partition of an unsorted array is that we get an element at its sorted position. And then, we send the array from the left of the partition index (the sorted position for the pivot element of the previous partition) to be partitioned and then we send the array to the right of the partition index also to get partitioned. We need to do this recursively till the array gets sorted.<\/p>\n<p>For instance, consider the array shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221855-Quick%20Sort%20Program%20in%20Java9.png\" alt=\"\" \/><\/p>\n<p>After partitioning the array for the first time, we get the pivot at index 2. Then, we will send the 2 arrays for partition. The recursion tree for the same is shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221861-Quick%20Sort%20Program%20in%20Java10.png\" alt=\"\" \/><\/p>\n<p>The partitioning technique that we have used in the above quicksort algorithm is called Lomuto\u2019s partition. In Lomuto\u2019s partition technique, both the pointers left and right start from index 0 and move in the same direction.<\/p>\n<p>There is another popular partitioning technique called <strong>Hoare\u2019s partition.<\/strong> In Hoare\u2019s partition, the left and right index start from the start and the end index of the array respectively, and move in opposite directions i.e. towards each other. <\/p>\n<p>Hoare\u2019s partition can be considered slightly optimized than Lomuto\u2019s partition because it caused 3 times fewer swaps. However, the average and the worst-case time complexity of the quicksort algorithm remain the same using any of the 2 partition techniques.<\/p>\n<p>Now that we have understood the quicksort algorithm, let us write the quick sort program in Java.<\/p>\n<p><strong>Quick Sort Program in Java<\/strong><br \/>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11580 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11580 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11580 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11580 .wpsm_nav-tabs > li.active > a, #tab_container_11580 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11580 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11580 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11580 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11580 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11580 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11580 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11580 .wpsm_nav-tabs > li > a:hover , #tab_container_11580 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11580 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11580 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11580 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11580 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11580 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11580 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11580 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11580 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11580 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11580 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11580 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11580\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11580\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11580_1\" aria-controls=\"tabs_desc_11580_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11580\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11580_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">import java.util.*;\r\n\r\npublic class Main {\r\n    \r\n    public static void swap(int[] arr, int i, int j) {\r\n        int temp = arr[i];\r\n        arr[i] = arr[j];\r\n        arr[j] = temp;\r\n    }\r\n    \r\n     public static void quickSort(int[] arr, int lo, int hi) {\r\n    \/\/write your code here\r\n    \r\n    if(lo &gt; hi) return;\r\n    \r\n    int pivot = arr[hi];\r\n    int partitionIndex = partition(arr,pivot,lo,hi);\r\n    \r\n    quickSort(arr,lo,partitionIndex -1);\r\n    quickSort(arr,partitionIndex + 1,hi);\r\n  }\r\n\r\n  public static int partition(int[] arr, int pivot, int lo, int hi) {\r\n    int i = lo, j = lo;\r\n    while (i &lt;= hi) {\r\n      if (arr[i] &lt;= pivot) {\r\n        swap(arr, i, j);\r\n        i++;\r\n        j++;\r\n      } else {\r\n        i++;\r\n      }\r\n    }\r\n    return (j - 1);\r\n  }\r\n    \r\n    public static void display(int[] arr) {\r\n        \r\n        for(int i=0;i&lt;arr.length;i++) {\r\n            System.out.print(arr[i] + \" \");\r\n        }\r\n    }\r\n    \r\n    public static void main(String[] args) {\r\n        int[] arr = {7,9,4,8,3,6,2,5};\r\n        quickSort(arr,0,arr.length-1);\r\n        display(arr);\r\n    }\r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11580 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11580 a\"),jQuery(\"#tab-content_11580\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t<\/p>\n<h2>Time Complexity of Quick Sort Program in Java<\/h2>\n<p>The <strong>average case time complexity of the quick sort algorithm in java is O(NlogN)<\/strong> where N is the number of elements in the array. This can be proved by solving the recurrence relation of the quicksort algorithm which is as follows: <strong>T(N) = T(N\/2) + O(N).<\/strong> This T(N\/2) term came because after partition, the array gets divided into 2 halves almost (in the average case, we consider it to be half) and we solve each half separately. The O(N) term is because of the partition procedure that takes O(N) time.<\/p>\n<p>The <strong>worst-case time complexity of quicksort is O(N2).<\/strong> This happens due to the formation of the recurrence relation: <strong>T(N) = T(N-1) + O(N).<\/strong> This T(N-1) term occurs when the partition takes place at the end of the array i.e. the partition index is either 0 or N-1.<\/p>\n<p>So, the <strong>worst case is partitioning happening at the end of the array<\/strong> and the worst-case time complexity is O(N2).<br \/>\nThe <strong>average and the best-case is partitioning happening at the middle of the array<\/strong> and the best-case and the average-case time complexity is O(nlogn).<\/p>\n<p>The following image shows the solution of the recurrence relation: T(N) = T(N\/2) + O(N).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221869-Quick%20Sort%20Program%20in%20Java11.png\" alt=\"\" \/><\/p>\n<p>The below image shows the solution of the recurrence relation: T(N) = T(N-1) + O(N).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221879-Quick%20Sort%20Program%20in%20Java12.png\" alt=\"\" \/><\/p>\n<p><strong>Space Complexity of the Quick Sort Program in Java:<\/strong><br \/>\nThe auxiliary space is O(1) as we have not used any extra space. However, the recursion space is O(N) in the worst case.<\/p>\n<h2>Is QuickSort Stable?<\/h2>\n<p>No, quicksort in java is not a stable algorithm. This is because quicksort in java depends on the partition algorithm and partition algorithm is not stable. To understand what a stable algorithm means, have a look at the image shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221879-Quick%20Sort%20Program%20in%20Java13.png\" alt=\"\" \/><\/p>\n<p>So, if the order of the equal elements is maintained after sorting, the algorithm is said to be stable. However, quicksort is not stable as the order after partitioning might or might not remain the same.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nQuick sort algorithm in java is an efficient sorting algorithm that works by recursive partitioning and sorting sub-arrays. We can implement it in Java using a combination of recursive functions and a partitioning algorithm to sort large datasets efficiently.<\/p>\n<h2>Frequently Asked Questions(FAQs)<\/h2>\n<p><strong>Q1. What is Quick Sort program in java?<\/strong><br \/>\n<strong>Ans:<\/strong> Quick Sort program in java is an efficient sorting algorithm that sorts an array or a list by partitioning it into smaller sub-arrays or sub-lists, sorting them recursively, and then merging them back together.<\/p>\n<p><strong>Q2. What is the time complexity of the Quick Sort algorithm in java?<\/strong><br \/>\n<strong>Ans:<\/strong> The worst-case time complexity of Quick Sort algorithm in java is O(n^2), but on average, its time complexity is O(n log n), which makes it one of the most efficient sorting algorithms.<\/p>\n<p><strong>Q3. What is the Quick Sort algorithm in java?<\/strong><br \/>\n<strong>Ans:<\/strong> Quick Sort algorithm in java is a divide-and-conquer sorting algorithm that works by selecting a pivot element from the array, partitioning the array into two sub-arrays or sub-lists, one with elements less than the pivot and the other with elements greater than or equal to the pivot, and then recursively sorting these sub-arrays or sub-lists.<\/p>\n<p><strong>Q4. How does Quick Sort program in java works?<\/strong><br \/>\n<strong>Ans:<\/strong> Quick Sort program in java works by selecting a pivot element from the array, partitioning the array into two sub-arrays or sub-lists, one with elements less than the pivot and the other with elements greater than or equal to the pivot, and then recursively sorting these sub-arrays or sub-lists.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Sort program in Java has been introduced because it is an efficient sorting algorithm that can quickly sort large datasets. It has a time complexity of O(n log n) and is widely used in many programming applications. Introduction to Quick Sort Program in Java Quick Sort program in Java is a fast and efficient [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[143],"tags":[],"class_list":["post-11620","post","type-post","status-publish","format-standard","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Quick Sort Program in Java<\/title>\n<meta name=\"description\" content=\"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quick Sort Program in Java\" \/>\n<meta property=\"og:description\" content=\"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-10T07:01:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-17T12:39:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Quick Sort Program in Java\",\"datePublished\":\"2023-01-10T07:01:54+00:00\",\"dateModified\":\"2023-04-17T12:39:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\"},\"wordCount\":1781,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\",\"name\":\"Quick Sort Program in Java\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\",\"datePublished\":\"2023-01-10T07:01:54+00:00\",\"dateModified\":\"2023-04-17T12:39:32+00:00\",\"description\":\"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/java\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Quick Sort Program in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Quick Sort Program in Java","description":"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Quick Sort Program in Java","og_description":"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis","og_url":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-01-10T07:01:54+00:00","article_modified_time":"2023-04-17T12:39:32+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Quick Sort Program in Java","datePublished":"2023-01-10T07:01:54+00:00","dateModified":"2023-04-17T12:39:32+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/"},"wordCount":1781,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/","url":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/","name":"Quick Sort Program in Java","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg","datePublished":"2023-01-10T07:01:54+00:00","dateModified":"2023-04-17T12:39:32+00:00","description":"We will understand the partition procedure, the quicksort algorithm with the quicksort program in Java and its worst-case and best-case analysis","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673333221250-Quick%20Sort%20Program%20in%20Java.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/quick-sort-program-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/prepbytes.com\/blog\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Quick Sort Program in Java"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11620"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11620\/revisions"}],"predecessor-version":[{"id":15683,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11620\/revisions\/15683"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}