Actual Algorithms (Are Fun)

As a computer scientist, I get pretty annoyed with the constant cultural usage of the term algorithm. There seems to be an unwritten rule that whenever a technical concept is brought into the mainstream cultural discussion, it will be bastardized into the void away from its original meaning. Nowadays it’s used to denote “that internet code.” People talk about the YouTube algorithms, the Facebook algorithm, the Google algorithm, the Amazon algorithms, the Twitter trending algorithm.

I hate these people. Ha, I try not to hate the people, just the behavior. Yet that is certainly one of my pet peeves – people using technical words without conveying what the words actually mean, commonly because they themselves don’t actually know. Poor usage spreads and the word loses meaning. To contrast, you can check wikipedia on algorithms. It’s dry reading and believe me, that’s a feature and not a bug.

To those who are always talking about “the algorithms”, kindly be a little more wary. Most of your online experience nowadays is governed by machine learning statistical engines with very big tables and very fancy heuristics, but it’s really arcane and not very algorithm-y, which is near the root of many of the controversies. For instance, a trainable neural network that you can teach to recognize written numbers is easy enough to do but no expert doing it knows how, and it only works most of the time. If we did, we’d have much cooler algorithms. We don’t, so Google uses their I’m-not-a-robot CAPTCHA to force you to help them train their bots by labeling crosswalks and stop signs. Algorithms are an actual thing, not fancy models that work most of the time.

Precise definitions of the word algorithm can convey to someone educated on relevant subjects a whole rainbow of ideas, thoughts, and worlds. The word algorithm should be like the word library, a word that can connote the Dewey Decimal System, that crazy lady you feared when your books were overdue in school, or rows and rows of books above your head, and that lovely smell of old books – there really is nothing quite like it. Algorithms, similarly, should connote to people titans of technology, pioneers like Turing or Knuth, magical answers to age-old problems, famous puzzles and thought experiments, and math tricks to solve the unsolvable.

Let’s make a definition, what should be denoted:

Algorithm – a finite sequence of well-defined instructions, typically to solve a class of problems or to perform a computation, in a finite amount of space and time, in a well-defined formal language.

This is my own definition, contrived from that wikipedia article I told you to look at. There isn’t an agreed upon precise definition philosophically, partly because of its extremely meta-abstract (even the abstractions are abstract!) nature. (See arcane bickering here).
I’ll emphasize a few things here then we’ll move on:

1. It’s finite. That means it can be complicated but not infinite.
2. well-defined. A good one is like 2+2, there’s no nuances.
3. “instructions” is a great almost-synonym.
4. it’s instructions to compute or solve a problem.
5. it’s useless unless it uses finite (not-infinite) space and time. This is a big attribute I’ll detail in a bit.
6. “in well-defined formal language” they are somehow logically defined, and Spock must approve on the minutia.

If math is mostly playing with nouns, algorithms are mostly verbs. In some sense, algorithms are the playing.


How is this fun? I hear you. I want to talk about what the word should connote, rather than denote. I want to give you a feel, not a definition. Let’s talk about the most fun and easy introduction to algorithms: sorting.

Sorting problems are every computer science nerd’s first fun project. Given a list of random items, like socks or numbers or people of different height, what’s the fastest way to put them in order?

Simple problem, right? WRONG. As it turns out, which way is faster depends on the data set and what ways of shuffling them around you have available. Some of the fastest ways of sorting are actually terrible if they’re already almost in order. And then if you have extra space to make copies or take notes as you sort, you might be able to sort faster in less steps. That’s called a space-time trade-off. Towers of Hanoi is an old puzzle game that on the other extreme makes you sort with as little space as possible. It can be converted into binary because it literally can’t be smaller. (More on Towers of Hanoi and math)
More variables and options is more space, and more steps is more time, and you might decrease one by increasing the other.

Here is a brief introduction to sorting algorithms. I’ll summarize a few classics and have a link for more info. Gifs will make them fun. Wheeeee.

