Data Structures and Algorithms: Why You Need Them

GUPTA, Gagan       Posted by GUPTA, Gagan
      Published: December 7, 2021
        |  

Enjoy listening to this Blog while you are working with something else !

   

Mindset

Bad programmers worry about the code. Good programmers worry about Data structures and their Relationships.

   Computer Programming is all about Data Structures and Algorithms. Computer science legend Donald Knuth once said I don't understand things unless I try to program them. I also believe that the best way to learn an algorithm is to program it. Algorithms and Data structures (I'm deliberately using the Term 'Algorithms' before the 'Data Structures') are essential for any Computer Programmer. As a beginner, one may feel discouraged and frustrated by these concepts. The terms algorithms and data structures both sound abstract and obscure. The reason you feel that way is that you haven't found the right method to let you study the subject deliberately. I'm going to tell you about my roadmap and tips. Be patient, and always keep moving forward.

Don't be intimidated by mathematics

   Data structures and algorithms do involve some mathematical reasoning and proofs, particularly when analyzing the time- and space-complexity of an algorithm. Being able to perform a big-O complexity analysis is certainly important, but you don't need to worry about it too much to start with. You don't need a high IQ or abstract mathematical knowledge. As long as you understand high school mathematics, you have the tools needed to understand data structures and algorithms.

Algorithm

   Algorithms are everywhere. Algorithms are also used heavily in Data Science. An algorithm for a particular task can be defined as "a finite sequence of instructions, each of which has a clear meaning and can be performed with a finite amount of effort in a finite length of time". As such, an algorithm must be precise enough to be understood by human beings. However, in order to be executed by a computer, we will generally need a program that is written in a rigorous formal language; and since computers are quite inflexible compared to the human mind, programs usually need to contain more details than algorithms.

Algorithms can obviously be described in plain English, and we will sometimes do that. However, for computer scientists it is usually easier and clearer to use something that comes somewhere in between formatted English and computer program code, but is not runnable because certain details are omitted. This is called pseudocode, which comes in a variety of forms.

Fundamental questions about algorithms

Given an algorithm to solve a particular problem, we are naturally led to ask:
1. What is it supposed to do?
2. Does it really do what it is supposed to do?
3. How efficiently does it do it?

The technical terms normally used for these three aspects are:
1. Specification.
2. Verification.
3. Performance analysis.

The details of these three aspects will usually be rather problem dependent.

   The specification should formalize the crucial details of the problem that the algorithm is intended to solve. Sometimes that will be based on a particular representation of the associated data, and sometimes it will be presented more abstractly

   For simple problems, it is often easy to see that a particular algorithm will always work, i.e. that it satisfies its specification. However, for more complicated specifications and/or algorithms, the fact that an algorithm satisfies its specification may not be obvious at all. In this case, we need to spend some effort verifying whether the algorithm is indeed correct. In general, testing on a few particular inputs can be enough to show that the algorithm is incorrect. However, since the number of different potential inputs for most algorithms is infinite in theory, and huge in practice, more than just testing on particular cases is needed to be sure that the algorithm satisfies its specification. Formal verification techniques are complex and will normally be left till after the basic ideas of these notes have been studied.

   Finally, the efficiency or performance of an algorithm relates to the resources required by it, such as how quickly it will run, or how much computer memory it will use. This will usually depend on the problem instance size, the choice of data representation, and the details of the algorithm.

Data Structure

   For many problems, the ability to formulate an efficient algorithm depends on being able to organize the data in an appropriate manner. The term data structure is used to denote a particular way of organizing data for particular types of operation.

Generally speaking, a data structure is a way to organize data, while an algorithm is a method or pattern for solving problems.

   Often we want to talk about data structures without having to worry about all the implementational details associated with particular programming languages, or how the data is stored in computer memory. We can do this by formulating abstract mathematical models of particular classes of data structures or data types which have common features. These are called abstract data types, and are defined only by the operations that may be performed on them. Typically, we specify how they are built out of more primitive data types (e.g., integers or strings), how to extract that data from them, and some basic checks to control the flow of processing in algorithms. The idea that the implementational details are hidden from the user and protected from outside access is known as encapsulation



Our On-Premise Corporate Classroom Training is designed for your immediate training needs

Data Structures and Algorithms: Why You Need Them
Data Structures and Algorithms: Why You Need Them

Characteristics of an Algorithm

   Every Algorithm must satisfy the following properties:

