Data Structures using Python — #0
Article #0: Series Announcement and Introduction
In this article, we will start our journey together towards learning and implementing Data Structures using Python Programming Language.
The article contains the following sections:
- Series Introduction
- What is a Data Structure?
- Why Learn Data Structures?
Series Introduction
The post is a part of a blog series that will try to cover the concept and the implementation behind many important Data Structures and will also cover some of the important Interview Prep Questions based on these data structures.
Each Data Structure will be covered in 2–3 blog posts. In the first blog post, we will understand the concept behind the data structure and try to analyze the advantages offered. Python implementation of the data structure will be covered in the same article. I will try to provide the best and the most simple implementation that is easy to understand and follow along. Finally, the post will contain a list of questions from various sites like LeetCode, CodeChef, etc. based on the data structure to help us practice and solidify our knowledge.
In the second post, I will discuss the questions and provide solutions to the questions given in the first blog. I will also try to solve the doubts if any from the previous blog. If there are a few more questions that we want to practice, that will be covered in the third blog.
What is a Data Structure?
Data Structure is a means for storing data in a particular structure. This structure allows programmers to perform various operations on the data very efficiently. The operations can be of various types, like quick retrieval of numbers greater/smaller than a given number, check for the presence/count of a particular number in the list of numbers, and many others.
Depending upon our requirements, we can have multiple data structures to help us. Now it is a programmer's decision to select the data structure by analyzing the advantages, disadvantages, and trade-offs of different data structures.
Why Learn Data Structures?
Consider the following simple example.
Suppose we are solving a problem and we want a data structure that will allow us to first, add numbers to a list, and second, given a key calculates and returns the count of that key in the list.
Now, if we decide on using a linear data structure like a list, that stores a list of numbers then, the first operation of insertion can be done quickly. But for doing the second operation we would have to traverse the entire list of numbers and maintain the count of the key. The traversal of the entire list for answering every query is inefficient. Can we do better?
For doing both of the operations efficiently we can use a dictionary in Python. Dictionary in Python is an in-built data structure that allows us to store a key-value pair, where the key acts as an index for the value and allows quick retrieval. So, by using a dictionary that uses the number as the key and its count as the value, we can do both of the operations efficiently.
The ability to understand different data structures, their advantages and disadvantages, and trade-offs between them make a good programmer. For this purpose, we will be learning and implementing various data structures that will help us to be better programmers.
Thanks
Thanks a lot for reading my first article. Please provide your feedback or comments in the comment section. In the next post, we will learn our first data structure ‘Singly Linked List’.