Bubble Sort
Are we done moving yet?

Bubble sort is the sort almost everybody thinks of first. If you haven’t read ahead, come up with your own sort first and see if it’s this one. It sucks, but don’t be ashamed. It’s a start.
Step 1: pick a pair of things and swap them so they’re in order.
Step 2: repeat moving groups around until they’re in order.
It sucks because it’s O(n2), which is math talk for saying twice as many things to sort will take 4 times as long. You want your sort to take O(n log(n)) or O(n) if you can manage it (and the O(n) ones are usually theoretical or complicated).

Insertion Sort
Brrrrrrrrrrrr

Insertion sort also sucks (O(n2)) and is like another flavor of bubble sort with its simplicity.
Step 1: Grab the first two items and sort them
Step 2: Repeat adding the next item and putting it where it goes

This might be the other one you thought of. It’s not that bad IRL. Very little to keep track of if you don’t struggle making room each time.

Selection Sort
And the next one, …

Selection sort sucks even worse than the above because it’s O(n2) in the best case. The other ones can be more like O(n) if you’re lucky.
This is the first one I think of.
Step 1: grab the biggest or smallest thing and put it on the end
Step 2: grab the next biggest or smallest thing.

The problem is you have to spend your time looking at everything for the next one, every time. It’s a good one to think about however, because if you managed to keep track of what you found as you compared them the first time, you might be able to make a space-time tradeoff.

Quicksort
Kids in the front! Smile Timmy!

Enter Quicksort. The name is a dead giveaway. This is the not-so-humble “hahaha rekt” sort that kicks butt most of the time. Don’t think of it as the fastest sort. Think of it as the arrogant sort that has weaknesses but is usually so good it makes other sorts mad. It divides and conquers.
Step 1: pick one thing. call it the “pivot”. Pick the middle or randomly, people argue over how to pick a pivot.
Step 2: move smaller ones to the left and bigger ones to the right.
Step 3: Take each half and repeat, going deeper. When you only have 2 left, put them in the right order and you’re done with those.

It’s a devilishly elegant O(n log(n)), but can take O(n2) if unlucky. Sometimes the hare takes a nap and oversleeps.

Mergesort
Alright gang, let’s split up!

Mergesort can go almost as fast as Quicksort, but it doesn’t trip at the finish line at random. The idea is divide and conquer O(n log(n)) like Quicksort, but from the other direction where you combine and conquer.
Step 1: Split in half, then repeat until it’s all groups of one.
Step 2: Go backwards to the last step and combine those two sorted, then three or four, until you’re done and it’s sorted.

It requires you to keep track of a bit more, but I’ve heard it said operating systems can do it fast with files. Notice it may use more space, and takes less time! I’m sure I could make a Fullmetal Alchemist joke here about the law equivalent exchange.

Heapsort
Like I said, complicated.

Remember when I noted some faster ones were more complicated? Heapsort is a last one I’ll mention. Remember when I said Selection Sort was good to think about because it’s easy to improve? This is where you can end up if you chased that white rabbit (wild goose?) of keeping track of what’s sorted. It can compete with Quicksort and Mergesort.
Step 1: Build a heap.
Step 2: Sort it by swapping one not sorted with the top and trickling down
.
What’s a heap? It’s a binary tree like you’ll see in the gif. You build this tree and then sort them so the big ones are at the bottom, by finding a little one compared to its parent and then swapping it with the top one and bubbling it down. The secret is mathematically the number of changes you have to do is O(n log(n)) once you’ve built the heap, because as you move each new one down into its right spot, you only have to look at a few, you forget about the other branches. Do some more research if this is the only one that confuses you. There are several ways of doing it.

Takeaway

Learning algorithms is a lot like taking a ride through a series of thought experiments and seeing how fast or high the roller coaster is. It’s educational to realize how many different ways you can solve a simple problem, and that crucially, not all ways of solving problems are remotely equal. And if you find a better way than anyone else, you’ve added to humanity’s genius.

