2. Outlines
About the course
Objectives
Contents
Course Materials
Exams & Evaluations
Introduction to Data Structure
Basic Data Structures
Introduction to Algorithm
Summary
2
3. About the course
Analyze the asymptotic performance of algorithms.
Write rigorous correctness proofs for algorithms.
Demonstrate a familiarity with major algorithms and data structures.
Apply important algorithmic design paradigms and methods of analysis.
Synthesize efficient algorithms in common engineering design
situations.
3
5. About the course
Introduction to Algorithms
3rd edition, Thomas H Cormen Charles E,
Leiserson Ronald L Rivest Clifford Stein,
MIT press.
• Lecture slides and programing examples
will also be shared after very class
5
7. About the course
Regular Lectures:
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday: 09:00 AM to 10:50AM
Consultation Hours:
You can send me an email at any time.
7
9. Definition
◦ A data structure is a way to store and organize data
in order to facilitate access and modifications
◦ No single data structure works well for all purposes,
and so it is important to know the strengths and
limitations of several of them
9
10. Basic Data Structures
10
Basic Data Structures
Linear Data Structures Non-Linear Data Structures
Arrays LinkedLists Stacks Queues Trees Graphs Hash Tables
12. Choosing a Data Structures
The choice of particular data model
depends on two consideration:
◦ It must be rich enough in structure to mirror the actual
relationships of data in the real world
◦ The structure should be simple enough that one can
effectively process the data when necessary
12
13. Basic data structures
Linear structures
◦ Array: Fixed-size
◦ Linked-list: Variable-size
◦ Stack: Add to top and remove from top
◦ Queue: Add to back and remove from front
◦ Priority queue: Add anywhere, remove having highest priority
Hash tables: Unordered lists which use a ‘hash function’ to insert
and search
Tree: A branching structure with no loops
Graph: A Graph consist of a set of vertices V and a set of edges E
13
14. Arrays
Linear array : A list of a
finite number n of
similar data elements
referenced respectively
by a set of n
consecutive numbers
Also known as one
dimensional arrays
14
STUDENT
Usman Saleem
Usama Arshad
Nasir Fida
Tayyab Ahmad
Abdullah
Musa Ahmad
1
2
3
4
5
6
15. Arrays
Multidimensional arrays
◦ Each elements is referenced
by two subscripts
◦ For example, weekly sales
record of a chain of 28
stores, each having 4 depts
15
16. Linked List
Suppose a firm maintains
a file, as shown here
This file could be stored
in the computer by two
columns of nine names
However, there is
redundant information in
such a scheme,
especially if we have
hundreds of names 16
Customer Salesperson
Adams Smith
Brown Ray
Clark Jones
Evans Smith
Farmer Jones
Drew Jones
Geller Ray
Hill Smith
Infeld Ray
1
2
3
4
5
6
7
8
9
18. Alternate representation
(cont.)
Now suppose the firm wants the list of
customers for a given salesperson
◦ Using the data representation in last slide,
search is to be carried out through the
entire file ( not a good solution)
Any Solution?
◦ Arrows to point the other way
18
19. Another representation
19
Salesperson Pointer
Jones 3, 6
Ray 2, 4, 7, 9
Smith 1, 5, 8
Can you think of any disadvantage associated with this scheme ?
◦ Set of pointers will change as customers are added and deleted,
because each salesperson may have many pointers
20. Still another representation
20
Customer Pointer
Adams 5
Brown 4
Clark 6
Evans 7
Farmer 8
Farmer 0
Geller 9
Hill 0
Infeld 0
1
2
3
4
5
6
7
8
9
Salesperson Pointers
Jones 3
Ray 2
Smith 1 3
2
1
Now we can easily insert and
delete customers
This
representation
is an example
of linked list
21. Hierarchical relationship
Data frequently contain a hierarchical relationship between
various elements
Data structure used to reflect such kind of relationship is called a
rooted tree graph or simply a tree.
For example, an employee personal record may contain the
following data items:
◦ Social security number,
◦ Name,
◦ Address,
◦ Age,
◦ Salary,
◦ Dependents
However Name is composed of subitems,
◦ Last,
◦ First
◦ MI (middle initial)
Similarly we have address item
21
25. Other data structures
Stack (LIFO)
◦ E.g., stack of dishes
Queue (FIFO)
◦ E.g., line of people waiting at bus stand
Graph
◦ Sometimes relationship between pairs of
data elements is not hierarchical.
25
28. The Need for Data Structures
Goal: to organize data
Criteria: to facilitate efficient
◦ storage of data
◦ retrieval of data
◦ manipulation of data
Design Issue:
◦ select and design appropriate data types.
(This is the real essence of OOP.)
28
29. After Class Dicussion (Self Test)
Differentiate static and dynamic data structure.
Why Data structure is necessory?
What are the limitations of algorithms?
How the efficiency of an algorithm can be measured ?
29