Introduction to Algorithms for Beginners and Aspiring Programmers

This is a brain-friendly introduction to algorithms for beginners, written with the intent of guiding readers in their journey of learning algorithms more streamlined and less intimidating.

For those with little to zero experience with programming, the word algorithms evoke a lot of fear, mystery, and suspense. It is portrayed as an esoteric, cryptic black box that none but the smartest of individuals dare open and attempt to decode.

Well, I am here today to blow away some myths regarding algorithms.

What is an Algorithm?

Don’t feel stupid for asking. I asked the very same question when I started out.

An algorithm is a detailed step-by-step instruction set or formula for solving a problem or completing a task. In computing, programmers write algorithms that instruct the computer how to perform a task.

Source: https://www.tynker.com

I love this definition, because, it captures the heart of algorithms. It CAN involve mathematical formulas, but algorithms don’t have to have mathematical formulas.

Often at times, people who are just starting out have this misconception that algorithms involve highly complex mathematical formulas, calculus, and all that jazz.

Break that misconception off right now. It is wrong at its best, and downright destructive at its worst.

Algorithms are all around us. In the context of programming, the basic code which returns the average from a list of integers IS an algorithm.

function getAverage(list) {
    int sum = 0, count = list.length;
    for (var i = 0; i < count; i++) {
        sum += list[i];
    }
    return sum/count;
}

Am I capable of Learning Algorithms? 

The number one factor that prevents people from learning algorithms is the fear factor. People lose the battle before it even begins because they are afraid.

Let me just say this

If I can learn algorithms, you can too!

Really. I am not a very smart person. It just takes an effective learning place, dedication, and some hard work.

And I write this introduction to algorithms for that very reason: to help you learn effectively.

I have made a lot of mistakes when learning algorithms.

Through this introduction to algorithms, I write to ensure that you are able to profit off my mistakes by not making them.

How do I learn Algorithms?

Like many things in life, the best way to learn algorithms is by practice. Because algorithms are written procedures of steps. Developing strong written communication skills and logical processing helps. Below are some questions you should answer to get you started.

1. Do you know a programming language?

Because programming languages are the language of choice of expressing your logic, you should first aim to get comfortable with a language of your choice.

If you are starting out, I recommend starting off with Python, because it has a relatively shallow learning curve.

JavaScript is also another great choice, but JavaScript becomes steeper as you get into some of the more advanced topics, which you don’t have to worry about for now.

2. If I know a programming language, where is a great place to start practicing algorithms?

Focus on the fundamentals. People are under the impression that writing algorithms in entirely language agnostic. While that is true in essence, mastering and becoming comfortable with at least one programming language is a huge step.

Remember, algorithms are step-by-step instructions to solve problems. Programming languages are tools that developers use to solve problems. How are you even expected to solve a problem effectively if you don’t know how to use the tools to solve problems?

While you are learning the in and outs of a programming language, whether you are aware of it or not, you are learning how to write algorithms.

3. Become proficient at written communication

To other developers reading the code, it is a written documentation that provides information on the steps taken to solve a problem.

So how can you improve your written communication? The short answer is by writing. Tennis players sharpen their skills by playing tennis. A guitarist hones his/her skill with the guitar by playing it.

In the same way, you can improve your written communication skills by writing. But remember this: (for most readers) you are not a novelist.

Here are some ideas to get you started in brushing up your written communication skills.

  • Start a blog and write about what you know/are learning.
  • Before writing code, try writing out the pseudo code.
  • Craft API documentation for your existing code.

From doing this, you will not only become better at communicating your ideas and thoughts, it will also help you process your thoughts and identify potential pitfalls in your current logic.

Thanks for the Introduction to Algorithms. Where do I Start?

Once you have decided to start learning, this is one of the most common questions asked. Start out small. One good place to start out is by starting off with basic sorting algorithms such as

  • Bubble sort.
  • Insertion sort.
  • Selection sort.

Sorting algorithms are sorting a collection of items in ascending order. For example, sorting the following list

[3, 1, 2, 5, 6] into [1, 2, 3, 5, 6].

A lot of people, especially those that are starting out believe that the only way to become better at writing algorithms is by writing algorithms. Although this is a great way to start off, it can set you back in the long run, if this is the only way you practice writing algorithms.

Practice Writing Algorithms by Not Practicing Algorithms

