Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python The median of a list L is the element a such that half of the elements in L are smaller than a and half

Python image text in transcribed
The median of a list L is the element a such that half of the elements in L are smaller than a and half of thern are larger than a. For example, the median of list L = {20, 10, 45, 1,12) is 12, since 12 s grater than 1 and 10 and smaller that 20 and 45. An easy way to find the median is to sort the list and return the element in the middle: def Median (L): C = Copy(L) Sort (C) return ElementAt (C,GetLength(C)//2) Your task for this lab is to implement several algorithms for finding the median of a list of integers, using objects of the List class described in class, and compare their running times (measured as the number of comparisons each algorithm makes) for various list lengths. To generate data to test your methods, write a method that receives an integer n and builds and returns a list of random integers of length n. The algorithms to compare are the following 1. Sort list using bubble sort, then return the element in the middle. 2. Sort list using merge sort, then return the element in the middle. 3. Sort list using quicksort, then return the element in the middle. 4. Implement a modified version of quicksort that makes a single recursive call instead of the two made by normal quicksort, processing only the sublist where the median is known to reside

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

Students also viewed these Databases questions