A data structure is a method of storing data in a computer so that it can be used effectively. A data structure is a specialized format for organizing and storing information.
A data structure is a method of organizing data so that any operation on it can be performed efficiently.
Arrays, files, linked lists, stacks, queues, trees, and graphs are examples of general data structure types.
Types of Data Structure
1. Primitive Data Structure
A primitive data structure is a predefined data structure that stores a single value. A primitive data structure is a type of data structure that stores only one type of data. The fundamental data structures are primitive data structures.
It can perform direct operations on data and machine instructions.
It is also referred to as a basic data structure.
Primitive data structures are defined by programming languages, or they are built-in.
Integer, Boolean, character, floating-point number, and String are examples of primitive data types.
Essentially, the terms ‘data-type and ‘data structure’ are frequently used interchangeably.
Integer:- The numeric values are stored in the integer data type. It contains whole numbers that can be positive or negative.
Float:- The float data type can store decimal values. which contains a formulaic representation of real numbers
Character:- It is a data type that can store a single uppercase and lowercase character value, such as ‘A’ or ‘a’.
String:- String is a collection of characters.
Boolean:- A data type that can store either a True or False value. It is primarily used to check the condition.
2. Non-Primitive Data Structure
A Non-primitive data structure is a defined data structure that stores multiple values. A non Primitive data structure is a type of data structure that stores multiple value types of data. Non-primitive data structures are those that are created by using primitive data structures.
As compared to primitive data structure it is a little bit complicated.
linked lists, stacks, trees, and graphs are examples of non-primitive data types.
A non-primitive data structure is further divided into two-part:-
- Linear Data structure in linear data structure elements are organised sequentially so that each element is attached to its previous and next adjacent elements. Example of linear data Structure Array,Stack , Queue and linked list
Array:- An array is a collection of items that are stored in contiguous memory locations.
Stack:- A stack is a linear data structure in which operations are performed in a specific order. It is based on the principle of LIFO (LAST IN FIRST OUT).
Queue:- A queue is a linear structure in which operations are performed in a specific order. It is based on the principle of FIFO (FIRST IN FIRST OUT).
Linked list:- A linked list is a type of linear data structure in which the elements are not stored in consecutive memory locations. A linked list is made up of nodes, each of which has a data field and a reference (link) to the next node in the list.
- Non-linear Data Structure Data elements in a non-linear data structure are attached hierarchically. It is opposite of linear data structure that means elements are not organised sequentially . Example of non-linear data structure Graph and Tree
Graph:- A graph is a nonlinear data structure made up of nodes and edges. The nodes are also known as vertices, and edges are lines or arcs that connect any two nodes in the graph.
Tree:- A tree is a hierarchical data structure consisting of nodes. Value is represented by nodes, which are connected by edges. Each node has a single parent but may have multiple children. Each node has an edge that connects it to its children.