Tukey's ninther def tukeys_ninthers(items): Back in the day when computers were far slower and had a lot less RAM for our programs to burrow into, special techniques were necessary to achieve many things that are trivial today with a couple of lines of code. In this spirit, "Tukey's ninther" is an approximation algorithm from the seventies to quickly find some value that should be “reasonably close” to the median element of the given unsorted list. For the purposes of this problem, the median element of the list is defined to be the element that would end up in the middle position if that list were sorted. This makes the median unambiguous, regardless of the elements and their multiplicities. This function is not tasked to find the true median, which would be a trivial one-liner by sorting items, but find and return the same element that Tukey's ninther algorithm would return for those items. Tukey's algorithm splits the list into triplets of three elements, and finds the median of each triplet. These medians-of-three are collected into a new list and this same operation is repeated until only one element remains. For simplicity, your function can assume that the length of items is always some power of three. In the following table, each row contains the result produced by applying a single round of Tukey's algorithm to the list immediately below. Tukey's algorithm is extremely robust, as can be appreciated by giving it a bunch of randomly shuffled lists of distinct numbers to operate on, and plotting the histogram of results to admire how heavily centered around the actual median this distribution ends up being. These distinct numbers can even come from distributions over arbitrary scales, since this comparison-based algorithm never performs any arithmetic between elements. For example, the median of the last example list in the above table is really 15, pinky swear for grownup realsies. Even better, if all items are distinct and the length of the list is some power of three, the returned result can never be from the true top or bottom third of the sorted elements, thus eliminating all risk of using some funky outlier as the approximation for the true median.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Tukey's ninther
def tukeys_ninthers(items):

Back in the day when computers were far slower and had a lot less RAM for our programs to burrow into, special techniques were necessary to achieve many things that are trivial today with a couple of lines of code. In this spirit, "Tukey's ninther" is an approximation algorithm from the seventies to quickly find some value that should be “reasonably close” to the median element of the given unsorted list. For the purposes of this problem, the median element of the list is defined to be the element that would end up in the middle position if that list were sorted. This makes the median unambiguous, regardless of the elements and their multiplicities. This function is not tasked to find the true median, which would be a trivial one-liner by sorting items, but find and return the same element that Tukey's ninther algorithm would return for those items.

Tukey's algorithm splits the list into triplets of three elements, and finds the median of each triplet. These medians-of-three are collected into a new list and this same operation is repeated until only one element remains. For simplicity, your function can assume that the length of items is always
some power of three. In the following table, each row contains the result produced by applying a single round of Tukey's algorithm to the list immediately below.

Tukey's algorithm is extremely robust, as can be appreciated by giving it a bunch of randomly shuffled lists of distinct numbers to operate on, and plotting the histogram of results to admire how heavily centered around the actual median this distribution ends up being. These distinct numbers
can even come from distributions over arbitrary scales, since this comparison-based algorithm never performs any arithmetic between elements. For example, the median of the last example list
in the above table is really 15, pinky swear for grownup realsies. Even better, if all items are distinct and the length of the list is some power of three, the returned result can never be from the true top or bottom third of the sorted elements, thus eliminating all risk of using some funky outlier
as the approximation for the true median.

items
Expected result
[15]
15
[42, 7, 15]
15
[99, 42, 17, 7, 1, 9, 12, 77, 15]
15
[55, 99, 131, 42, 88, 11, 17, 16, 104, 2, 8, 7,
15
0, 1, 69, 8, 93, 9, 12, 11, 16, 1, 77, 90, 15,
4, 123]
Transcribed Image Text:items Expected result [15] 15 [42, 7, 15] 15 [99, 42, 17, 7, 1, 9, 12, 77, 15] 15 [55, 99, 131, 42, 88, 11, 17, 16, 104, 2, 8, 7, 15 0, 1, 69, 8, 93, 9, 12, 11, 16, 1, 77, 90, 15, 4, 123]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education