Implement algorithms for sorting in python

Assignment Help Python Programming
Reference no: EM131317800

Objectives

The objectives of this assignment are:
- To gain experience in designing algorithms for a given problem description and implementing those algo- rithms in Python 3.
- To demonstrate the ability to:
- Implement algorithms for sorting in Python.
- Decompose code into functions in Python.
- Implement simple recursive algorithms in Python.
- Read from text files using Python.
- Manipulate lists using basic operations.

Task 1:

Part A

(a) File read in correctly

(b) Merge sort implemented correctly (c)Rankings printed correctly

(d)Code is readable (including meaningful variable names and non-trivial comments on code)

(e)Code is appropriately decomposed

Part B

(a) File read in correctly

(b) Merge sort implemented correctly

(c)Rankings printed correctly

(d) Code is readable (including meaningful variable names and non-trivial comments on code) - 1 marks (e)Code is appropriately decomposed

Task 2:

(a) File read in correctly - 2 marks (b)Maximum spanning tree found - 3 marks (c)Spanning tree printed correctly

(d) Code is readable (including meaningful variable names and non-trivial comments on code)

(e)Code is appropriately decomposed

Task 3:

Part A

(a) Recursive function(s) implemented correctly - 3 marks (b)Mathematical function(s) implemented correctly

(c) Code is readable (including meaningful variable names and non-trivial comments on code)

(d)Code is appropriately decomposed

Part B

(a) Report conclusions and quality

Task 1

For this year's Olympic games, as always, the ranking of the teams is given by the number of medals that they win in the various events. The number of medals that each team won is stored in a file with one team per line. Each line contains a team's name, followed by the number of gold, silver and bronze medals they won. The values on each line are separated by commas. An example of the format is shown below.

Canada (CAN),1,5,12
Indonesia (INA),0,1,1 Poland (POL),2,2,6

Part A

For this part, you are to write a Python program to sort the teams by the number of gold medals that they won. Perform this sort using Merge sort. The program should ask the user for a filename containing the medal tally and read the file in. It should then sort the teams by their number of gold medals and finally print the teams in their sorted order along with their rank. Note that multiple teams can have the same rank if they have the same number of medals. For example, given a file containing the above tally, the program could print:
Sorted according to the number of gold medals

1: Poland (POL)
2: Canada (CAN)
3: Indonesia (INA)

Part B

In this part, write a Python program similar to the one from Part A but sort by the total medal count instead. So instead of sorting by the number of gold medals that each team won, this time it should be sorted by the total number of medals (gold, silver and bronze) that the team won.

For this part, your program might print the following:

Sorted according to the total number of the medals 1: Canada (CAN)
1: Poland (POL)
2: Indonesia (INA)

Task 2

Previously in this unit, we have discussed finding minimum spanning trees using a variety of methods. In this task, we will be finding maximum spanning trees, that is spanning trees with the highest possible weight.

Create a Python program which finds a maximum spanning tree of a given graph. Your program will ask the user for a filename and read a graph, stored as an edge list, from that file. It will then compute a maximal spanning tree from that graph and print the edges in the tree along with its weight. For example: The file containing the following lines:

0

1

1

0

4

8

0

5

9

1

2

17

1

4

6

2

3

2

3

4

9

4

5

3

2

4

12

For example: If the file testGraph.txt contains the edges and weights of the graph (see figure 1), your program might do the following:

2129_Figure1.jpg

This is the edges of the spanning tree

[[0,5],[0,4],[4,2],[2,1],[4,3]]

The weight of the maximum spanning tree is: 55

Task 3

A combination is a way of selecting k elements from a set of n elements. The total number of ways of doing this for a given n ≥ 0 and k ∈ [0, n] is denoted (nk). The value of (nk) can be calculated using (1) below where n! is the factorial of n.

(nk) = n!/((n - k)!k!)

The following identity involving a sum of a number of combinations allows for it to be calculated more simply:

Σnk=0(nk)xk/k=1 = ((x +1)n+1 -1)/x(n +1)

Part A

For this task, you are to attempt to verify the correctness of this identity. Do this by implementing both the left-hand and right-hand sides of the equation as functions in Python.

Using these two functions, create a program which takes values for x and n and prints the result of both the left-hand and right-hand sides of the identity for those values.

Your program should include at least one non-trivial recursive function. You must not use the math package and must write your own function to compute (nk).

Part B

Using your program from Part A, compare the results for both functions for a variety of values of both x and n. Choose at least 10 combinations of values and present your results in a table. Include this table in a short report (about 2 paragraphs) and discuss whether your results indicate that the identity is true.

Verified Expert

In this assignment 3 tasks are involved. All the task involves writing the python program. In task 1 the data is read from file and merge sort algorithm is implemented on them to sort the data in the file. The sorting is done based on the number of medals won by them. In task 3 the maximum spanning tree algorithm is implemented in python with nodes and edges list obtained from the file. Task 3 involves solving the combinatorics equation in python. All the python programs written and well documented and sample output is added in the documentation.

Reference no: EM131317800

Questions Cloud

Compute the expected return and standard deviation : Following are four economic states, their likelihoods, and the potential returns: Economic State Probability Return Fast growth 0.30 71 % Slow growth 0.40 17 Recession 0.19 –18 Depression 0.11 –50 Compute the expected return and standard deviation.
Projects are expected to produce the net cash inflow : Better Health Inc. is evaluating two capital investments, each of which requires an up-front (Year 0) expenditure of $1.5 million. The projects are expected to produce the following net cash inflow
Make using covered interest arbitrage : Given the following information, find the JPY profits you can make using covered interest arbitrage. Assume you can borrow either EUR 100,000 or JPY 14,603,000.
Constant growth rates in dividends for foreseeable future : Consider four different stocks, all of which have a required return of 15 percent and a most recent dividend of $4.80 per share. Stocks W, X, and Y are expected to maintain constant growth rates in dividends for the foreseeable future of 10 percent, ..
Implement algorithms for sorting in python : MCD4710 Algorithmic Problem Solving - write a Python program similar to the one from Part A but sort by the total medal count instead. So instead of sorting by the number of gold medals that each team won, this time it should be sorted by the total..
Create an application the will calculate your total pay : Create an application the will calculate your total pay for the number of days worked. Number of days worked can be from 1 to 30 days.
What acceleration factor does 175 ?c present : What acceleration factor does 175 ?C present? Temperatures are junction temperatures, and typical values are 55 ?C for consumer and 85 ?C for industrial electronics.
Describe unique aspects of revenue recognition : Insurance industry-specific financial ratios are usually prepared from financial statements prepared under what standards?
Write an abstract superclass encapsulating a vacation : Write an abstract superclass encapsulating a vacation: A vacation has two attributes: a budget and a destination. It has an abstract method returning by how much the vacation is over or under budget.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd