Lec 01
Lec 01
to
Data Structures
1
Variables
• Before going to the definition of variables, let us
relate them to old mathematical equations.
• All of us have solved many mathematical
equations since childhood. As an example,
consider the below equation:
2
Variables
4
Data Types
5
System-defined data types
(Primitive data types)
• Data types that are defined by system are called
primitive data types.
• The primitive data types provided by many
programming languages are: int, float, char,
double, bool, etc.
• The number of bits allocated for each primitive
data type depends on the programming
languages, the compiler and the operating system.
6
System-defined data types
(Primitive data types)
• For the same primitive data type, different
languages may use different sizes.
• Depending on the size of the data types, the total
available values (domain) will also change.
7
User defined data types
struct newType{
int data1;
float data2;
…
char data;
};
9
Data Structures
10
Data Structures
11
Data Structures
12
Abstract Data Types (ADTs)
13
Abstract Data Types (ADTs)
14
Abstract Data Types (ADTs)
15
Abstract Data Types (ADTs)
16
Abstract Data Types (ADTs)
17
Abstract Data Types (ADTs)
• The most commonly used operation on data
structure are broadly categorized into following
types:
– Create
– Selection
– Updating
– Searching
– Sorting
– Merging
– Destroy or Delete
18
Arrays
19
Lists
20
Stack
21
Queue
22
Trees
23
Graph
24
Graph
25
Efficiency
27
Summary
• Each data structure has costs and benefits.
• Rarely is one data structure better than another in all
situations.
• A data structure requires:
– space for each data item it stores,
– time to perform each basic operation,
– programming effort.
• Each problem has constraints on available space and
time.
• Only after a careful analysis of problem characteristics
can we know the best data structure for the task.
28