Let me know what you think because if I can get people interested in the subject I’d love to do a series on algorithms. Searching graphs and hard problems and puzzles and riddles that if you solved unlock secrets of the universe are worthy of talking about. Algorithms are at the heart of our best known ways of solving problems. It’s a good mental exercise to answer a question correctly multiple different ways. It might even make you smarter.

Be Quiet.

Peace, be still. Listen. Hush. Shush. Breathe. Be quiet. There’s a lot of us online who spend way too much time speaking or spectating. Don’t be one of them all the time. You don’t have to reply to every post or even acknowledge every reply to you. Sometimes the hardest path and one less traveled is to not take the journey others do at all.

We live in a very noisy world – literally and figuratively. I spent the weekend at our state’s aquarium and it had awkward soundproofing triangles on the side because of the noisy roads nearby. (Easier to see in this ancient pic below)

SHELBY DOBSON / LOVELAND LIVING PLANET AQUARIUM

What kind of metaphorical soundproofing do you have in your life? We’re constantly barraged by advertisements online and streams of posts from our friends and peers, and news articles are always fighting to be as psychologically loud as possible. What do you think this is doing to us? We’re getting louder and louder. We’re becoming less able to hear good things that are quieter. Truth of the matter is, we’ve been in this deafening noise for so long that some of us seem to have forgotten what it’s like to step outside of it.

Step outside of it. Every day in this tough year I see another acquaintance snap and make a drastic negative life change because they can’t take it anymore. Divorce and breakups, quitting a career, torching a project, permanently cutting off friends, suicide. People “can’t take it anymore.” The only way you’re going to be able to survive and succeed in a perpetually negative noisy world is to manage to get outside it and know the opposite exists, and what it looks like. A lot of still-successful celebs and commentators I’ve noticed will do so once a year with some kind of “break”. Even they need to be quiet sometimes.

I want to examine just three simple things you can do to bring more peace and balance in your life if you’re roped into tumultuous news and entertainment. (I have more but let’s narrow it down to a few you’ll remember)

1. Take a Sabbath

The word comes from Shabbat, the Hebrew origin that dates at least back to Moses’ 10 Commandments. For practicing Jews that’s Saturday. For most Christians, it’s Sunday. But you don’t have to be religious. It’s a generic principle. You need to take time to mentally rest from the crap you have to put up with every other day of the week.

Decide what that would look like to you. Maybe your phone is always turned off all day on the first day of each month. Maybe you refuse to open certain social media apps on a certain day of the week. Whatever you do, you need to define it as a law that you live by, one nearly as big as “don’t kill people”. One public figure takes an entire month away from being online, with assistance from peers to find out what was missed. What matters is that you take a well-defined regular quiet break. Do what fits into your own work schedule.

2. Meditate

Do you know how hard it is to do nothing on purpose? For some of us, it’s boring. For others, it’s a nightmare that lets our inner demons have a voice. Many of us don’t want to be left alone with our thoughts. For those and many more, to go meditate on purpose about their life and problems is a terrifying idea that takes legitimate courage to face a little introspection.

Introspect. Take time to sit on the floor quietly with your eyes closed for 10 or 15 minutes. Set an alarm if you have to. You can hum or empty your mind and think of nothing and see what bubbles up. You could have paper and pencil ready. You could only focus on your breathing. You don’t even have to call it meditation if you think it’s silly. But we don’t get enough of it. You may even find time to meditate on the go, if you go running without music like I do. But if you don’t give yourself time to introspect, you forego one of the only ways to course-correct your life and improve where you’re headed. And maybe if you faced those demons they’d leave and take some anxiety and stress with them.

3. Write

This is one of the reasons I have this blog now, but I write elsewhere too. Writing has a deeply therapeutic effect on a cluttered soul. When you write down what’s on your mind, it suddenly doesn’t have to be on your mind anymore. You can clear and quiet your mind. I’ve encountered this numerous times, where I finally write down a list of things that have been secretly plaguing me and then suddenly I can think and breath again.

