Introduction to Data Structures & Algorithms.
Hi Guys, This is the first blog of the Data Structures and algorithms blog series. Before going to learn deep lessons on this topic first we’ll have a clear idea of what is data structure and algorithms, why we use and learn them, what occasions we use them etc. First, we’ll learn what is a data structure and what is an algorithm means.
Data Structure: Simply it is a way of storing and organizing data on a computer. But it is also used for processing, retrieving, and storing data.
Algorithm: A set of instructions used to perform a task.
As an example imagine you are going to the office by bus. So what you have to do first is go to the bus stop, then take a bus, and finally, you can go to the office. These are the steps you have to follow if you need to go to the office by bus. This is a simple algorithm we use in our day-to-day lives.
What makes a good algorithm?
- Correctness — each step in the algorithm should be clear and unambiguous
- Efficiency — should be the most effective among many different ways to solve a problem.
Do You Know??
- Facebook and Google use Audio and Video Compression algorithms to transmit videos lively across the internet.
- Google, Apple, and Microsoft maps use Graph algorithms to find the shortest path between two locations.
3. Optimization & scheduling algorithm is used by NASA to arrange solar panels on international space stations.
Types of Data Structures
As shown in the above diagram data structure can be divided into 2 sections; primitive and non-primitive.
Primitive data structures: These are built in the programming language itself and available for the programmer.
Non-primitive data structures: These are user-defined and implemented using combining 2 or more primitive data structures.
Next, non-primitive data structures can be divided into 2 types: linear and non-linear.
Linear data structures: Data elements are arranged in memory in a linear sequential manner. They can be either static or dynamic.
Static Data Structure: This has a fixed memory size. (eg: Array)
Dynamic Data Structure: The size is not fixed and can be randomly updated during the runtime which may be considered efficient concerning the memory (space) complexity of the code. (eg: stack,queue,LinkedList)
Non-Linear Data Structure: Data is connected to several other items and not in a sequential manner. (eg: Graphs, Trees)
Though there are a lot of data structures mentioned above, each of these data structures has its own unique properties which work very efficiently in different circumstances. For instance, graph data structure works perfectly for maps, and stack works perfectly when you have backward and forward buttons in your app due to its LIFO concept.
Types of Algorithms
- Recursive Algorithm — This works as an iterative algorithm. Here, a problem is broken into several sub-parts and called the same function again and again.
- Divide & conquer Algorithm- This consists of 2 parts.
- Divide the problem into smaller sub-problems of the same type & solve those problems recursively.
- Combine the solutions of the sub-problems into a solution to the original problem.
Note: It should contain at least 2 recursive calls in order to name it as Divide & conquer Algorithm.
eg: Quicksort algorithm, Merge sort algorithm
3. Dynamic Programming Algorithm: Remembers the past results and uses them to find the new result by avoiding repetitive calculation of the same part of the problem. ( work based on memoization)
4. Greedy Algorithm: This algorithm takes the best without worrying about future consequences. The solution is built part by part. The solution of the next part is based on the immediate benefit of the next part. The solution giving the most benefit will be chosen as the solution of the next part.
5. Brute Force Algorithm: Simplest approach for a problem. This algorithm simply tries all the possibilities until a satisfactory solution is found.
6. Randomized Algorithm: Use a random number at least once to make a decision.
eg: Quicksort Algorithm
That’s all for now!!
So here marks the end of this tutorial. Congrats on covering the basics of data structures and algorithms. Hope you have learned something new from this article. This is the first step in your journey to learning and mastering data structures and algorithms. Let’s meet with a new topic.