Introduction to
data structures
Introduction
What is a good program?
A program that
runs correctly
is easy to read and understand
is easy to debug and
is easy to modify
run efficiently
A program is said to be efficient when it executes in
minimum time and with minimum memory space.
Data Structures help us to write efficient programs
What is a Data Structure?
Data structure is the mathematical or logical
organization of data elements in the computer
memory.
Ex: Array, stack, queue, Tree, Graph, dictionary
Why Data Structures
Data must be organized efficiently to speed up the
programs
Eg: imagine searching linearly through an entire
array versus searching data based on some heuristic.
Why is Google so fast?
Because it organizes the data for faster retrieval
It may sometimes cache data for faster search
Classification of data structures
Primitive data structures
The fundamental data types which are supported by a
programming language.
integer, real, character, and boolean.
The terms ‘data type’, ‘basic data type’, and ‘primitive
data type’ are often used interchangeably.
Non Primitive data structures
These are created using primitive data structures.
Ex: linked lists, stacks, trees, and graphs.
Non-primitive data structures can further be
classified into two categories:
linear data structures.
non-linear data structures.
Linear data structures
If theelements of a data structure are stored in a
linear or sequential order, then it is a linear data
structure.
Examples include arrays, linked lists, stacks, and
queues.
Non-Linear data structures
If theelements of a data structure are not stored in
a sequential order, then it is a non-linear data
structure.
The relationship of adjacency is not maintained
between elements of a non-linear data structure
Ex: Trees, Graphs
Operations on data structures
Traversing
Searching
Inserting
Deleting
Sorting
Merging
Real-Life Examples of Data Structures
1. You have to store social network \feeds".
You do not know the size, and things may need to be
dynamically added.
2. You need to store undo/redo operations in a word
processor.
3. You need to evaluate an expression (i.e., parse).
4. You need to store the friendship information on a social
networking site. I.e., who is friends with who.
5. You need to store an image (1000 by 1000 pixels) as a
bitmap.
6. To implement printer spooler so that jobs can be printed in
the order of their arrival.
7. To implement back functionality in the internet browser.
8. To store the possible moves in a chess game.