Every Beginner Should Know These Differences Between Data Structures and Algorithms

A simple guide to understanding the fundamental blocks of Computer Science.

Anand K Parmar
The Startup
5 min readNov 19, 2019

--

Photo by Randy Fath on Unsplash

It’s very difficult to explain these words Data Structures and Algorithms to a person who is a beginner in the Computer Science world.

I exactly remember those initial days of my college when the first time I have heard that jargon around 8 years ago. I struggled a lot to understand these two terms in meaningful ways as I didn’t have much knowledge about Computer Science during that time.

I have observed the same difficulty with many of the beginners which I have faced during my initial days. This led me to write this article which can spread light on the fundamental blocks of Computer Science.

Both of these fundamental blocks are needed to solve Computer Science problems. Where one is the way to solving a problem while the other is organizing and managing the data using which we are solving the problem.

Algorithms are like verbs and Data Structures are like nouns. An Algorithm is just a method of doing something on a computer, while a Data Structure is a layout for memory that represents some sort of data. - Om Singh

Data Structures

A data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. - Wikipedia

Photo on pexels.com

Yes, yes… I know these statements are too difficult to understand and that’s why I am here with this article.

Let’s first break this down to understand what Wikipedia is saying.

A data structure is a data organization, management, and storage format that enables efficient access and modification.

Most of the problems in computer science have some sort of data associated with, using which we have to solve the problem or we have to come up with a sort of conclusion.

So, as the above line states, the data structure is a way to organize and manage that data at memory level such that we can effectively and efficiently do operation on that data. Here, operations on data are like accessing, modifying or maybe deleting that data.

In other words, we have to structure and organize the raw data available for the problem statement, such that we can efficiently perform the required operation to solve the problem.

More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.

Generally, developers know that Data structure is just an organization and management of data but it’s more than that and that’s why Wikipedia has added the above line in the definition. This statement is equally important to understand the role of data structure.

Here, in this statement the most useful words are “… the functions or operations that can be applied to the data”. If you don’t have much knowledge yet about actual data structures(Linked List, Stack, Queue, etc.), then it is very difficult to understand this line of definition.

In layman’s language, we can say that many data structures have the same organization of data at the memory level but they can provide the different functions and operations on them which differentiate with each other.

Let me give an example of the same. Stack and Queue can be implemented using Linked List have the same data organization at the memory level but they are providing different functions that are useful in different scenarios. Like, Queue can be used for First in first out(FIFO) scenarios while Stack can be used in Last in first out(LIFO) scenarios.

Few examples of Data Structures

  • Linear Data Structure: Linked List, Stack, Queue, Array.
  • Hierarchical data structures: Tree, Heap, Trie.
  • Other Data Structures: HashMap, Graph, Matrix.

Note: If you are a beginner and don’t know much about Queues or Stacks or LinkedList, don’t worry. You can follow me for my upcoming series on “Data Structures for beginners with the real-world application”.

Algorithms

An algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation. Algorithms are unambiguous specifications for performing calculation, data processing, automated reasoning, and other tasks. - Wikipedia

Photo by Alvaro Reyes on Unsplash

I can understand that as a beginner you may be confused after reading this definition. Let’s understand this in layman’s language first and then jump to the technical definition of Algorithm.

In the simplest words, Algorithm is nothing but a sequence of steps to be followed to solve any problem or to achieve the desired output.

By taking this simplest definition now in your mind, let's understand the words mentioned in Wikipedia’s definition.

  • Finite sequence: The number of steps to solve a problem should be finite in numbers.
  • Well-defined: There should not be any ambiguity in any step.
  • Computer-implementable instructions: As we are talking about Computer Science related problems here, the steps should be understood by the computer.
  • A class of problems: Set of problems that have the same end goal or may have the same sequence of steps to reach the desired output.

Now let me put this down in one sentence.

An algorithm is a process of finite well-defined steps to be carried out to solve a particular class of problems or to get the desired output.

Few examples of Algorithms

  • Sorting Algorithms: Merge Sort, Quick Sort, Tim Sort, etc.
  • Searching Algorithms: Linear Search, Binary Search.
  • Shortest Path Algorithms: Dijkstra’s algorithm, Bellman-Ford algorithm.

Summing-up

  • Data Structure is about organising and managing data effectively such that we can perform specific operation efficiently, while Algorithm is a step-by-step procedure to be followed to reach the desired output.
  • To understand the Data Structure in a meaningful way, you also have to consider the understanding of memory allocation as well as space and time complexity to perform a specific operation on it.
  • We have to note that, different Data Structures can use the same internal memory management and organisation but they can differ by the functions they are providing which can be used to solve a specific class of problems. (Read the “Data Structures” Chapter).
  • Steps in an algorithm can use one or many data structure(s) to solve a problem.
  • One algorithm can internally use separate Data Structure to solve the same problem but that may lead to varying in performance. Ex. A Graph algorithm can use Adjacency List or Matrix representation of Graph for solving a problem but their Time Complexity and Space Complexity will be vary based on choices of the Data Structure.

I really appreciate your comment on any suggestions/points which you think can help beginners to understand this jargon.

Subscribe to my mailing list and get my latest content on Computer Science, Programming and Personal Finance.

--

--

Anand K Parmar
The Startup

Head of Mobile @ CoFounder App || A quality-obsessed Creator || I write stories on Programming, Tech, and Computer Science || connect@anandparmar.com