In computer science, a data structure is a logical way of organizing data in computer memory so that it can be used effectively. A data structure allows data to be added, removed, stored and maintained in a structured manner. Python supports two types of data structures:
1. Non-primitive data types:-
Python has list, set, tuples and dictionary as its non-primitive data types which can also be considered its in-built data structures.
- List
- Arrays
- Tuples
- Dictionaries
2. User-defined data structures:-
Data Structures that aren't supported by python but can be programmed to reflect the same functionality using concepts supported by python are user-defined data structures. There are many data structures that can be implemented this way:-
- Linked List
- Stack
- Queue
- Tree
- Graphs
- Hash map
Linked List Data Structure:-
A Linked List is a linear data structure, in which the elements are not stored at contiguous memory location. The elements in a linked list are linked using pointers.
output:-
Queue Data Structure:-
Stack Data Structure:-
A Stack is a linear structure that allows data to be inserted and removed from the same end thus follows LIFO (Last in First Out) methodology. Insertion and deletion is known as push() and pop() respectively:-
Python Code:-
Output:-
Tree Data Structure:-
A Tree is a non-linear but hierarchical data structure. The topmost element is known as the root of tree since the tree is start from the root. The elements at the end of the tree are known as its leaves. Trees are appropriate for storing data that aren't linear connect to each other but form a hierarchy.
Graph Data Structure:-
A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. A Graph is consist of a finite set of vertices(or nodes) and set of Edges which connect a pair of nodes.
Hash map Data Structure :-
Hash map are indexes data structures. A hash map makes use of hash functions to compute an index with a key into an array of buckets or slots. Its values is mapped to the bucket with the corresponding index. The key is unique and immutable. In Python, dictionaries are example of hash map.
Python code:-
output:-
If you like this post please Like and share this post and please don't forget to subscribe our Youtube channel - @codin india
Thanks for waching, reading and learning.
:)
Comments
Post a Comment