I can’t overstate the value of coping with stress, anxiety, and possibly depression by writing. Barf your mind onto a page. Make it a note document you can conceal from everyone. Spill it. Start a journal or diary. Let it all out and see how it affects you. You’ll feel better once you realize you can have a paper therapist. It might help you become aware of things you keep forgetting, and you’ll be able to look back a few weeks later and see what ended up mattering versus what didn’t age well.

Takeaway

It doesn’t matter how you go about it, but if you can’t give your subconscious some ways to participate in your life, you’ll go crazy. We’re seeing it happen to all kinds of people this year. If it means you have to start hiking into the mountains, do it. It’s one of the reasons people find various vacations alluring. You need one around once a week. There was a time in our culture where that’s what weekends were for, but we rush into them so hard or work on those days now and we’re less sane and less mentally healthy than ever. If you haven’t, start doing something for your present or future self. Turn down the signals. Find time to be quiet.

Among Us: 2020 Sus

If you aren’t familiar with the trending game Among Us, I think it’s worth finding out more about, because I think its viral-ity comes at this particular time (summer 2020) for specific reasons in the collective unconscious. It is an indie game made by a small creator, not a big gaming company. It has been around for a few years, but only now went super viral. I wanna look at why it exploded so huge they cancelled a sequel.

In Among Us, you play in a self-explanatory group game of ten people. You are astronauts arriving at an abandoned space ship and fixing it back up. Each of you has a set of trivial tasks to do. They’re tiny minigames like connecting 4 pairs of dots or swiping a card through a reader. If you do, you win. But there’s a catch: one of you is an Imposter, an assassin bent on killing everyone. Each time a dead body is found or an emergency button is pressed, a meeting is called and somebody is voted off the ship and thrown into space.

Simple enough? It’s a digital variant of a game many of us played when we were young called something like “assassin”, where heads would go down, an assassin would pick somebody to die, and the group had to identify who it was.

Why now? The game has been around but few played it. Suspend your disbelief and assume for a moment my frame of reference: I like to think there are almost no coincidences like this in the world, only complex patterns we fail to identify. I tend to think at least most viral things go viral for a reason, and that reason has to do with the online humanity at the time, even if we never do discover why a thing gets popular.

Right now Americans are roped in the drama of another political election, a massive high stakes game of deciding who to trust. We’ve had a terrible year, with members of society reporting each other and covering their faces with masks. We have had violent riots and a breakdown in many formerly-civil public discourses. After a rough summer, many people are looking for something to settle down and tune out even while paying attention to the news. Perhaps they’ve already decided who they’ll vote for and put it out of mind. 2020 has been a long year filled with looking for who to blame, and it has torn down our ability to trust each other and anything, and we have been desperate for a way to cope with it.

Enter Among Us. Twitch streamers started playing it in the early phase of 2020 but critical mass was hit right as the summer was ending and all of a sudden almost everybody I know online is playing this little 5 dollar game. It’s FUN, but so are a lot of games. Seriously go play it some. If you like, you can try playing with friends! It’s a barrel full of laughs. Go look up YouTubers playing it if you’re coming totally from the outside.

I think Among Us is what we needed. We needed a childhood game to serve as a simulator of being betrayed or literally back-stabbed. Those worth their salt in the psychological professions will tell you that exposure therapy is one of the most effective ways at helping people overcome their mental challenges – their fears and phobias. We’re SO TIRED of 2020 we don’t want to think about it anymore. And yet, we’re looking for a “new normal”, a new way to look at the world that isn’t discouraging and can help us move forward in spite of the fears. Having a videogame where you do it is a good way to practice.

