User Defined Data Structure in Python

 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 Data Structure:-

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.

Linked List

Python code:-

Linked List data structure

output:-

Linked List


Queue Data Structure:-

A Queue is a linear data structure that allows insertion of elements from one end and deletion from other end.  Thus it follow FIFO(First in first out) methodology. The end which allows deletion is known as front end of the queue and the other end is known as rear end of the queue.
Queue data structure
Python Code:-

Queue data structure code

Output:-
Queue data structure output


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:-

Stack data structure

Python Code:-

Stack data structure code


Output:-

Stack data structure 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.

Tree data structure tutorial

Python code:-
    
Tree data structure

Output:-

Tree data structure

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.

Graph data structure tutorial

Python code:-
Graph data structure tutorial

Output:- 
Graph data structure using python

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.

Hash data structure

Python code:-

Python Hash map tutorial

output:-

hashmap data strcuture

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