Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Quick sort comments
Added extra comments in functions, for better understanding.
  • Loading branch information
kehsihba19 authored Oct 1, 2019
commit 52c4e2d5c41ad8bfc957c27988be04077c2d1bda
12 changes: 10 additions & 2 deletions Sorting/5. Quick_Sort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
"outputs": [],
"source": [
"def partition(array, low, high):\n",
" i = low - 1\n",
" pivot = array[high]\n",
" i = low - 1 # index of smaller element\n",
" pivot = array[high] # pivot \n",
" \n",
" for j in range(low, high):\n",
" # If current element is smaller than the pivot\n",
" \n",
" if array[j] < pivot:\n",
" # increment index of smaller element\n"
" \n",
" i += 1\n",
" array[i], array[j] = array[j], array[i]\n",
" \n",
Expand All @@ -27,8 +31,12 @@
"\n",
"def quick_sort(array, low, high):\n",
" if low < high:\n",
" # pi is partitioning index, arr[p] is now\n",
" # at right place \n",
" temp = partition(array, low, high)\n",
" \n",
" # Separately sort elements before\n",
" # partition and after partition \n",
" quick_sort(array, low, temp - 1)\n",
" quick_sort(array, temp + 1, high)"
]
Expand Down