Prev: W8, Next: W10
Links: Zoom, TopHat (010339, or Form), Calculator:
Slide:



# Sorting Algorithms

📗 Comparison Sorts (\(N\) = data items to sort):
➩ Bubble Sort: \(O\left(N^{2}\right)\).
➩ Heap Sort, Merge Sort: \(O\left(N \log N\right)\).
📗 Stable vs unstable (preserve ordering of equal elements).
📗 Visualization: Link, Link.



# Counting Sort

📗 We take the range R of symbols into consideration.
📗 Visualization: Link

# Counting Sort Example

ID:
📗 [1 point] Sort the following array: .

Auto-add based on digit: .



# Radix Sort

📗 What if the range is big:
➩ Apply Counting Sort once per position.
➩ Radix Sort
📗 Visualization: Link

# Radix Sort Example

ID:
📗 [1 point] Sort the following array: .

Auto-add based on digit: .



# Complexity

📗 Linear sorting algorithms:
➩ \(N\): the number of data items to sort.
➩ \(R\) range of symbols.
➩ \(Q\): length of the data items.
📗 Counting Sort: \(O\left(2 N + R\right) = O\left(N\right)\).
📗 Radix Sort: \(O\left(Q N\right) = O\left(N\right)\).



# Readings

📗 DOT Graph Language: Link
📗 Google Cloud Platform:
➩ Redeem your Google Cloud Coupon following these steps: .
➩ Get your coupon: there is a Piazza post for our section.
➩ Video demonstration by Professor Florian Heimerl: Link.
➩ To install the cs400 script on your VM
(1) run the following command in Bash on your VM: dst=/usr/local/bin/cs400 && sudo wget -O $dst https://pages.cs.wisc.edu/~cs400/cs400 && sudo chmod 755 $dst; sudo apt-get install git
(2) Then, run cs400 init to set up a gitlab access token for the script your VM.
➩ If you see the error "YOUR-NETID is not in the sudoers file.  This incident will be reported." try the following steps:
(1) log into your VM with your browser through the SSH button on the Google Cloud platform
(2) run the following command (replace YOUR-NETID with your username on your google VM): sudo usermod -aG sudo YOUR-NETID
(3) run the command to install the cs400 script again



📗 Notes and code adapted from the course taught by Professor Florian Heimerl and Ashley Samuelson.
📗 Please use Ctrl+F5 or Shift+F5 or Shift+Command+R or Incognito mode or Private Browsing to refresh the cached JavaScript.
📗 You can expand all the examples and demos: , or print the notes: .
📗 If there is an issue with TopHat during the lectures, please submit your answers on paper (include your Wisc ID and answers) or this Google Form at the end of the lecture.

Prev: W8, Next: W10





Last Updated: November 25, 2025 at 1:46 AM