Skip to content

Commit

Permalink
Added sorting comparison notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSol committed Oct 21, 2024
1 parent c99b9dc commit a747384
Showing 1 changed file with 204 additions and 0 deletions.
204 changes: 204 additions & 0 deletions week02_binary_search/Sorting comparison.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append('..')\n",
"sys.path.append('../../week01_sorting_algorithms/')\n",
"from qsort import qsort\n",
"from bubble import bubble_sort\n",
"from selection import selection_sort\n",
"from insertion import insertion_sort\n",
"from merge import merge_sort\n",
"from counting import counting_sort, counting_sort2\n",
"from random import randint"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"======= N=1000 ======\n",
"Built-in: \n",
"CPU times: total: 0 ns\n",
"Wall time: 0 ns\n",
"CountingSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 0 ns\n",
"MergeSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 1.32 ms\n",
"QSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 1.01 ms\n",
"BubbleSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 37.3 ms\n",
"======= N=10000 ======\n",
"Built-in: \n",
"CPU times: total: 0 ns\n",
"Wall time: 0 ns\n",
"CountingSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 0 ns\n",
"MergeSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 16 ms\n",
"QSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 5 ms\n",
"BubbleSort: \n",
"CPU times: total: 2.69 s\n",
"Wall time: 4.03 s\n",
"======= N=100000 ======\n",
"Built-in: \n",
"CPU times: total: 15.6 ms\n",
"Wall time: 5.51 ms\n",
"CountingSort: \n",
"CPU times: total: 0 ns\n",
"Wall time: 8.51 ms\n",
"MergeSort: \n",
"CPU times: total: 141 ms\n",
"Wall time: 181 ms\n",
"QSort: \n",
"CPU times: total: 62.5 ms\n",
"Wall time: 71.2 ms\n",
"BubbleSort: \n",
"TimeOut\n",
"======= N=1000000 ======\n",
"Built-in: \n",
"CPU times: total: 46.9 ms\n",
"Wall time: 61.6 ms\n",
"CountingSort: \n",
"CPU times: total: 93.8 ms\n",
"Wall time: 94.9 ms\n",
"MergeSort: \n",
"CPU times: total: 1.31 s\n",
"Wall time: 2.11 s\n",
"QSort: \n",
"CPU times: total: 484 ms\n",
"Wall time: 694 ms\n",
"BubbleSort: \n",
"TimeOut\n",
"======= N=10000000 ======\n",
"Built-in: \n",
"CPU times: total: 391 ms\n",
"Wall time: 626 ms\n",
"CountingSort: \n",
"CPU times: total: 656 ms\n",
"Wall time: 950 ms\n",
"MergeSort: \n",
"CPU times: total: 16.3 s\n",
"Wall time: 24.5 s\n",
"QSort: \n",
"CPU times: total: 4.25 s\n",
"Wall time: 5.91 s\n",
"BubbleSort: \n",
"TimeOut\n",
"======= N=100000000 ======\n",
"Built-in: \n",
"CPU times: total: 4.19 s\n",
"Wall time: 6.67 s\n",
"CountingSort: \n",
"CPU times: total: 6.38 s\n",
"Wall time: 9.76 s\n",
"MergeSort: \n",
"TimeOut\n",
"QSort: \n",
"TimeOut\n",
"BubbleSort: \n",
"TimeOut\n"
]
}
],
"source": [
"for N in [1000, 10000, 100000, 1000000, 10000000, 100000000]:\n",
" print(f'======= N={N} ======')\n",
" X = [randint(0, 100) for i in range(N)]\n",
" x = list(X)\n",
" print('Built-in: ')\n",
" %time x.sort()\n",
" \n",
" x = list(X)\n",
" print('CountingSort: ')\n",
" %time counting_sort(x)\n",
" \n",
" x = list(X)\n",
" print('MergeSort: ')\n",
" if N >= 100000000:\n",
" print('TimeOut')\n",
" else:\n",
" %time merge_sort(x)\n",
" \n",
" x = list(X)\n",
" print('QSort: ')\n",
" if N >= 100000000:\n",
" print('TimeOut')\n",
" else:\n",
" %time qsort(x)\n",
" \n",
" x = list(X)\n",
" print('BubbleSort: ')\n",
" if N >= 100000:\n",
" print('TimeOut')\n",
" else:\n",
" %time bubble_sort(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit a747384

Please sign in to comment.