Trump Sort — A new sorting algorithm

Making Sorting Algorithms Great Again

Gant Laborde
Mar 20, 2017 · 3 min read

What is Trump Sort?

Trump Sort is an merciless O(n) in-memory variation of the drop sort algorithm with political benefits baked in. The algorithm is extremely easy to write, explain, and it’s useful to any native english-speaking white male. Ask anyone! The benefits are yuge.

Start with a random list of values:

You begin by looping N times where N is the size of the array. You then either build a wall or deport along the set.

Let’s do this example as an exercise.

Compare the second item in the array against the first. If that second item is larger than the first, then that index is now your “wall”.

We continue moving along to the 3rd index where the value is lower than our wall. That 3rd item of the set is then deported to the end.

You continue on until you have performed the original N times, and something magical happens! 🎩

We did it!

The wall is built! None of the deported items can return, because the wall is assured to be the tallest, and we didn’t have to pay for the wall! We can now safely ignore everything above the wall for our sorted list.

💥 You just got Trump Sorted

Not only did our algorithm sort quickly, build a wall and export unwanted items, it also decreased the size in memory! I’ve asked a lot of people, and they’ve said this is the best sorting algorithm out there. You can’t trump Trump Sort.


Q: What happens to the deported items from our list?
A: Who cares? Why does everyone keep asking this?

Q: Sort only costsO(n) WOW! Who paid for the wall?
A: Trump Sort deserves credit, but did not pay for the wall.

Q: Why would I use this when it doesn’t actually work?
A: You’re being rude. APOLOGIZE!

Can you implement Trump Sort?

Give it a try! Implement Trump Sort in your favorite programming language, and link it in the comments.

I hope that everyone enjoys the humor of this blog post, regardless of political oblivion. Special thanks to the devs I was talking with when we came up with this (i.e. Andrew Brindamour, Matt Hargett et al.). Also special thanks to Unsplash for the header background.

Thanks to Shawni Danner

Gant Laborde

Written by

Software Consultant, Adjunct Professor, Published Author, Award Winning Speaker, Mentor, Organizer and Immature Nerd :D — Lately full of React Native Tech

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade