Okay, so today I wanted to mess around with a couple of algorithms, Stearns and Li, just to see how they stack up. It’s something I’ve been meaning to do for a while, and I finally carved out some time this afternoon.

First, I needed some data. I didn’t want anything too crazy, so I just whipped up a simple dataset – a bunch of numbers, some duplicates, nothing fancy. The goal was to have something I could easily understand and visualize, you know?
Then, I got down to coding. I started with Stearns’ algorithm. I found some pseudocode online and translated that into Python. It wasn’t too bad, actually. The logic is pretty straightforward: you’re basically iterating through the data and keeping track of things in a specific way.
Stearns’ Algorithm Implementation
- Set up initial data input.
- Implemented core logic based on pseudocode.
- Checked output for correctness using test data.
After getting Stearns’ algorithm working, I moved on to Li’s. This one was a little trickier, at least for me. The explanation I found was a bit more dense, and I had to read it a few times to really wrap my head around it. It involved some clever manipulation of indices, which, honestly, took me a bit to debug. It have use other way to do it,and I used the easy way.
Li’s Algorithm Implementation

- Read and re-read the algorithm description (phew!).
- Wrote the Python code, focusing on index handling.
- Spent a good chunk of time debugging – that was fun (not!).
Running and Comparing
Once I had both algorithms implemented, I ran them on my dataset. I timed them, of course, because that’s half the fun, right? Seeing which one is faster, even on a small scale, is satisfying. I use time package to get the record.
I also made sure to print out the results of each algorithm so I could compare them directly. I wanted to see if they were producing the same output, which they should if I did everything right! I even threw in a few edge cases just to be sure.
My very personal conculsion,both of them are good,it depends the specific needs.