A data structure is a Specific way to store and organize data in a computer’s memory so that these data can be used efficiently later.
Data may be arranged in many different ways, such as the logical or mathematical model for a particular organization of data is termed as a data structure.
Categories of data structure
- Linear Data Structure
- Non-linear Data Structure
Linear data structure
A Data Structure is said to be linear if its elements combine to form any Specific Order.
- The first way is to provide the linear relationships among all the elements represented using linear memory location. These linear structures are termed as arrays.
- The second technique is to provide a linear relationship among all the elements represented by using the concept of pointers or links. These linear structures are termed as linked lists.
- The common examples of the linear data structure types are:
Arrays
A Array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value. the memory location of the first element of the array
Queues
A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.
Stacks
Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Linked lists
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers.
Nonlinear data structure
This structure is mostly used for representing data that contains a hierarchical relationship among various elements. Types are
Graphs
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.
Binary trees
A tree whose elements have at most 2 children is called a binary tree. Since each element in a binary tree can have only 2 children, we typically name them the left and right child.
String
Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’.
Declaring a string is as simple as declaring a one dimensional array. Below is the basic syntax for declaring a string in C programming language.
char str_name[size];