[SOLVED] python ECS 32B: Fall 2019 Homework Assignment 4

$25

File Name: python_ECS_32B:_Fall_2019_Homework_Assignment_4.zip
File Size: 442.74 KB

5/5 - (1 vote)

ECS 32B: Fall 2019 Homework Assignment 4
Due Date: No later than Sunday, November 17, 6:00pm Submit your solutions via Canvas in one file named hw4.py. Here are your homework problems:
1. In the PowerPoint slides for lecture 15, you will find a function that performs binary search on a Python list using iteration. Modify that binarySearch(alist, item) function so that it performs ternary search on a Python list. Your new function should find two midpoints that divide the list into three (hence the name ternarylook it up) approximately equal size segments. If the item being searched for is found at either of the midpoints, the function should return True. If the item being searched for is less than the value at the first midpoint, ternary search continues with the segment to the left of the first midpoint. If the item being searched for is greater than the value at the second midpoint, ternary search continues with the segment to the right of the second midpoint. Otherwise, ternary search continues with the segment between the first and second midpoints. Name your function ternarySearch.
2. In the PowerPoint slides for lecture 15, you will find a function that performs binary search on a Python list using recursion. Modify that binarySearchRec(alist, item) function so that it performs ternary search on a Python list. Your new function should find two midpoints that divide the list into three approximately equal size segments. If the item being searched for is found at either of the midpoints, the function should return True. If the item being searched for is less than the value at the first midpoint, ternary search continues with the segment to the left of the first midpoint. If the item being searched for is greater than the value at the second midpoint, ternary search continues with the segment to the right of the second midpoint. Otherwise, ternary search continues with the segment between the first and second midpoints. Name your function ternarySearchRec.
3. A number of different sized frisbees are stacked. A sorted frisbee stack is defined as having the smallest frisbee on top, the second smallest frisbee under the smallest frisbee, etc. The only tool provided is a shovel that can be used to flip any top partition of the stack, including the entire stack. Note that there only ever exists one stack of frisbees, not multiple smaller, independent stacks. Larger frisbees may be on top of smaller frisbees and vice versa.
Assume that an arbitrary stack of n frisbees is represented as a Python list of numbers, with each number representing the size of the frisbee. When sorted, the smallest frisbee (with the smallest number) will be at index 0 in the list, and the largest frisbee will be at index n 1. Write a Python function named frisbeeSort that expects one argument, a possibly unsorted list of numbers representing frisbees, that uses the frisbee flipping technique described above to sort the list.
4. To gain familiarity with bubble sort, which we did not talk about in class, do programming exercise 10 from chapter 6: Implement the bubble sort using simultaneous assignment. Name your function bubbleSort.
5. And for a little bit of practice with merge sort, do programming exercise 14 from chapter 6: Implement the mergeSort function without using the slice operator.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] python ECS 32B: Fall 2019 Homework Assignment 4
$25