
- 22nd Jul 2024
- 19:03 pm
In this assignment use the JupyterHub server on the Google Cloud Platform, provided by your designated instructor, for this assignment. Ensure using Python 3.7 release or higher then complete the assignment by inserting your Python code wherever seeing the string #INSERT YOUR ANSWER HERE. When you click the File button, from the top navigation bar, then select Export Notebook to HTML, an HTML document will be generated that includes both the assignment content and the output of any embedded Python code chunks. Use these guidelines to submit both the IPYNB and the exported file (HTML).
Question 1 : The following two algorithms sort a list of integers in ascending order.
Question 2 : Assume the following class implements the STACK abstract data type (ADT) using the array ADT
Free Assignment Solution - Python Programming for Data Science - CIND830
{
"cells": [
{
"cell_type": "markdown",
"id": "bee409cf",
"metadata": {},
"source": [
"# Question 1 (Solution)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "0685f486",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"([1, 2, 3, 4, 5, 6, 8, 9], 6)\n",
"([1, 2, 3, 4, 5, 6, 8, 9], 16)\n"
]
}
],
"source": [
"def Algorithm_1(lyst):\n",
" i = 0\n",
" count=0\n",
" while i < len(lyst) - 1: \n",
" minIndex = i \n",
" j = i + 1\n",
" while j < len(lyst): \n",
" if lyst[minIndex] > lyst[j]:\n",
" minIndex = j\n",
" j += 1\n",
" if minIndex != i: \n",
" lyst[minIndex], lyst[i] = lyst[i], lyst[minIndex]\n",
" count+=1\n",
" i += 1\n",
" return(lyst,count)\n",
"def Algorithm_2(lyst):\n",
" n = len(lyst)\n",
" count=0\n",
" while n > 1: \n",
" i = 1 \n",
" while i < n:\n",
" if lyst[i] < lyst[i - 1]: \n",
" lyst[i], lyst[i - 1] = lyst[i-1], lyst[i]\n",
" count += 1 \n",
" i += 1\n",
" n -= 1\n",
" return(lyst,count) # return(lyst,count)\n",
"Lyst=[5, 6, 8, 3, 2, 1, 9, 4]\n",
"\n",
"print(Algorithm_1(Lyst))\n",
"\n",
"Lyst=[5, 6, 8, 3, 2, 1, 9, 4]\n",
"\n",
"print(Algorithm_2(Lyst))\n"
]
},
{
"cell_type": "markdown",
"id": "17512710",
"metadata": {},
"source": [
"# Question 2 (Solution)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "ebbd8613",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
"[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n"
]
}
],
"source": [
"class aStack():\n",
" def __init__(self, capacity = 5):\n",
" self._items = (capacity)\n",
" self._top = -1\n",
" self._size = 0 \n",
" # Modified push method\n",
" def push(self, newItem1, newItem2):\n",
" self._top += 1\n",
" self._size += 1\n",
" self._items[self._top] = newItem1\n",
" self._top += 1\n",
" self._size += 1 \n",
" self._items[self._top] = newItem2\n",
" # Modified pop method \n",
" def pop(self):\n",
" oldItem1 = self._items[self._top]\n",
" self._items[self._top] = None\n",
" self._top -= 1\n",
" self._size -= 1\n",
" oldItem2 = self._items[self._top]\n",
" self._items[self._top] = None\n",
" self._top -= 1\n",
" self._size -= 1\n",
" return (oldItem1,oldItem2)\n",
" def peek(self):\n",
" return self._items[self._top]\n",
" def __len__(self):\n",
" return self._size\n",
" def __str__(self):\n",
" result = ''\n",
" for i in range(len(self)):\n",
" result += str(self._items[i]) + ''\n",
" return result\n",
"def reverse(aStack):\n",
" new_aStack = aStack()\n",
" while not aStack.__len__()==0:\n",
" new_aStack.push(aStack.pop())\n",
" aStack = new_aStack\n",
"s=[1,2,3,4,5,6,7,8,9,10]\n",
"print(s)\n",
"s.reverse()\n",
"print(s)\n",
" \n",
" \n",
" \n",
"\n",
"\n",
"\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"id": "18b37b8a",
"metadata": {},
"source": [
Get the best Python Programming for Data Science - CIND830 assignment help and tutoring services from our experts now!
Please note that this is a sample 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 above.
About The Author - Sneha Mishra
Sneha Mishra is an experienced data scientist and Python developer with a strong background in algorithm design, data structures, and web scraping. She holds a degree in Computer Science and is proficient in using cloud-based platforms such as Google Cloud Platform for scalable and efficient computing solutions. Sneha specializes in creating robust, data-driven applications and has a passion for teaching and sharing knowledge with others.