One approach that I find very useful is to not focus on writing algorithms. Here are some creative ways to learn how to think in algorithms.

Learn Functional Programming

Learning functional programming will help you write more readable, robust code that minimizes side effects. More importantly, functional programming trains a developer to break down a bigger problem into smaller, reusable parts.

This is a very important concept to understand when writing algorithms. A problem can generally be broken down into smaller sets of problems that need to be solved.

Learn Object Oriented Analysis and Design

Learning to think Object-orientedly trains developers to see the relationship between various objects that interact with one another. Often, when writing algorithms in the real world, there will often be interactions between two or more parties. Having the eye to see the interactions and to design your algorithms or classes in an effective and scalable manner will help you write coherent, robust solutions to problems.

Do I need to be Good at Maths to Learn Algorithms?

The short answer is no. You don’t need to be good at maths, but having a strong background in mathematics will definitely help. Like a programming language, math is another form of written communication. Mathematics symbols such as sigma (Σ) has a certain meaning, just as each character in the English alphabets all carry a certain meaning.

Chances are, if you are good at Mathematics, a lot of the process and parts of writing algorithms will feel very similar to writing up a solution to a mathematical problem/equation.

Online Resource for Learning Algorithms

Since you are just starting out, it is only natural to ask the following question: What are some good online resources for learning algorithms?

Below are some recommended websites that help/helped me a lot. Please note that the order in which the resources appear do not reflect my personal evaluation/opinion of the service.

Unless I specified “pay to use“, the resources listed below will be free. Please note that this is a growing list, and I will be adding more items to the list in the near future.

1. Free Code Camp

Although Free Code Camp is mostly based around web-programming, it does a great job at teaching the languages interactively (I.E. JavaScript) and easing users into writing algorithms. The process feels somewhat organic, and users are given practical opportunities to partake in personal projects.

Projects are one of the best ways to grow, as it challenges you and puts your knowledge to the test. Every seasoned developer can attest to the fact that they grew the most when faced with difficult challenges in projects.

2. Code Wars

Don’t worry, we aren’t fighting anyone. You will be partaking in a war against your own mind by writing solutions for the plethora of algorithmic challenges available on the site. Most of the problems can be solved in a language of your preference, which can all be configured on their platform.

What I really like about this site is that it encourages you to write test cases. Writing test cases is a great way to review your train of thoughts when writing algorithms. For each algorithm that you write, if you cannot write specific test cases and test against them, you probably don’t have a clear plan on how you are going to implement your algorithm. Think of this as a litmus test/filter to protect yourself from writing code during auto-pilot mode.

Recommended Readings

Okay, here are some books to get you started on learning algorithms.

Grokking Algorithms: An illustrated guide for programmers and other curious people

I will be honest: I needed to look up the word Grokking. For a short read, this book was surprisingly informative. People who are new to programming will benefit greatly from reading this book before any other resource. Even if you are a seasoned programmer, I am still confident that you will be able to take something from this book.

It does a great job in breaking down complex and potentially daunting “algorithms” into bite-sized chunks.

Computer Science Distilled: Learn the Art of Solving Computational Problems

Even shorter than the previous book, the reason why I like this book is that it is great for reading while commuting. The concepts are explained very clearly, using relatable illustrations and analogies.

One thing I love about this book is that it is very much straight to the point and clear. None of those long-winded, verbose analogies that you hear from professors at Universities. It teaches you only what you need to know.

Introduction to Algorithms, 3rd Edition (MIT Press)

If you ask for a book recommendation on algorithms, most people will point you to this book. Although it is an extremely well-written book, this book will slap you in the face if you are unprepared. Therefore, I only recommend reading this once you have a solid understanding of programming, and Big-O notation.

If you jump into this book with a few months of programming experience, YOU WILL BE JADED. Not to mention that the book is over 1000 pages (yes, even longer than a Harry Potter book).

I recommend this book for experienced programmers who are eager to do a deep and focused dive into the world of algorithms. This book is NOT for those who wish to simply test the waters or study algorithms once every other week.

Hopefully, the tips and advice shared here are of some help to you. Until next time, peace!

About the Author Jay

I am a programmer currently living in Seoul, South Korea. I created this blog as an outlet to express what I know / have been learning in text form for retaining knowledge and also to hopefully help the wider community. I am passionate about data structures and algorithms. The back-end and databases is where my heart is at.

follow me on:
5 Shares