Data structures and  Algorithms for Noobs

Data structures and Algorithms for Noobs

ยท

3 min read

Data structures and algorithms are very essential is software development or any other computer science related field. So important, yet so easily misunderstood. If you intend working at a large tech company, you must have the fundamentals of data structures and algorithms under your belt.

This is a 3 part series where I explain data structures and algorithms in lay man terms.

By the end of this course, you'll know the following:

  • what an algorithm is
  • what a data structure is
  • how certain data structures work
  • when to use certain data structures

Table of Contents

  1. introduction
  2. Prerequisites
  3. stack
  4. queue
  5. set
  6. conclusion

Introduction

Welcome to part 1 of my data structures and algorithm course. In this part, we'll cover three data structures: stack, queue and set.

What are Algorithms?

Algorithms are simply the steps taken to achieve a task. Simple right?

What are Data structures?

Think of data structures as containers used to hold data. You wouldn't want to use a basket to fetch water would you? Hence, the importance of knowing when to use certain data structures.

Prerequisites

No prerequisites required.

Stack

A stack is a type of a data structure. Think of stack like a pile of books; The book at the top of the pile was placed last. However, it will be the first to be removed from the pile of books. A stack works in a last in, first out manner.

Stacks have the following methods:

  • push which adds an element to the top of the stack
  • pop which removes the element at the top of the stack and returns it
  • peek which returns the first element at the stack
  • sizeor length which returns the length of the stack

Queue

A queue is just like a stack. The only difference is that it works in a first in, first out manner. Imagine you're on a queue at the airport. Who will be the first person to get attended to? You guessed it right! The first person at the queue. However, there is an exception. If someone like the president is on that same queue, he will get attended to first. In programming, you call that a priority queue.

Queues have the following methods:

  • enqueue which adds an element to the queue
  • dequeue which removes the first element at the queue
  • front which returns the first element at the queue
  • size which returns the length of the queue
  • isEmpty which returns a boolean (true or false) depending on if the queue is empty or not

Set

A set is simply an array that has no duplicate items. Sets are useful when checking if an item is present in an array. A grocery list is an example of a set.

Sets have the following methods:

  • has which returns a boolean (true or false) depending on if an element is present in a set or not
  • union which joins two sets and returns the result
  • difference which returns the elements that are present in one set but not in the other set
  • remove which deletes an element from a set
  • intersection which returns elements that are present in both sets

Conclusion

You have completed part 1 of my data structures and algorithm course. By now, you know what stacks, sets, and queues are. With this knowledge, I urge you to implement them in any programming language of your choice. I'll be happy to see your implementation.

Stay safe :)