Why are Data Structures and Algorithms so important in Computer Science?
What actually is a computer?
A machine that:
- Takes some input
- Process that input
- Output the result
- Stores that result
Algorithms are everywhere. Anything you do, can be broken down into small steps and that is the Algorithm.
Suppose you want to find a word from a Dictionary. Algorithm involved is:
- Find the Dictionary
- Search for the word
- Look for meaning once you found the word
Now what is a data structure?
Data Structures helps to store data efficiently. A dictionary stores words. And just think if thew words were stored in a random order, it would have become impossible to find a word from the dictionary.
The dictionary stores words in Alphabetical Order. This is the data structure a dictionary follows. The algorithm for searching a word in a dictionary is called Binary Search.
They are also important because, they are what you do after you’ve become a computer scientist.Without,data structures and algorithms, you will be only a monkey coder without the ability to understand how does the code execution takes place inside the computer system.Any developer or cs student must have to write code which provides a required output. Algorithms are methods to implement certain task. Algorithm is general word which suggest a process to perform task in sequential manner. Algorithms are developed to perform task more efficiently. If you write code as per your perception and judgement without applying any predefined algorithm, your code will be botched up after certain time. It is because you haven’t applied any predefined approach or methodology.
Same thing happens with data structures. Data structures are like hands for algorithms to make recipe. Using combination of data structure and algorithms, we can improve performance of program drastically. For example, you are using any searching algorithm like binary search, then set data structure would be perfect rather than array. The reason is, set is much better for checking whether element is present in specified place or not. This is actually not a quite good example but it can tell you the actual need of data structure in algorithms.
Do you think that what difference would it make if we do not use any algorithm or suitable data structure? The ans is — Assume your task is to perform sorting on array of N elements. First you apply normal selection sort which is pretty easy to perform using two nested for loop. Second you apply Quick sort or merge sort which uses recursion and code is like around 50 lines with to many variables and Hodge podge. Now if the value of N is 100 or 1000, your both algorithm implementation would work perfectly without error or lag. Selection sort is O(N²) and Merge sort is O(NlogN) so at max number of comparison will be 1M. They will not lag on i5 at all.
Now think that value of N is 1M. This time your selection sort will stop giving you any result. Number of comparison will be 10¹². So on i5 or i7 also, it will take few hours to complete. On the other hand, merge sort would require only 10⁷ moves which will take around minute (roughly) at max. So this is actual power of algorithms. Array data structure is also perfect for sorting and so that combination of both will make us happy.
We can say that algorithms and data structures are swords for computer science engineers. As much and efficiently you use them, your future will be bright for sure.