My intro to data structures and algorithms 📚
October 4, 2022 • ☕️ 3 min read
Data structures and algorithms are terms that I’ve seen always pop up when I’m reading blogs or watching youtube videos and for a long time I’ve always wanted to learn them but was never motivated to
I would often start then give up as quickly as possible.
This time is different, I am literally forcing myself to learn them and in this blog post I’m going to give a quick introduction by explaining data structures and algorithms in the simplest way possible.
- Algorithms.
While the word might seem prestigious, it is nothing but a list of instructions for performing a specific task. If you have been coding then you have been writing algorithms all along, it is a procedure of having well defined steps for solving a particular problem or producing a particular result.
I like to think of an algorithm as a recipe(the one used for cooking) because it tells you a list of steps and actions that you must take in order to make food
There are different types of algorithms that perform different tasks such as:
- sorting
- searching
- deleting
- inserting
- updating
There are different ways of writing an algorithm that does the same thing but they are distinguished by performance and perfomance for algorithms is measured by:
- time (amount of time for an algorithm to execute)
- space (the amount of memory required by the algorithm)
- Data Structures.
As the name implies, they are structures that store and organize data.
Data structures are built in a way that data values have relationships amongst them and that there are functions and operations built-in to manipulate the data.
An example would be an array/list, a data structure that you have probably used in your coding career. There is a relationship between index of an array and size of an array (The array is indexed from 0 to size-1.). There are operations/functions such as sorting, deleting,inserting etc. all built-in into the array data structure.
types of data structures include:
- linear data structures (they are arranged in a linear order meaning that they are non-trees and non-graph, examples would be: arrays; linked lists; stacks; and queue.)
- non-linear data structures (they do not form a sequence and each element or item is connected with two or more other items, examples would be trees and graphs)
You are probably asking yourself why do we have so many data structures, the reasons are:
- processor speed (cpu processes some data structures faster than others)
- data search (efficent retrival of specific data differs amongst diiferent data structures)
- multiple request (some data structures take longer to make multiple requests)
Besides the number of data structures, just having one is advantage because:
- They are efficient (fast)
- They are reusable (build once use anywhere)
- They are abstractable (process of filtering out)
And I mentioned earlier that there are functions built into data stuctures, the common ones are:
- Traversing (iterating over the data)
- Insertion (adding a new item in any place in the data structure)
- deletion (removing an item form anywhere in the data structure)
- searching (finding the location of any element within the data structure)
- sorting (arranging data in a specific order)
- merging (adding two or more groups of data to form a single unified set)
- etc.. many more
- Conclusion. This post was so that I can explain algorithms and data structures, Theres still a vast majority that I still need to cover from Big O notation to creating algorithms and data structure to algorithmic thinking hopefully in future posts, this was just an introduction