What are Fundamentals of Data Structure in C?
A data structure is a particular configuration of information for arranging and saving information so any client can easily get to and work inside specified data to run a program proficiently. PC memory data can be coordinated logically or numerically, and this interaction is known as a data structure. By and large, choosing a specific configuration of data relies upon two elements. The data should be sufficiently rich to fulfill the genuine relationship of the data in reality. What’s more, then again, the data design should be easy to the point that one can without much of a stretch cycle the data when it should be utilized.
Fundamentals of Data Structure in C
Now let’s see the different fundamental concepts of data structure in c as follows.
- Linear: In linear data structure we arrange the data in a sequential manner like array structure.
- Non-Linear: In nonlinear data structure we arrange the data in a non-sequential manner like graph and tree structure.
- Static: It is a static data structure that depicts the size and structure of a collection of data values related to a memory area at assemble time that is fixed. For example- Array.
- Homogenous: It is a quality of data structures addressing whether the data types of all components are the same for example Array.
- Non-Homogenous: It is a quality of data structures addressing whether the data types of all components are not the same.
- Dynamic: It is a dynamic data structure that characterizes the contracting and growing of data items at the run time or the program’s execution. It is likewise identified with the usage of the memory area that can be changed at the program’s run time for example Linked List.
- It has a few principles that characterize how the data items are identified with one another.
- It characterizes a few guidelines to show the relationship between data items and how they communicate with one another.
- It has a few tasks used to perform on data items such as insertion, deletion and searching, and so on.
- It helps in reducing the utilization of memory assets.
- Time Complexity: It is used to define how much time is required for the execution of a program and it should be less as possible.
- Space Complexity: It is used to define how much memory space is required for the execution of a program and it should be less as possible.
Types of Data Structure
Basically, there are two types of data structure.
- Primitive Data Structure
- Non Primitive Data Structure
Primitive Data Structure
Basically Primitive Data types directly work with the machine instruction and it has different data types for different machines such as integer, float, character, string, constant and pointer.
Non Primitive Data Structure
This is a complex data structure as compared to the primitive data structure. It works on clusters or we can say that grouping the same or different data values and it includes the following data structure as follows.
Array: Normally an array is a collection of values that are stored in a sequential manner in a memory location. If we need to store the multiple values that have the same data type at that time we can use an array data structure. The array data structure we illustrate by using the following figure as follows.
In the above figure we show the value of the array that is 10, 20, 30, etc, and the index of array 0, 1 to 7. Note here array index always starts with 0.
List: List we divide into two different categories as follows.
- Linear List
- Non Linear List
Linear List: Linear data structure can further be divided into two parts as follows.
- Stack: Stack is one type of data structure in which we can store the data element. On the stack, we can perform the two types of operation such as push and pop. By using push operation, we can add the element into the stack and by using pop operation we remove the top element of the stack, so that reason stack works as LIFO manner (Last In First Out). The stack data structure we illustrate by using the following figure as follows.
- Queue: Queue is also a linear data structure in which we can add elements from the rear side and we can remove elements from the front side of the queue. The queue works as FIFO manner means (First In First Out). The queue data structure we illustrate by using the following figure as follows.
Non Linear List: Non linear list means there is no sequence to store the data; in other words, we can say that every element has multiple paths. The Non linear list also has two categories as follows.
- Graph: Basically a graph is a collection of different nodes and nodes containing data value, all nodes are connected to other nodes in the graph. Between two nodes one link is present that we call edge. So, G= (Vertices and Edges)
Graph has different terminology. The graph data structure we illustrate by using the following figure as follows.
- Trees: A tree is a nonlinear data structure, in which nodes are connected by using edges and it maintains the hierarchical data structure. See other data structures work in a sequential manner, suppose we need to perform any operation that increases the complexity of structure, so that is the reason we use tree data structure. The tree data structure we illustrate by using the following figure as follows.
Example of Fundamentals of Data Structure in C
Now let’s see a basic example in a data structure as follows.
Normally we can implement Array, Linked List, Stack, Queue, Tree and graph, etc. in Data structure by using the C programming language.
#define MAX 50
int que_rear = - 1;
int que_front = - 1;
printf("1.Add Data Element \n");
printf("2.Delete Data element \n");
printf("3.Display Data elements \n");
printf("Enter choice : ");
printf("Choice is incorrect \n");
if (que_rear == MAX - 1)
printf("Now Queue is Overflow \n");
if (que_front == - 1)
que_front = 0;
printf("Enter data element : ");
que_rear = que_rear + 1;
que_array[que_rear] = add_element;
if (que_front == - 1 || que_front > que_rear)
printf("Now Queue is Underflow \n");
printf("Data Element deleted: %d\n", que_array[que_front]);
que_front = que_front + 1;
if (que_front == - 1)
printf("Empty Queue \n");
for (a = que_front; a <= que_rear; a++)
printf("%d ", que_array[a]);
Explanation: By using the above example we try to implement the queue in the data structure by using C programming. The final output of the above statement we illustrate by using the following snapshot.
We hope from this article you learn the Fundamentals of data structure in C. From the above article, we have learned the basic theory of Fundamentals of data structure and we also see different examples of Fundamentals of data structure. From this article, we learned how and when we use the Fundamentals of data structure in C.
This is a guide to Fundamentals of Data Structure in C. Here we also discuss the definition and different fundamental concepts of data structure in c along with examples and its code implementation. You may also have a look at the following articles to learn more –