ECS32B California Davis Stable Merge Sort and Heap Representations Problem Paper All the work should be done in the file hwX.py, so the structure of the co
ECS32B California Davis Stable Merge Sort and Heap Representations Problem Paper All the work should be done in the file hwX.py, so the structure of the code should be exactly same as hwX.py
Please see both of the attchments
the instruction and homework is attached
you will work in hwX.py(in the zip),
and after you finished,
run hwX_test.py all statement should be saying “ok” Makeup Assignment:
Problem 1? (30 points) stable merge sort
Consider the following unsorted list of integers containing duplicates where the relative position
of each duplicated integer in the unsorted list is noted as a subscript. For example, 1?1? is at a
smaller index than 1?2?. The subscript is ignored when comparing two values since it would not
actually be present in the underlying Python representation of this list.
8?1
4?1
1?1
4?2
8?2
1?2
A sorting algorithm is ?stable? if the relative position of duplicate items is preserved. Stable
sorting can be a useful property in many instances. The list below represents a stable sort of he
list above.
1?1
1?2
4?1
4?2
8?1
8?2
Another example would be sorting a list by first name and then by last using a stable sorting
algorithm. This would order everybody with the same last name by their first name.
You will modify the merge sort procedure from lecture 20 to demonstrate that merge sort can be
stable. Hint: consider how ties should be broken during the merge phase.
To demonstrate that the modified merge sort procedure modify it so it sorts a list of tuples by
their second position. The tuples contain the first and last names of some random individuals.
Problem 2? (15 points) unstable selection sort
You will show that selection sort is unstable by sorting the same list of tuples in part 1 by their
second position. Note that the first names of people with the same last name are no longer in
sorted order.
Problem 3: ?(30 points) Heap Representations
Part 1:
Convert the following maxheap from a tree representation to a Python list representation.
Part 2:
Show the new state of the maxheap in a Python list representation after inserting the value 63
into the maxheap and restoring the heap order property.
Part 3:
Show the state of the maxheap in a Python list representation after removing the value 89 from
the ?original? maxheap and restoring the heap order property.
Problem 4 ?(25 points) Tree traversal
Consider the following tree containing integer values at each node. Traverse the tree in the
order specified. When visiting each node, the operation you will perform is to append the integer
to the end of a Python list. In your homework file specify the list of integers that results from
each traversal approach.
Part a. inorder
Part b. preorder
Part c. postorder
Part d. levelorder (see lecture 23)
Purchase answer to see full
attachment
We've got everything to become your favourite writing service
Money back guarantee
Your money is safe. Even if we fail to satisfy your expectations, you can always request a refund and get your money back.
Confidentiality
We don’t share your private information with anyone. What happens on our website stays on our website.
Our service is legit
We provide you with a sample paper on the topic you need, and this kind of academic assistance is perfectly legitimate.
Get a plagiarism-free paper
We check every paper with our plagiarism-detection software, so you get a unique paper written for your particular purposes.
We can help with urgent tasks
Need a paper tomorrow? We can write it even while you’re sleeping. Place an order now and get your paper in 8 hours.
Pay a fair price
Our prices depend on urgency. If you want a cheap essay, place your order in advance. Our prices start from $11 per page.