Introduction to DSA

March 18, 2020 || 2 min

Hey everyone, in this series we will go through the basics of Data Structures and Algorithms. This post is the first article in the series. The series is based on my learnings from the course with the same name taught at BITS Pilani, Rajasthan, India. The series will cover the following topics in no particular order -

  1. Introduction
  2. Linear Structures (Arrays, Linked lists)
  3. Non-Linear Structures (Trees, Graphs)
  4. Sorting and Searching Techniques (including Hashing)
  5. Performance Analysis (Time and Space Complexity)

Most of the content of the course is handpicked from the book Introduction to Algorithms by Cormen (CLRS). I highly recommend reading it if you are stuck at any point. You can find it here (for free!).

In this article, we will cover the basics of Data Structures and Algorithms - the definitions, their advantages, etc.

1. Data Structure -

A Data structure is a way of storing and organizing data so that it can be used efficiently. For example, let's assume that we want to write the names of people along with their phone numbers in a diary. Consider two cases -

  1. We write the names of people followed by their phone numbers starting from page 1 followed by page 2 and so on.
  2. We reserve one page for each letter (A, B, C, D,.., Z) and write the names of people and their phone numbers on the page reserved for the first letter of the first name. For example - Tanya's phone number will be stored on the page reserved for the letter 'T'.

Now the method we choose for writing names depends on our use. If we want to make a phonebook, the second way is probably better since we can search a phone number easily later (go to the page marked 'T' for getting the phone number of Tanya) but if we just want to write 2 or 3 phone numbers method 1 is better.

So the data structure we use helps us to manage and organize our data more efficiently and makes our code cleaner and efficient. Some commonly used data structures are Arrays, Linked Lists, Graphs, Trees, Stack, Queue. The common operations performed on data structures are Sorting, Merging, Deleting, Inserting, Traversing, Searching.

2. Algorithms -

An algorithm is a finite set of instructions that accomplishes a particular task. It is a high level (human-readable), language-independent description of a step by step process for solving a problem. Algorithms and Data Structures together make a computer program that solves a problem like storing phone numbers of people alphabetically efficiently.

That's it for this one. In the next article, I will talk about Performance Analysis. Please reach out to me on twitter if you have any suggestions or requests.