
- 3rd Jul 2024
- 18:19 pm
In this assignment, we explore the efficiency of various sorting algorithms using different sets of word lists—sorted in ascending, descending, and random orders—ranging from 100 to 100,000 words. By timing sorting operations on these datasets, we aim to analyze and compare the performance of bubble, insertion, shell, merge, and quicksort algorithms against theoretical expectations.
Program Specification
Using a wordlist provided (Info & Resources), make sets of words in the following amounts: 100, 1000, 10000, 100000. For each set, have 3 versions: sorted in alpha order, sorted in reverse order, and a 'random' (shuffled) set of words. You can then take the sets and time the various sort programs. Once you have it set up properly, you should be OK to simply substitute the input file containing the words. I used "R" for Random, "A" for Ascending and "D" for Descending.and combined the letters with the number of words in each. For example 100R.txt, 100A.txt and 100D.txt. This allows you to quickly subsitute the filenames. The objective is to compile a table showing completion times for each sort as shown below: (file) You'll have 1 of these for each sort algorithm: Bubble, Insertion, Shell, Merge and Quicksort. Once done, you can then graph out the "random" times for each of the sorts. Compare the times against the predicted "cheat-sheet" result for that sort. MyWords.txt contains approximately 355,000 words. (1 word per line) Wordsfile.txt contains approximately 170,000 words. (multiple words per line)
Analyzing Sort Algorithm Performance with Word Sets and Orders - Get Assignment Solution
Please note that this is a sample Analyzing Sort Algorithm Performance with Word Sets and Orders assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Analyzing Sort Algorithm Performance with Word Sets and Orders
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7b8b528d",
"metadata": {},
"outputs": [],
"source": [
"from fileinput import filename\n",
"import random\n",
"from datetime import datetime\n",
"import pandas as pd\n",
"\n",
"\n",
"filename = './Python_Angele_15th April/mywords.txt'\n",
"f = open('./Python_Angele_15th April/mywords.txt', 'r')\n",
"last_sort = f.readline()\n",
"\n",
"with open(filename) as file:\n",
" lines = [line.rstrip() for line in file]\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ae8eb9f1",
"metadata": {},
"outputs": [],
"source": [
"# acsending order\n",
"def bubble_sort(f_name, arr):\n",
" start_time = datetime.now()\n",
" \n",
" n = len(arr)\n",
" for i in range(n):\n",
" for j in range(n - i - 1):\n",
" if arr[j] > arr[j + 1]:\n",
" # sorting by using simultaneous assignment in python\n",
" arr[j], arr[j + 1] = arr[j + 1], arr[j]\n",
" \n",
" new_file_1 = open(f_name, 'w')\n",
" \n",
" for i in arr:\n",
" new_file_1.writelines(i)\n",
"\n",
" new_file_1.close()\n",
"\n",
" end_time = datetime.now()\n",
" # print('Duration acsending order for {} file: {}'.format(f_name, end_time - start_time))\n",
" return (end_time - start_time)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8bc1d5cc",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# decsending order\n",
"def bubble_sort_descending(f_name, arr):\n",
" start_time = datetime.now()\n",
"\n",
" n = len(arr)\n",
" for i in range(n):\n",
" for j in range(n - i - 1):\n",
" if arr[j] < arr[j + 1]:\n",
" # sorting by using simultaneous assignment in python\n",
" arr[j], arr[j + 1] = arr[j + 1], arr[j]\n",
" \n",
" new_file_1 = open(f_name, 'w')\n",
" \n",
"\n",
" for i in arr:\n",
" new_file_1.writelines(i)\n",
"\n",
" new_file_1.close()\n",
"\n",
" end_time = datetime.now()\n",
" # print('Duration descending order for {} file: {}'.format(f_name, end_time - start_time)) \n",
" return (end_time - start_time)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d3bba4f9",
"metadata": {},
"outputs": [],
"source": [
"# shuffle order\n",
"def shuffle_sort(f_name, arr):\n",
" start_time = datetime.now()\n",
" random.shuffle(arr)\n",
" \n",
" new_file_1 = open(f_name, 'w')\n",
" \n",
"\n",
" for i in arr:\n",
" new_file_1.writelines(i)\n",
"\n",
" new_file_1.close()\n",
" \n",
" end_time = datetime.now()\n",
" print('Duration shuffle order for {} file: {}'.format(f_name, end_time - start_time))\n",
" return (end_time - start_time)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e4677067",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Duration shuffle order for R100.txt file: 0:00:00.000279\n",
"Duration shuffle order for R1000.txt file: 0:00:00.000182\n",
"Duration shuffle order for R10000.txt file: 0:00:00.001237\n",
"Duration shuffle order for R100000.txt file: 0:00:00.112235\n"
]
}
],
"source": [
"\n",
"a_100 = lines[:100]\n",
"a_1000 = lines[:1000],\n",
"a_10000 = lines[:10000],\n",
"a_100000 = lines[:100000]\n",
"\n",
"random_time = []\n",
"ascending_time = []\n",
"descending_time = []\n",
"\n",
"\n",
"ascending_time.append(bubble_sort('A100.txt', a_100))\n",
"ascending_time.append(bubble_sort('A1000.txt', a_1000))\n",
"ascending_time.append(bubble_sort('A10000.txt', a_10000))\n",
"ascending_time.append(bubble_sort('A100000.txt', a_100000))\n",
"\n",
"random_time.append(shuffle_sort('R100.txt', a_100))\n",
"random_time.append(shuffle_sort('R1000.txt', a_1000))\n",
"random_time.append(shuffle_sort('R10000.txt', a_10000))\n",
"random_time.append(shuffle_sort('R100000.txt', a_100000))\n",
"\n",
"descending_time.append(bubble_sort_descending('D100.txt', a_100))\n",
"descending_time.append(bubble_sort_descending('D1000.txt', a_1000))\n",
"descending_time.append(bubble_sort_descending('D10000.txt', a_10000))\n",
"descending_time.append(bubble_sort_descending('D100000.txt', a_100000))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "d873eb9a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
100 | 1000 | 10000 | 100000 | |
---|---|---|---|---|
Asc | 0 days 00:00:00.002504 | 0 days 00:00:00.001031 | 0 days 00:00:00.004082 | 0 days 00:09:14.119494 |
Desc | 0 days 00:00:00.000791 | 0 days 00:00:00.000134 | 0 days 00:00:00.000787 | 0 days 00:14:27.654122 |
Random | 0 days 00:00:00.000279 | 0 days 00:00:00.000182 | 0 days 00:00:00.001237 | 0 days 00:00:00.112235 |
\n",
"
"
],
"text/plain": [
" 100 1000 10000 \\\n",
"Asc 0 days 00:00:00.002504 0 days 00:00:00.001031 0 days 00:00:00.004082 \n",
"Desc 0 days 00:00:00.000791 0 days 00:00:00.000134 0 days 00:00:00.000787 \n",
"Random 0 days 00:00:00.000279 0 days 00:00:00.000182 0 days 00:00:00.001237 \n",
"\n",
" 100000 \n",
"Asc 0 days 00:09:14.119494 \n",
"Desc 0 days 00:14:27.654122 \n",
"Random 0 days 00:00:00.112235 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result = pd.DataFrame([ascending_time, descending_time, random_time], columns = ['100', '1000', '10000', '100000'], index = [ 'Asc', 'Desc', 'Random'] )\n",
"\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0f2c4b4",
"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.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Get the best Analyzing Sort Algorithm Performance with Word Sets and Orders assignment help and tutoring services from our experts now!
About The Author - Sarah Thompson
Sarah Thompson is a seasoned software engineer and data scientist with over 10 years of experience in algorithm development and optimization. She specializes in creating efficient sorting algorithms and has a deep understanding of data structures. Sarah's expertise includes practical applications of sorting algorithms to large datasets, making her well-suited to guide you through this assignment.