TMA02 – Python
Question 1 (30 marks)
The TMA questions and guidance page has all the files mentioned in this question.
More to Read:
Short Questions Political Science
Imagine you are part of a team developing a crossword app that helps the user, e.g. by listing all 3-letter English words ending in ‘t’. For such a feature, it is better to store dictionary words sorted by length instead of alphabetically.
The team lead asks you to write a function that takes a non-empty list of non-empty strings (e.g. [‘hi’, ‘this’, ‘is’, ‘Jane’]) and returns a new list with the same strings in increasing length. Words of the same length must appear in the original order (that’s called a stable sorting). For this example, the result is [‘hi’, ‘is’, ‘this’, ‘Jane’]. You are asked to use this bucket sort algorithm:
Compute the maximum length Lof the words in the list. For the example, L is 4.
Create a list with Lbuckets, each bucket being initially the empty list. For the example, this step creates [[], [], [], []].
Put each word in the right bucket: words of length 1 (like ‘a’ and ‘I’) go in the first bucket, words of length 2 go in the second bucket, etc. For the example, the result of this step is [[], [‘hi’, ‘is’], [], [‘this’, ‘Jane’]]. The first and third buckets remain empty.
Compute the sorted list by first adding the words in bucket 1, then those in bucket 2, etc. For the example, the result of this step is [‘hi’, ‘is’, ‘this’, ‘Jane’].
This part is about Python’s list operations (Python activity 1.5).
Step 2 has been implemented for you in file TMA02_Q1.py. Implement the rest of the algorithm by replacing the pass statements by your code (about 12 lines). You can only use the Python list operations given in the Companion’s appendix. Copy the completed bucket_sorted function into your Solution Document.
We advise you add one step at a time and test it with file TMA02_Q1_tests.py. You should add your own tests. Your tutor will use a different test file, so make sure your code solves the general problem, not just the problem instances (tests) we provide. (12 marks)
Explain how your implementation guarantees the sort to be stable, i.e. keeps the original order of words of the same length. (2 marks)
This part is about algorithmic complexity (Unit 2 Section 4.1and theCompanion).
State and explain the worst-case Big-O complexity of your bucket sort implementation in terms of the number of words n, i.e. the length of the input list. The unit of computation is the assignment. Use the complexities in the Companion’s appendix.
Explain also why the problem size is just the number of words and not dependent on the number of buckets L too. (5 marks)
This part is about heap sort (Unit 3 Section 4.2) and the professional skill of comparing alternative approaches.
A team member suggests it would be easier to just take heap sort and in the percolation process replace every comparison of strings in the heap by the comparison of their lengths, i.e. x < y becomes len(x) Brilliant services. I ordered a 4 page essay and it was delivered in less than 24hours with every detail intact! Aceassignment is the way to go. The writers are humble and patient with clients. I know this after using the website for about an year My writer did a brilliant job. Not only did she delivered the paper on time and it was superb as my professor granted me an A without any criticism I was running late with my assignment. I run into aceassignment on google, placed my order and within less than 18 hours my page essay was delivered. Thank you Aceassignment. I've been using Aceassignment for about 2 years. My writer always delivers quality work. Mind you whenever I request for a revision it's always done ASAP and free of charge
At first, I was scared and hesitant about using this website. Didn't know if they would deliver, but they assured me they will. And for sure they did. I will definitely continue to use their service!
Easy to use website. You simply give your essay's instructions, make payment and before you known it the paper is delivered to you.
Unlike other platforms, this website is quite cheap and the quality is high. I have them manage my whole class and everything has been smooth this far.
Thanks for the excellent job. Swift and on the subject, just the way I like it. The Support team was quite nice to me, helped me with the order placing process.
They are a marvel. I love their support team, they are so polite, it’s like speaking to a butler or something. Very pleasant people and good service of course.
Thank you for the help, I took my time and ordered a 14 days long essay. It came much earlier, around 7 days after I ordered it. Oh, and it was good, of course. I like the writer who did that, will definitely use again.
What I received was great. I forgot to mention in the instructions field that I needed reference page and by default, there was 0 in the number of references. I was surprised to see a full-fledged reference page in my paper with relevant citations. Bravo!
I was bombarding him with fine tuning and he handled it professionally. Thank you I will hire again the writer
Provided exceptional essay writing help in a short period of time. I plan to work with writer on many more projects!
Awesome paper in such a short amount of time. Was in a jam with another service who didn't deliver, but my writer did the job correctly. I will use her again to do my essays for sure!
Pretty good essay writer. I only made a couple of adjustments. She caught some instructions for the essay writing assignment that I didn't even notice, including them which was a pleasant surprise. Definitely recommend.
It was a very long paper, but the writer followed all the instructions, and she even finished the paper 5 days before the due date. Will write an essay with her again, thanks!
Writer was timely and proficient. I had to ask for a revision, but I got it back quickly with no other issues. Would use this essay writing service again. Paper writing was prepared and submitted prior to the completed request date, and there were changes made quickly after I requested. This paper writer was accurate with numbers.
The first time I ordered here and it was a success. I received my order on time and according to my instructions. Thank you!
When I first discovered this website I was hesitant on whether they will deliver a plag free paper. The support team reassured me of their plagiarism policy. In deed they kept their word as the paper I got was authentic and plagiarism free. Clients' Reviews about Our Services
Client ID 45637
U.S.A
Client ID 45783
U.K
Client ID 45214
U.K
Client ID 45009
CAD
Client ID 45870
U.S.A
Client ID 44218
U.S.A
Client ID 45622
U.S.A
Client ID 43964
U.S.A
Client ID 41996
U.K
Client ID 47654
AU
Client ID 45670
FRA
Client ID 22368
US
Client ID 46325
U.S.A
Client ID 456820
U.S.A
Client ID 36890
UAE
Client ID 41427
U.K
Client ID 45009
CAD
Client ID 36984
U.S.A
Client ID 42960
CAD
Client ID 31638
U.K
Client ID 46041
CAD