Introduction to Data Structure

A data structure is a method for storing and organizing data efficiently. They play an important role in various computing tasks like managing large datasets, enabling operations like search, insert, update, and delete to be performed quickly.

Example 1: Student marks in various subjects

  • Data: Raw facts and figures is called data, such as student marks: 50, 90, 15, 100, 13, 32.
  • Data Structure: Organizing this data in an array allows efficient management and access: [50, 90, 15, 100, 13, 32].
  • Information: By processing, various operations (i.e. sort, insert, delete etc.) can be performed on data structure to get the information’s.  (i.e.  count the marks which are greater than 40).

Example 2: Employee Salaries in a Department

  • Data: Individual salaries of employees, like 45000, 56000, 75000, 30000, 90000.
  • Data Structure: Storing these salaries in a list allows easy access and manipulation: [45000, 56000, 75000, 30000, 90000].
  • Information: By processing the list, you can calculate the average salary, find the highest and lowest salaries, or count how many employees earn above a certain amount.

Classification of the data structure

Data structures are classified into two types: primitive and non-primitive. Let’s explain the following diagram of data structure classification.

Classification of the data structure

1. Primitive Data Structures in C

Primitive data structures are basic types built into the language that store a single value of a specific type. Here are some examples:

  • int: Used to store integers. Example: int age = 30;
  • float: Used for storing floating-point numbers (numbers with a decimal point). Example: float temperature = 98.6;
  • char: Used to store a single character. Example: char grade = ‘A’;

2. Non-Primitive Data Structures

Non-primitive data structures are more complex and can be user-defined. They allow storing multiple items, possibly of different types, in a single entity. Here are some common non-primitive data structures.

Arrays: An array is a collection of elements of the same type placed in contiguous memory locations. For example, to store the grades of students, you can use:

int grades[5] = {90, 85, 88, 92, 80};

Structures: A structure in C groups different data types under a single name. Structures are useful for grouping data to form records. For example, a structure to represent a book might look like this:

struct Book {
   char title[50];
   int year;
   float price;
};

In the next lecture, we will see the explanation of Nonlinear data structure.