EzeanaMichael

Posted on

# Data structures and algorithms with python: Linear Data structures.

What are data structures?

Data structures are organized formats or methods of storing data for effective search, retrieval, and use of data.

Operations that can be performed on data structures

• Insertion
• Deletion
• Transversion

Types of data structures.
There are 2 types of data structures

1. - Linear Data structure
2. - Non-linear Data structure

Linear Data structure
In this type of data structure, data is stored in an ordered or sequential manner.
There are 3 types of linear data structures:

• Stack
• Queue

1. Stack
Stack is a linear data structure that follows a last in first out(LIFO) method. A real-world example is a stack or deck of cards.

Image gotten from tutorialspoint

There are 2 main operations in a stack:

• Push: The function of the push operation is to put a new data item or element into the top of the stack.
• Pop: The function of the pop operation is to delete or remove the last element to enter the stack.

A stack function in python that demonstrates how it works.

2. Queue
This is a type of linear data structure that stores data in a sequential manner and follows a First in First out (FIFO) method. A real-world example of this is cars queuing in traffic.

Image gotten from tutorialspoint

There are 2 main operations in a queue:

• Enqueue: This is an operation that adds a data item or element to the back of the queue.
• Dequeue: This is an operation that removes a data item or element at the front of the queue.

Implementation of queue data structure in python:

A LinkedList is an ordered data structure which consists of a connection of nodes which contains data items and a connecting link to the next node.

There are 3 different types of linked list:

• Single linked list: In this type of linked list, there is one head and a tail/exit of the linked list with each node pointing to the next.

• Double linked list:In this type of linked list, there is one head and two tails/exits of the linked list with each node pointing to the next and previous node.

• Circular linked list:In this type of linked list, there is one head. The next of the last node points to the first node and the previous of the first node points to the last node.

Images gotten from geekforgeeks