Data Structure Introduction and Basic Terminologies
A Data Structure is a particular way of organizing, storing, and managing data in a computer so that it can be accessed, modified, processed, and retrieved efficiently.
Theory & Explanation
What is a Data Structure?
Imagine your room is messy with clothes, books, and toys scattered everywhere. Finding a specific red shirt would be a nightmare.
But if you organize the clothes in a drawer, books on a shelf, and toys in a box, finding that red shirt becomes incredibly easy and fast.
In computing, data is like the mess in your room.
A data structure is simply a specific way of organizing, storing, and managing data inside a computer so that it can be accessed and worked with efficiently.
Think of it as filing cabinet versus a pile on the floor.
You choose different data structures for different jobs.
Just as you wouldn't store soup in a sock, you wouldn't use a complex structure for simple data.
The right choice makes your programs run faster and use less memory.
Why Do We Need Data Structures?
Without data structures, our computers would be chaotic and slow.
Here’s why they are so important:
- Efficiency: They make searching, sorting, and organizing data incredibly fast.
Imagine trying to find a name in an unsorted phonebook versus an alphabetical one.
Data structures help create the "alphabetical phonebook." - Reusability: Once a data structure is designed and built, it can be used in many different programs.
It's like building a sturdy tool you can use over and over. - Abstraction: Data structures allow us to think about the what the data does, rather than the how it's stored at the technical level.
This makes programming much easier.
Basic Terminologies
To talk about data structures, we need a few key words:
- Data: The raw facts and figures—like a single number (25), a name ("Alice"), or a date (24/12/1995).
By itself, data doesn't tell us much. - Information: Data that has been processed and given context to make it meaningful.
For example, "Alice is 25 years old" is information. - Entity: An object or concept about which we store data.
In a student database, 'Student' is an entity. - Attribute: A characteristic or property of an entity.
For a 'Student' entity, attributes would be Student ID, Name, Course, and Age. - Record: A collection of related attributes for a single entity.
All the information about one student (like Student ID: 101, Name: Bob, Course: B.Tech, Age: 20) forms a record. - File: A collection of related records.
All the student records together make up the 'Student File'. - Field: A single item of information within a record.
In our student record, "B.Tech" is the value in the 'Course' field.
Types of Data Structures
Data structures come in different shapes and sizes.
We can generally group them into two main families:
- Primitive Data Structures: These are the fundamental building blocks provided directly by programming languages.
Think of them like atoms.
Examples include integers (whole numbers), floats (decimal numbers), characters (letters), and pointers (which store memory addresses). - Non-Primitive Data Structures: These are more complex structures created by combining primitive data structures.
Think of these as molecules.
They are used to store large, organized collections of data.
They are further divided into:- Linear Data Structures: Data is arranged in a sequence, one after another, like cars in a train.
Examples include arrays, linked lists, stacks, and queues. - Non-Linear Data Structures: Data is arranged in a hierarchical or interconnected network manner, like a family tree or a web of roads.
Examples include trees and graphs.
- Linear Data Structures: Data is arranged in a sequence, one after another, like cars in a train.
Operations on Data Structures
No matter what the structure is, we generally perform the same basic operations on them.
You can remember the main ones with the acronym TRAVERSE:
- Traversing: Visiting each and every piece of data in the structure exactly once.
Think of it like roll call in a classroom. - Searching: Finding the location of a specific piece of data within the structure.
- Insertion: Adding a new piece of data into the structure.
- Deletion: Removing a piece of data from the structure.
- Sorting: Arranging the data in a specific order (e.g., alphabetical or numerical).
- Merging: Combining two different sets of data into a single, larger set.
Worked Example / Dry Run
Putting Terminologies into Practice: The Library Analogy
Let's see how the basic terminologies apply to a familiar setting: a library.
- Entity: A 'Book'
- Attribute: Title, Author, ISBN, Publication Year, Genre.
- Record: All the details for one specific book.
Example: (Title: "To Kill a Mockingbird", Author: "Harper Lee", ISBN: 9780446310789, Year: 1960, Genre: "Fiction") - Field: A single piece of data.
Example: "Harper Lee" is the value in the 'Author' field for this record. - File: The entire card catalog containing all the records for all books in the library.
Program Implementations
#include <stdio.h>
struct Student {
int rollNo;
int marks;
};
int main() {
struct Student s[3] = {
{101, 82},
{102, 76},
{103, 91}
};
printf("Roll No\tMarks\n");
for (int i = 0; i < 3; i++) {
printf("%d\t%d\n", s[i].rollNo, s[i].marks);
}
return 0;
}
Roll No Marks 101 82 102 76 103 91



