Introduction To Data Structures And Algorithms With Python. 
Published: 2022-02-21 21:32:26

**Introduction**
A data structure is a particular way of organizing data in a computer so that it can be used effectively. Data structures are fundamental concepts of computer science that help in writing efficient programs in any language. Python is a high-level, interpreted, interactive and object-oriented scripting language which we can use to study the fundamentals of data structure in a simpler way as compared to other programming languages. The primary purpose of data structures is to provide a method for organizing data so that it may be used effectively.
An algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language.
The various data structures in computer science are divided broadly into two categories shown below:
**• Linear data structures** - these are data structures that store data in a sequential manner and the elements are connected to the previous and the next element. As the elements are stored sequentially, so 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.
**a) Array:** An array consists of data elements of a same data type. For example, if we want to store the roll numbers of 10 students, so instead of creating 10 integer type variables, we will create an array having size 10. Therefore, we can say that an array saves a lot of memory and reduces the length of the code.
**b) Stack:** It is linear data structure that uses the LIFO (Last In-First Out) rule in which the data added last will be removed first. The addition of data element in a stack is known as a push operation, and the deletion of data element form the list is known as pop operation.
**c) Queue:** It is a data structure that uses the FIFO rule (First In-First Out). In this rule, the element which is added first will be removed first. There are two terms used in the queue front end and rear.The insertion operation performed at the back end is known ad enqueue, and the deletion operation performed at the front end is known as dequeue.
**d) Linked list:** It is a collection of nodes that are made up of two parts, i.e., data element and reference to the next node in the sequence.
**e) Tuple:** Tuples are similar to lists but they are immutable which means the values in a tuple cannot be modified they can only be read.
**f) Dictionary:** The dictionary contains Key-value pairs as its data elements.
**g) List**: It is similar to array with the exception that the data elements can be of different data types. You can have both numeric and string data in a python list.

**• Non-linear data structures** – these are data structures where data elements are not arranged in a nonsequential order, so the data elements cannot be traversed or accessed in a single run. In the case of linear data structure, an element is connected to two elements (previous and the next element), whereas, in the non-linear data structure, an element can be connected to more than two elements.
The types of non-linear data structures are trees and graphs
**a) Tree** - A tree consists of various linked nodes. It has a hierarchical tree structure that forms a parent-child relationship. The diagrammatic representation of a tree data structure is shown below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nm47y1552g2vxk90l7jf.png)
 

 
For example, the posts of employees are arranged in a tree data structure like managers, officers, clerk. In the above figure, A represents a manager, B and C represent the officers, and other nodes represent the clerks.
**b) Graph** - A graph is has a finite number of vertices and edges, and these edges are used to connect the vertices. The vertices are used to store the data elements, while the edges represent the relationship between the vertices. A graph is used in various real-world problems like telephone networks, circuit networks, social networks like LinkedIn, Facebook. In the case of facebook, a single user can be considered as a node, and the connection of a user with others is known as edges.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vd632n4ibcyv7kg06hop.png)
 
 **Various Operations that can be performed on Data Structures:**
**1. Insertion** - Adding a new data item to the specified data item collection.
**2. Delete** - Removes an existing data item from a collection of data items.
**3. Traversal** - Only access each data item once in order to process it.
**4. Searching** - If the data item exists in the given collection of data items, find its location.
**5. Sorting** - entails arranging data items in a specific order, such as ascending or descending for numerical data and dictionary order for alphanumeric data.

**Conclusion**
Data structures and algorithms a defined in quite a number of ways, just make sure to understand what you read and also make sure to practice a lot since it’s the only way to get these skills.