Get Started with Data Structure and Algorithm
‘As a developer, a computer scientist, tech enthusiasts or whatever interest you fall in the Software technology space you’d have undoubtedly come across the term D.S & A ( Data structures and algorithms).
It is a very important aspect that every individual that wants to be a technology know-how, or get a Job as a software developer must/should know as over 90% of Technology companies require during their recruitment process to bring in individuals to their team.
You might know how to code but you’re not a good developer if you don’t know Algorithms
In this article, I'd try to make you comfortable with the basics of algorithms and Data Structure
Algorithm
An Algorithm is a set of instructions followed to complete a task.
Simple, right ?
We basically go through or use an algorithm in our everyday life. Your To-do List is an Algorithm, The Recipe to cook your Nigerian jollof Rice ( oh, sweet goodness! ) is an algorithm.
The steps taken to find x in the equation 2x+3 = 13 is an algorithm
When we talk about algorithms, two points are basically put into context
- Knowing that there is an established body of problems and it is important to know what the solutions are because there’s a likelihood that your solution has been undertaken in the past and had been properly reviewed for its efficiency ( whatever that is!, LOL)
- Part of knowing an algorithm is not just knowing that an algorithm exist but knowing when to apply it and this requires proper understanding of the problem at hand You should be able to look into a problem and break it down into distinct steps, which then you should be able to identify the best Data structure or algorithm best for the task, this simple process is called Algorithmic thinking ( Yay, you’re an algorithmic thinker )
Lastly, learning about algorithm gives
Deeper meaning about Complexity and efficiency ( Basically how to get things done in the best time possible with total efficiency in check.
Having a better sense about how your code will perform in different situations
Algorithmic thinking is the major reason why Algorithms questions comes up in Big Tech Interviews, interviewers most times don’t care how you can specifically write an algorithm in code but how you can break insurmountable problems into distinct components and identify the write tools to solve each components
Data Structures
Data Structure is a particular way of organizing data in a computer so that it can be used effectively
Just like in real life, we discover how to store certain items based on what they are and how we plan to access them.
Your pringles in a pringles jar (took this with some nutella at my cousin’s yesterday, LOL)
Your sugar cubes in a box
Your eggs in an egg Crates , bla bla bla are all examples of Data structures (in real life though!)
Data Structures depends on the type of Data you have and how you can access them, you need to find the best data structure to help you organize and perform any sort of operation on that data
The basic operations that can be carried out in any data structure are
- Access
- Insertion
- Deletion and,
- Search
You need to know that there is no perfect Data Structure, Every Data structure has its strengths and weaknesses and you have to consider the trade-offs before deciding the one that suits your usage, the way to highlight the strengths and weaknesses of a Data Structure is through a mathematical concept called Big-O notation
Big-O notation simply represents the worst case run time or space requirements as input size( Data) increases
As your input size(Data) grows, How much longer does your Algorithm takes to run and how much more space in memory does the Algorithm needs ?
The most common Big-O notation are :
- Constant time, Big-O(1) : Regardless of the input size, the runtime stays the same
- Linear Time, Linear Time O (N) : As the input size grows, the runtime grows Linearly ( Serially)
- Quadratic time, O(N²) : As the input size grows, the runtime grows quadratically
- Logarithmic time, O (log N ) : As the input size grows, the runtime grows Logarithmically
Common Types of Data Structure
- Array: is a linear data structure of fixed size used on same type of elements at a contiguous location, This locations are also called indexes
In a computer, these indexes represent the location of an object in memory
An Example of an array practically would be the arrangement of Eggs in an Egg carton/Crate.
An example of an Array computer wise is
Languages = [ php, javascript, python, C++ ]
Strengths
- Arrays can be accessed in constant time so far the index(location) of the object is known
Weakness
- Arrays basically are of fixed size ( except in the instance of dynamic arrays)
- Searching for an object in an array is really slow as search is done serially ( most especially when the index is not known )
- Linked List: is where we have a node that stores data and those nodes have pointers which point to other nodes.
The pointers basically chain the nodes together in a linked list and constitutes the linked part of a linked list, this pointers also constitutes the address or memory of the location of the connected nodes ( too many grammar)
An example of a linked list practically are connected keychains (one keychain is connected to the other to form a bigger chain), because this links are pointers, its gives us some cool advantages over Arrays
Strengths
- To add a node(object) to a linked list, you only need to change the pointer in the linked list just like in a connected keychain just by unhooking the other keychain
- Insertion and deletion happen very quickly and in constant time
- There is no discrete size limit unlike an array ( Dynamic sizing )
Weakness
- They take up more memory size because of the pointers
The next types of Data Structures I will be highlighting is all about their retrieval order and how to access information from them.
1. Stack: is a linear data structure that is optimized for the Last-In-First-Out Order ( LIFO ), An example of a Stack is a Pringles Container ( Last- in, First- out ) where you can only take the pringles at the top , this is known as a Pop function and if you want to put the pringles back, it is called a Push function
i.e. Adding to a Stack is called a PUSH while removing from a stack is called POP
Strengths
- Optimized for the LIFO order
Weakness
- Searching takes times ( searching for a pringles require you taking every single pringles out before you can get the required or specified pringles)
- Only works for the LIFO retrieval order
- Queue: just like the name implies, just like a queue of people waiting to be attended to in an airport or a bank, it follows the First-In, First-Out Order (FIFO), others also refer it to as first come , first serve
When you add to the Queue, it is referred to as Enqueue( You add to the back of the data structure) and when you remove from the queue, it is called Dequeue ( take away from the front of the stack )
Strengths
- Insertion and deletion happens in constant time
- The main advantage is the FIFO retrieval order
Weakness
- Searching is tedious and happens in linear time
There we go, these are the basic Data Structures you need to know to get started as a developer or anyone interested in learning Data structures
There are other things to Algorithms which includes Linear Search, Binary Search, Sorting and the likes, Same applies to Data structure and how better to use them.
To get started, Watch FreeCodecamp’s Algorithm and Data Structure tutorial, Full course for beginners ( you’d love it ) click the link below to watch it on YouTube,* youtube.com/watch?v=8hly31xKli0&t=763s*
Thanks for Reading.
Ciao!!!