Introduction to Data Structures

Data Structures are ways of **organizing, storing, and managing data efficiently** in memory so that they can be used effectively in a program. They help in improving **performance, speed, and memory usage**.

What are Data Structures?

A Data Structure is a particular way of storing and arranging data in a computer so it can be accessed and modified efficiently.

Why Do We Need Data Structures?

Without proper data structures, even a simple program may become slow, heavy, and inefficient.

Types of Data Structures

Data structures are mainly divided into two categories:

Linear vs Non-linear Data Structures

Linear Data Structures

Elements arranged in a sequence.

Non-Linear Data Structures

Elements arranged hierarchically.

Applications of Data Structures

Basic Example: Array as a Data Structure

#include <stdio.h>

int main() {

    int marks[5] = {90, 85, 92, 88, 95};
    
    for(int i = 0; i < 5; i++){
        printf("%d ", marks[i]);
    }

    return 0;
}

Basic Example: Linked List Node

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

int main() {

    struct Node* head = (struct Node*) malloc(sizeof(struct Node));
    
    head->data = 10;
    head->next = NULL;
    
    printf("Node value: %d", head->data);

    free(head);
    return 0;
}

Practice Questions

  1. What is a data structure? Explain with examples.
  2. Difference between linear and non-linear data structures.
  3. List five real-life applications of data structures.
  4. Explain the importance of data structures in programming.
  5. What is the difference between primitive and non-primitive data structures?

Practice Task

Create an array of 10 numbers and print: ✔ Maximum value ✔ Minimum value ✔ Sum of all numbers ✔ Average ✔ Count numbers > 50