Input- There should be 0 or more inputs supplied externally to the algorithm.
Output- There should be atleast 1 output obtained.
Definiteness- Every step of the algorithm should be clear and well defined.
Finiteness- The algorithm should have finite number of steps.
Correctness- Every step of the algorithm must generate a correct output.

Characteristics of a Data Structure

Correctness- Data structure implementation should implement its interface correctly.

Time Complexity- Running time or the execution time of operations of data structure must be as small as possible.

Space Complexity- Memory usage of a data structure operation should be as little as possible.

How Data structures and Algorithms relate

   I am quite sure that by now, you know why and how Algorithms and Data Structures are related to each other. Data structures and algorithms complement each other. The data structure exists for the algorithm, and an algorithm generally suits a specific data structure. Together with the programming language, they are the building blocks of any Computer Program.

   At an even higher level of abstraction are design patterns which describe the design of algorithms, rather the design of data structures. These embody and generalize important design concepts that appear repeatedly in many problem contexts. They provide a general structure for algorithms, leaving the details to be added as required for particular problems

Time versus Space complexity

   When creating software for serious applications, there is usually a need to judge how quickly an algorithm or program can complete the given tasks. For example, if you are programming a flight booking system, it will not be considered acceptable if the travel agent and customer have to wait for half an hour for a transaction to complete. It certainly has to be ensured that the waiting time is reasonable for the size of the problem, and normally faster execution is better. We talk about the time complexity of the algorithm as an indicator of how the execution time depends on the size of the data structure.

   Another important efficiency consideration is how much memory a given program will require for a particular task, though with modern computers this tends to be less of an issue than it used to be. Here we talk about the space complexity as how the memory requirement depends on the size of the data structure.

   For a given task, there are often algorithms which trade time for space, and vice versa. For example, we will see that, as a data storage device, hash tables have a very good time complexity at the expense of using more memory than is needed by other algorithms. It is usually up to the algorithm/program designer to decide how best to balance the trade-off for the application they are designing.



Our On-Premise Corporate Classroom Training is designed for your immediate training needs

Why take the pain?

1. A comprehensive knowledge of DSA is the core foundation of writing good codes. It reduces coding costs and enhances data accuracy, which is the ultimate goal of organizations.
2. To earn salaries as high as the top developers, one need to improve their problem solving abilities by mastering DSA.
3. If one wants to generate as little bugs in their code, then it is utmost importance to excel DSA concepts.
4. Learning DSA is also beneficial for a better understanding of new frameworks and high level programming languages like Angular, React, Vue etc.
5. Programmers who are competent in DSA, can easily perform the tasks related to data processing, automated reasoning or calculations.
6. DSA is significant for developers as it shows their problem solving abilities amongst the prospective employers. Thus, amplifies the chances of getting the job.
7. When one get an exposure to a different range of problem-solving techniques as defined in DSA, it helps to take up the next challenging problem easily.

Conclusion

   Optimization of your code is essential. For that, one has to understand the concepts of Data Structures and Algorithms, along with the implementation of them. Once one is able to identify how an algorithm can be applied, on shall have a much deeper insight into how to design their complex AI / DS / ML solutions.

   I hope this article has given you insight into how important are data structures and algorithms for machine learning and data science, or for any other coding endeavor. Though you'll often come across the exact opposite of my viewpoint - they're not necessary.

   As an engineer or an ML practitioner, your task isn't to start jotting down the problems and write chunks of code to solve them. I'm sure by now you have a stern idea as to what will actually save you time and cost - applied computer sciences backed my structures and algorithms!

   The technology will only be going to become better at what it does as long as programming and coding continues to flourish. Therefore, the importance of Data Structures and Algorithms will remain persistence for the functioning of technologies, navigating what they do and how they do it.

   If you never had your hands at "Tower of Hanoi", try it today, I mean the algorithm. It would be fun !


At Vyom Data Sciences, we can help you build and accomplish your Data Science strategy or approach that suits your business requirements and your company's objectives. If you want to see how we can assist in your Data Science dreams, schedule an appointment with one of our experts today.



Support our effort by subscribing to our youtube channel. Update yourself with our latest video`s on Data Science.

Looking forward to see you soon, till then Keep Learning !

Our On-Premise Corporate Classroom Training is designed for your immediate training needs

Data Structures and Algorithms: Why You Need Them
                         



Corporate Scholarship Career Courses