You are on page 1of 27

Lecture 1

sidra.malik@ciitlahore.edu.pk
Course Information
Textbooks
Classic Data Structures
D. Samanta

2
Grading
Theory
Quizzes (3) ---------------15%
Assignments (3)---------10%
S-1 ------------------------ 10%
S-2 ------------------------ 15%
Final-------------------- 50%
Labs
Assignments/Exercises ---------- 15%
S1 and S2---------------------------- 25%
Final----------------------------------- 50%

3
What is Data Structure?
Data structure is a representation of data and the
operations allowed on that data.

A data structure is a way to store and organize data in


order to facilitate the access and modifications.

Data Structure are the method of representing of logical


relationships between individual data elements related to
the solution of a given problem.

5
Basic Data Structure
Basic Data Structures

Linear Data Structures Non-Linear Data Structures

Arrays Linked Lists Stacks Queues Trees Graphs Hash Tables

6
array

Linked list

queue
tree stack

7
Selection of Data Structure
The choice of particular data model depends on
two consideration:
It must be rich enough in structure to represent the
relationship between data elements
The structure should be simple enough that one can
effectively process the data when necessary

8
Types of Data Structure
Linear: In Linear data structure, values are arrange in linear
fashion.
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 the highest
priority

9
Types of Data Structure
Non-Linear: The data values in this structure are not
arranged in order.
Hash tables: Unordered lists which use a hash function to insert
and search
Tree: Data is organized in branches.
Graph: A more general branching structure, with less strict
connection conditions than for a tree

10
Type of Data Structures
Homogenous: In this type of data structures, values of the
same types of data are stored.
Array

Non-Homogenous: In this type of data structures, data


values of different types are grouped and stored.
Structures
Classes

11
Abstract Data Type
Definition:-
Abstract Data Types (ADTs) stores data and allow various
operations on the data to access and change it.

ADT) is a mathematical model for a certain class of data


structures that have similar behavior; or for certain data types of
one or more programming languages that have similar
semantics.

An ADT is a collection of data and associated operations for


manipulating that data

12
Abstract Data Type vs. Data Structure
A mathematical model, together with various operations defined on
the model
An ADT is a collection of data and associated operations for
manipulating that data

Data Structures
Physical implementation of an ADT
data structures used in implementations are provided in a language
(primitive or built-in) or are built from the language constructs (user-
defined)

13
Abstract Data Type
ADTs support abstraction, encapsulation, and
information hiding.

Abstraction is the structuring of a problem into well-


defined entities by defining their data and operations.

The principle of hiding the used data structure and to


only provide a well-defined interface is known as
encapsulation.

14
Abstract Data Type vs. Data Structure

Examples
List in ADT
Supporting Data Structures are matrix, linear list, tree, graph.
If we place list in ADT , users should not be aware of structure we use
As long as they can insert and retrieve data

Waiting line in a Bank


Supporting Data Structures are Queues not available in programming
languages
Solution?
Simulate a Queue
Writing a Queue ADT which may use to solve many Queue Problems
Advantage?

ADT is a data declaration packages together with the


operation that are meaningful for data type

15
The Core Operations of ADT
Every Collection ADT should provide a way to:
add an item
remove an item
find, retrieve, or access an item

Many, many more possibilities


is the collection empty
make the collection empty
give me a sub set of the collection

16
Which Data Structure to Use?

No single data structure works well for all purposes, and so


it is important to know the strengths and limitations of
several of them

17
List
A Flexible structure, because can grow and
shrink on demand.
Arrays and Link List
Elements can be:
Inserted
Accessed
Deleted
At any position
last
first

18
Linked Lists Vs Arrays
Advantage of Linear Linked Lists over Arrays
No need to shift elements in order to make room or to
remove an element
Easy insertion and deletion

19
Stacks
Collection with access only to the last element inserted
Last in first out
Data4 Top
insert/push
remove/pop Data3

top Data2
make empty
Data1

20
Queues
Collection with access only to the item that has been
present the longest
Last in last out or first in first out
enqueue, dequeue, front
priority queues and dequeue
Front Back

Data1 Data2 Data3 Data4

21
Tree
A Tree is a collection of elements called nodes.
One of the node is distinguished as a root, along with a
relation (parenthood) that places a hierarchical structure
on the nodes.
Root

22
Algorithms
An algorithm is a procedure for solving a problem in finite
number of steps

Algorithm is a well defined computational procedure that


takes some value (s) as input, and produces some value (s)
as output.

Algorithm is finite number of computational statements


that transform input into the output

An Algorithm is said to be accurate and truthful only when


it provides the exact wanted output.
23
Algorithms
An algorithm may be given in different forms.
A description using English/other languages
A real computer program, e.g. C++
A pseudo-code, C-like program, program-language-like
program.

Program = algorithms + data structures

24
Analysis of Algorithms
Why need algorithm analysis?
Just writing a syntax-error-free program is not enough. We need to
know whether the algorithm is correct or not, i.e. whether it can
give correct answers for the inputs.

If the program is run on a large data set, the running time becomes
an issue. We want to know how the algorithm performs when the
input size is large. The program may be computationally inefficient,
or may need lots of memory. We analyze the resources that the
algorithm requires: memory, and computation time. We can also
compare algorithms without implementations.

We analysis algorithms, rather than problems. A problem can be


solved with several algorithms, some are more efficient than others.

25
Analysis of Algorithms
Analysis of Algorithm refers to calculating or guessing
resources needful for the algorithm.
Resources means computer memory, processing time
etc.
In all these factors, time is most important because the
program developed should be fast enough.

26
Analysis of Algorithms
Analysis of Algorithm refers to calculating or guessing
resources needful for the algorithm.
Resources means computer memory, processing time
etc.
In all these factors, time is most important because
the program developed should be fast enough.

27

You might also like