DSA with Python. Day- 1
In this 75day series we will start learning Data Structures & Algorithms. We will discuss each and every algorithm required to crack good Product Based companies. This will be completely free and you can start following and connect with me in this learning series together.
Pre-requisites before starting?
Need to know basics of Python, Classes and OOPS concepts.
What all topics we will learn in this series?
Below is the list of all such topics —
- Data Structures basics (Implementation of Stacks, Queues, Linked-Lists, Hash-Tables, Trees, Heaps, Graphs etc.)
- Sorting Algorithms : Bubble sort, Selection sort, Insertion sort, Merge sort, Quick sort.
- Searching Algorithms: Linear Search, Binary Search.
- Dynamic Programming: Intro to Dynamic Programming, common problems like Fibonacci sequence, Knapsack Problem.
- Greedy Algorithms: Basic greedy strategies, common problems.
- Backtracking: Understanding backtracking and common problems.
- Advanced Data Structures: Advanced Trees, Advanced Graph Algorithms like Dijkstra's, Prim’s Algorithms etc.
Lastly we will practice a lot of problems from Hacker-rank, Leet-code, Code-Signal as well every day.
So Lets start —
Data Structures?
Organizing, managing and storing data is important as it enables easier access and efficient modifications. Data Structures allows you to organize your data in such a way that helps you to store collections of data, relate them and perform any kind of operations on them accordingly. A data structure is classified into two categories:
i) Linear data structure ii) Non-linear data structure
What is Linear Data Structure?
A linear data structure is a structure in which the elements are stored sequentially, and elements are connected to the previous and the next element. As the elements are stored sequentially hence they can be traversed or accessed in a single run.
The implementation of linear data structures is easier as the elements are sequentially organized in memory. The data elements in an array are traversed one after another and can access only one element at a time. The types of linear data structures are Array, Queue, Stack, Linked List.
What is a Non-linear data structure?
A non-linear data structure is a structure in which the data elements are not arranged in a contiguous manner. As the arrangement is nonsequential, so the data elements cannot be traversed or accessed in a single run. As in the case of linear data structure, elements are connected to two elements (previous and the next element), but here in the non-linear data structure an element can be connected to more than two elements. Trees and Graphs are the types of non-linear data structure which we will be learning in near future upcoming series.
Starting with Linear Data Structures:
Arrays/Lists: An array is a collection of elements usually of same data type stored in contiguous memory locations. In Python we typically use lists to represent arrays since Python lists are Dynamic and can grow or shrink as needed.

# Python code for declaring Arrays/lists using square brackets [].
arr = [110, 203333, 300] # This array stores integers
arr2 = ['c', 'def', 'efr'] # This array stores characters
arr3 = [128.56, 36.2345, 40.11] # This array stores floating elements
Types of Arrays?
There are two main types of arrays:
- One-dimensional arrays: These arrays store a single row of elements.
- Multidimensional arrays: These arrays store multiple rows of elements.
Array Operations?
Common operations performed on arrays includes:
- Traversal : Visiting each element of an array in a specific order (e.g., sequential, reverse).
- Insertion : Adding a new element to an array at a specific index.
- Deletion : Removing an element from an array at a specific index.
- Searching : Finding the index of an element in an array.
Applications of Arrays?
Arrays are used in a wide variety of applications including:
- Storing data for processing.
- Implementing data structures such as stacks and queues.
- Representing data in tables and matrices.
- Creating dynamic data structures such as linked lists and trees.
Python Basics Lists/Arrays Operations?
# Creating a List with
# the use of multiple values
List = ["Rahul", "Codey", "John"]
print("\nList containing multiple values: ")
print(List)
# Creating a Multi-Dimensional List
# (By Nesting a list inside a List)
List2 = [['Rahul', 'Codey'], ['John']]
print("\nMulti-Dimensional List: ")
print(List2)
# accessing a element from the
# list using index number
print("Accessing element from the list")
print(List[0])
print(List[2])
# accessing a element using
# negative indexing
print("Accessing element using negative indexing")
# print the last element of list
print(List[-1])
# print the third last element of list
print(List[-3])
#Iterating/Traversing through a list:
for i in List1:
print(i)
#Inserting element into the List:
List1.append('Johnny') #Inserts Johnny value at last(most right) of the List.
List1.insert(0, 'ABCD') #Inserts at the specified Index(here 0 first param).
#Removal of the element from the List:
List1.pop() # Removes last element by default
List1.pop(0) # Removes the specified index element(here 0).
Conclusion:
So above are the code examples of basic array/lists operations in Python and here we conclude for the Day-1 of learning DSA with Python. Please do comment for any suggestions/topics you want to include in this series and do follow for more such upcoming content. Happy Learning!!!