Data Structures and its types

Data Structure – Data Structures are not only allow the user to combine various data types in a group but also allow processing of the group as a single unit thereby making things much simpler and easier. 
The data structure can be classified into two types:
1. Simple Data Structure
2. Compound Data Structure
Simple Data Structure – are normally built from primitives data types like integer, reals, character, Boolean etc. Following data structures can be termed as Simple Data Structures: Example: Arrays and Structures
Compound Data Structure – Simple Data structure can be combined in various ways to form more complex structures called Compound Data Structure. There are two types of Compound Data Structures:
Linear  – A data structure is said to be linear if its elements form a sequence. They are single level. They are : Stacks, Queues, Linked Lists
Non-Linear  – These are multiple. They can not make sequence. They are: Trees and Graphs
Following figure shows all the data structures:

Types of Data Structures:
1. Array
– Array is a named list of similar or homogeneous data types, referenced by a common name and different index.  If the name of an array of 10 elements is ARY, then its indexes are 01,2,….9 and the elements will be referenced as ARY[0], ARY[1],ARY[2]………….ARY[9]
2. Structure – It is a named collection of same or different data types. The elements of a structure are referenced using a dot operator.
3. Stack: It allows adding and removing elements in a particular order. Every time an element is added, it goes on the top of the stack; the only element that can be removed is the element that was at the top of the stack. Consequently, a stack is said to have LIFO ie “Last in, First out” or FILO ie “First in, Last Out“. The first item added to a stack will be the last item removed from a stack. 
Example a stack of plates where each plate after washing will be kept at the top of the stack and every person will take plate from the top of the stack only.

Terminology of Stacks: Stacks have some useful terminology associated with them: 
a) Push To add an element at the TOP of the stack 
b) Pop To remove an element from the TOP of the stock
c) Peek To display the element at the TOP of the stack 
d) Display To display all the elements of the stack 
4. Queue Queues data structures are FIFO(First In First Out) lists where insertions are take place at the REAR end of the queue and deletions take place at the FRONT end of the queue. When a Queue is created an array, its number of elements is declared before processing. The beginning of array becomes its Front end and the end of the array becomes its Rear end. Front stores the index of first element in the queue and Rear stores the index of last element in the queue. 
Example: a line of people waiting for their turn to do payment at shopping mall. First person will be the first to pay and a new person can join the queue, at the rear end of it.

Terminology of Queues: Queues have some useful terminology associated with them: 
a) Enqueue – Insert new element at Rear end of the queue
b) Dequeue – Delete the element from Front end of the queue
c) Peek To display the element at the FRONT of the queue 
d) Display To display all the elements of the queue
5. Linked Lists : It is a linear data structure that consists of a sequence of nodes, where each node contains data and a reference (or pointer) to the next node in the sequence. Unlike arrays, which have a fixed size, linked lists can grow or shrink dynamically during program execution. They are useful for situations where the size of the data is not known beforehand, and you need to add or remove elements frequently. However, they have some disadvantages such as inefficient access to individual elements and the need for extra memory for storing the references. Linked lists can be used to implement various data structures such as stacks, queues, trees and graphs.

6. Tree: It is a hierarchical data structure that consists of nodes connected by edges or branches. Each node in a tree may have zero or more child nodes, except for the root node, which has no parent. The tree is often used to represent hierarchical structures like file systems, organization charts, or family trees. The topmost node in a tree is called the root, and each node in the tree can have any number of children. Nodes with no children are called leaf nodes or terminal nodes. The path from the root node to any node in the tree is called a path, and the length of the path is the number of edges along that path.

7. Graph: It is a data structure consisting of a set of vertices (also called nodes or points) and a set of edges that connect pairs of vertices. A graph can be used to represent a variety of things, such as roads and cities in a map, social networks, or dependencies between tasks in a project. Each vertex in a graph can have zero or more edges connecting it to other vertices, and an edge can be directed (going from one vertex to another) or undirected (going both ways). A graph with directed edges is called a directed graph or a digraph, while a graph with undirected edges is called an undirected graph.

error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.