Maybe I’m optimistic, but I like to think Among Us is going to have a massive positive dampening effect on the culture. I think in time there will be less incentive to protest in the streets. Maybe we can’t ignore the challenges of trusting other people in news and media any longer, and need an easy way to start doing it. Maybe we need to practice working together in spite of things we fear. Maybe we need to bond with friends or even total strangers as we take turns in a group being a devious monster and then laughing about it.

It’s Time for You to 3D Print

Everyone I talk to seems interested in 3D printing but hasn’t pulled the trigger on buying one yet. Why? They’re getting stupidly cheap.

Every decade or so a new technology comes along that changes the way society functions. This has been true for almost a century. One of the problems I’m noticing in recent years is that there’s a decline or split in this cycle. People seem to be declining opportunities to try something new. Maybe they look at the new thing as an oddity, or a fad. Maybe times are tough, maybe they’re skeptical that it’s for them. It’s new, it’s too complicated, or something like that. Then they go and get the next gaming console that’s not noticeably better than the last one, or sit in front of [latest B-quality show] on [streaming service].

We’ve had virtual reality and 3D printing for years now but they haven’t had the success that home paper printers or walkmans and iPods did long ago. I don’t see all the cool kids on the internet doing things like VR for more than a single video for clicks. It’s a lot of fun, and should be the wave of the future if more of the average people signed on to be a part of it. But it remains only a gimmick.

I feel like we’ve fallen into a cynical postmodern age, where we no longer believe in the new and the modern. I really think it’s going to hurt us if we don’t find a way to break free. You can’t have hope for the future if it’s not something you want to participate in! If I can’t get you to write software, at least maybe I can get you to learn to make things this way. More fun for less effort.

I guess what I want people to hear from me this fall season of a dismal 2020 is that the future is for you. What’s mainly stopping us from moving forward personally and as a civilization is ourselves, far as I can tell. We aren’t daring to dream of what could be anymore. Too many of us are so caught up in worries about what’s in the news that we don’t have a vision anymore.

Remember when the internet was new? Remember when the whole world opened up before us? That’s what 3D printing is. If you’re in technology, the combination it with Arduino and Raspberry Pi allow you to make virtually anything you can dream of. The world is opening up to those getting into this and I see too many standing on the sidelines still. Go make an army of robots! Nothing’s stopping you anymore.

It’s time to start dreaming again. I’m still a novice at 3D printing but I already have a lot to show for it, and I haven’t even started designing yet! I’m just pouring excellent creations out of Thingiverse. GO TAKE A LOOK please. (The search is a little clunky with how they use URLs so navigate back to the home before doing another search, but there’s cool stuff everywhere.)

Right now you can get a popular (well supported by the community!) 3D printer called the Ender 3 Pro for a little over $200. Rolls of filament are all over Amazon for $20-$30 for a massive 1kg wheel. I don’t think i’ve used half my first wheel and now I’m stockpiling a bunch of new types. Look at some of this stuff! Color changing, glow in the dark, clear, metallic, even red ones with glitter inside you could make ornaments with! For those getting better at it, some printers and filament allow you to print wood. They have sawdust as the main component. Sounds like work to deal with its issues, but the products are gorgeous, just l0ok up some YouTube videos.

I think we’re long overdue for everyone, and I do mean everyone, to own a 3D printer. Long, long overdue. This is bigger than AOL or iPods. I don’t know why it took me so long. It’s time for you to dive in when you have a weekend to toy with it. There’s a lot of things you can make with 3D printing that are hard to make with traditional plastic molding used for the stuff you see in toy aisles. I’ll be making one of those zip cord helicopter disk launchers in the next week or so. I’ve just been printing whatever looks good, and soon i’ll be coming up with my own things.

We’re living in an era of game-changers that many of us are letting blow right by us as we work our day jobs and then waste time talking about events on social media. The darkness of winter is coming and it’s time for you to add something to your spirit and mental health if you haven’t, and it’s never been easier to learn to do something more exciting. Do yourself a favor and make a flexi rex, and giggle as it wiggles. Be able to say I made this.