2. Instructor
Dr. Muhammad Anwar
PhD Computer Science (University of Technology Malaysia)
MS Computer Science (University of Lahore)
BS Information Technology (University of Lahore)
Microsoft Certified Professional (MCP)
Microsoft Certified System Engineer (MCSE)
Cisco Certified Network Professional (CCNP)
Cisco IP Communication Specialist (CIPCS)
Project Management Professional (PMP)
3. Objective of the Course
Develop student’s knowledge & skills about
different data structures that help them
to write programs to efficiently
manipulate, store, and retrieve data.
Learn about the concepts of time and
space complexity of computer programs.
Familiar with basic techniques of algorithm
analysis.
Implement data structures concepts in C++
4. Course Outline
Data structure and its types.
Algorithms, properties, specification and
performance analysis.
Abstract data type, dynamic arrays, linked
lists, stacks, queues, tree and graphs.
Sorting and searching algorithms such as
Linear search, Binary search, Bubble sort,
Selection sort, Insertion sort, Merge sort.
Storage and retrieval properties and
techniques for the various data structures
5. Grading policy
Mid Term 20%
Final Exam 45%
Practical* 15%
Quizzes** 10%
Assignment and 10%
Presentation
*Including practical lab report
**Quiz may be surprised
6. Need for Data Structures
Data structures organize data to make the
programs more efficient.
Applications becoming complex that need
more powerful computers. Solving such
problems with the help of programming,
data structures and algorithms.
More complex applications demand more
calculations.
7. Organizing Data
Different data structures are available for
organizing the collection of records that
can be searched, processed in any order,
or modified.
The choice of data structure and algorithm
can make the difference between a
program running in a few seconds or many
days.
8. Efficiency
A solution is said to be efficient if it solves
the problem within its resource constraints.
– Space
– Time
The cost of a solution is the amount of
resources that the solution consumes.
9. Selecting a Data Structure
Select a data structure as follows:
1. Analyze the problem to determine the
resource constraints a solution must
meet.
2. Determine the basic operations that must
be supported. Quantify the resource
constraints for each operation.
3. Select the data structure that best meets
these requirements.
10. Some Questions to Ask
• Are all data inserted into the data structure
at the beginning, or are insertions
interspersed with other operations?
• Can data be deleted?
• Are all data processed in some well-
defined order, or is random access
allowed?
11. 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 effort.
12. Arrays
Elementary data structure that exists as built-in
in most programming languages.
int main( )
{
int x[6];
int j;
for(j=0; j < 6; j++)
x[j] = 2*j;
}
13. Arrays
Array declaration: int x[6];
An array is collection of cells of the same type.
The collection has the name ‘x’.
The cells are numbered with consecutive
integers.
To access a cell, use the array name and an
index:
x[0], x[1], x[2], x[3], x[4], x[5]
15. What is Array Name?
‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.
For example, if we have the code
int a, b;
then we can write
b = 2;
a = b;
a = 5;
But we cannot write
2 = a;
16. Array Name
‘x’ is not an lvalue
int x[6];
int n;
x[0] = 5;
x[1] = 2;
x = 3; // not allowed
x = a + b; // not allowed
x = &n; // not allowed