Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
79 changes: 79 additions & 0 deletions 13. BucketSort.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sorted Array is : \n",
"[0.1, 0.34, 0.5, 0.6, 0.66, 0.8]\n"
]
}
],
"source": [
"# bucket sort\n",
"\n",
"def bucketSort(x):\n",
" arr = []\n",
" slot_num = 10 # 10 means 10 slots, each\n",
" # slot's size is 0.1\n",
" for i in range(slot_num):\n",
" arr.append([])\n",
" \n",
" # Put array elements in different buckets\n",
" for j in x:\n",
" index_b = int(slot_num * j)\n",
" arr[index_b].append(j)\n",
" \n",
" # Sort individual buckets\n",
" for i in range(slot_num):\n",
" arr[i] = insertionSort(arr[i])\n",
" \n",
" # concatenate the result\n",
" k = 0\n",
" for i in range(slot_num):\n",
" for j in range(len(arr[i])):\n",
" x[k] = arr[i][j]\n",
" k += 1\n",
" return x\n",
"\n",
"\n",
"data = [0.8, 0.5, 0.6, 0.1, 0.66, 0.34]\n",
"print(\"Sorted Array is : \")\n",
"print(bucketSort(data))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ This repository contains simple programs like searching algorithms, basic python

The first program is about python init method.
added exception handling program.

# This readme file is not yet organised