2. Course Objectives
Understanding the concepts of cost and benefits for data
structures
Understand commonly used data structures
Understand the effectiveness of data structure
Select a data structure for specific requirement
Implement data structures in a programming language
3. Agenda
Introduction to Data Structures
Importance and use of Data Structures
Linked Lists
Stack
Queue
Overview of Trees
Overview of Graphs
Sorting Algorithms
4. Session Agenda
Need of Data Structures
Data Structures Benefits
Data Structures Terminologies
Methodologies for Analyzing Algorithm
Asymptotic Notations
Types of Data Structures
Linear
Non Linear
6. Need for Data Structure
Applications are Complex
Complex Applications demand more Computations
Computations require Complex Data
Complex Data require Complex organization
Complex Organizations require Complex Processing
(Searching, Insertion, Deletion)
Data structures organize data
Provides way of storing data so that it can be used efficiently
7. Selection of Data Structures
The cost of a solution is the amount of resources
The choice of data structure and algorithm can make the
difference in execution of a program
Carefully chosen data structure will allow the most effective
algorithm to be used
A well-designed data structure allows a variety of critical
operations to be performed, using few resources
Quality and performance of the final result depends heavily
on choosing the best data structure
8. How to Select a data structure
Analyze the problem to determine the resource constraints a
solution must meet
Determine the basic operations that must be supported
Quantify the resource constraints for each operation
Select the data structure that best meets these
requirements
Some questions to ask
Amount of data to store
Are all data inserted into the data structure at the beginning,
or are insertions interspersed with other operations?
Can data be deleted? If so, a more complex representation is
typically required
Are all data processed in some well-defined order, or is random
access allowed?
9. Data Structure Philosophy
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 efforts
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
10. Methodologies for Analyzing Algorithm
How much of a computer time and memory is utilized by an
algorithm
Methodologies
Empirical Comparison (run programs)
Asymptotic Algorithm Analysis
The efficiency analysis concentrates on critical operations:
data interchanges (swaps)
comparisons (<, >, ==, ! =)
arithmetic operations (+, -, =)
Factors affecting running time
Critical resources
Size of the input
Machine load
Operating System, Compiler, …
Problem size
11. Types of Data Structures
Base Data Structures
Primitive
Composite
Linear Data Structures
Array
Linked List
Non-Linear Data Structures
Graph
Tree
12. Arrays
Arrays are the most common data structure used to store
collections of elements
Access any element using its index number
Occupies contiguous memory area
Example:
int scores[100];
scores[0] = 18;
scores[1] = 5;
scores[2] = 24;
scores
18 5 24 -2134 ... ... ... 14217
Index 0 1 2 3 . . . . . . . 99
13. Pointers
A variable capable of storing an address is called a pointer
variable.
Consider the variable declaration:
int *ptr;
Such a pointer is said to "point to" an integer.
Storing in ptr the address of an integer variable k is done as
ptr = &k;
The "dereferencing operator" refers to the value of that
which ptr is pointing to.
*ptr = 7;
To print to the screen the integer value stored at the address
pointed to by ptr.
printf("%dn",*ptr);
14. Structures
We can declare the form of a block of data containing
different data types by means of a structure declaration.
For example,
struct person
{
char name[20];
int age;
float weight;
};
We now declare a variable of type person
struct person p;
and access the structure data using this variable as
p.age
15. Structures Continued…
We can also declare a pointer to a structure with the
declaration:
struct person *ptr;
and we point it to our example structure with:
st_ptr = &p;
Now, we can access a given member by de-referencing the
pointer as
(*st_ptr).age = 63;
Or use an alternative syntax as
st_ptr->age = 63;