You’re creating software that analyzes the data of body temperature readings taken from hundreds of human patients. These readings are taken from healthy people and range from 97.0 degrees Fahrenheit to 99.0 degrees Fahrenheit. An important point: within this application, the decimal point never goes beyond the tenth place. Here’s a sample array of temperature readings: [98.6, 98.0, 97.1, 99.0, 98.9, 97.8, 98.5, 98.2, 98.0, 97.1] You are to write a function that sorts these readings from lowest to highest. Using a classic sorting algorithm such as Quicksort would take O(N log N). However, in this case, writing a faster sorting algorithm is possible. Yes, that’s right. Even though you’ve learned that the fastest sorts are O(N log N), this case is different. Why? In this case, there are limited possibilities for the readings. In such a case, we can sort these values in O(N). It may be N multiplied by a constant, but that’s still considered O(N).
You’re creating software that analyzes the data of body temperature readings taken from hundreds of human patients. These readings are taken from healthy people and range from 97.0 degrees Fahrenheit to 99.0 degrees Fahrenheit. An important point: within this application, the decimal point never goes beyond the tenth place.
Here’s a sample array of temperature readings:
You are to write a function that sorts these readings from lowest to highest.
Using a classic sorting
Yes, that’s right. Even though you’ve learned that the fastest sorts are O(N log N), this case is different. Why? In this case, there are limited possibilities for the readings. In such a case, we can sort these values in O(N). It may be N multiplied by a constant, but that’s still considered O(N).
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
Hello, this