Professional Documents
Culture Documents
Data Structure and Algorithms (CSC-216)
Data Structure and Algorithms (CSC-216)
Data Structure and Algorithms (CSC-216)
Algorithms(CSC-216)
1
Introduction
Muhammad Asad
Lecturer at CUSIT
MS Computer Software Engineering,
NUST, Islamabad
BS Computer System Engineering,
GIKI, Topi 2
Professional Experience
5 Years freelancing experience
Students in around 30+ countries
3
Data Structure and Algorithms(CSC-216)
Lecture # 1
Email: Muhammad.asad@cusit.edu.pk
4
Text Books:
A. M. Tenenbaum, Data Structures using C++, Prentice-Hall, New
Delhi.
Reference Books:
Seymour Lipschutz, Theory and Problems of Data structures, 2nd
Edition.
6
Path to A grade
Mid (1) 25
Project (1)10
Quizzes(5) 10
Assignments(4) 4
100% Attendance 1
FINAL 50
7
Basic Terminologies
Data
Data item
Group Items
Elementary Items
Entity
Attributes
Information
Field
Record
File
8
Basic Terminologies cont…
Data
Simply collection
facts and figures (digital or Analog )
may be in (voice or graphics or Text) OR
Data are values or set of values.
Data Item
A data item refers to a single unit of values.
9
Basic Terminologies cont…
In the above example ( ID, Age, Gender, First, Middle, Last, Street, Area ) are
elementary data items, whereas (Name, Address ) are group data items.
10
Basic Terminologies cont…
Entity & Attributes
An entity is something that has certain attributes or properties which may be
assigned values. The values themselves may be either numeric or non-numeric.
Example: Employee is an entity
Entities with similar attributes (e.g. all the employees in an organization) form an entity
set. Each attribute of an entity set has a range of values, the set of all possible values
that could be assigned to the particular attribute.
11
Basic Terminologies cont…
Information
The term “information” is sometimes used for data with given attributes, of, in other
words meaningful or processed data.
Field
A field is a single elementary unit of information representing an attribute of
an entity.
Record
A record is the collection of field values of a given entity.
File
A file is the collection of records of the entities in a given entity set.
12
Basic Terminologies cont…
Structure
The structure means a series of rules by which the data items are combined.
Data Structures
13
Examples of Data Structures
Queue Stack
Tree
Linked List
Graph 14
Categories of Data Structures
The data structure can be classified in to major types:
Linear Data Structure
Non-linear Data Structure
A data structure is said to be linear if its elements form any sequence. There are basically two ways of
representing such linear structure in memory.
a) One way is to have the linear relationships between the elements represented
by means of sequential memory location. These linear structures are called
arrays.
b) The other way is to have the linear relationship between the elements represented
by means of pointers or links. These linear structures are called linked lists.
The common examples of linear data structure are
Arrays
Queues
Stacks
Linked lists
15
Categories of Data Structures
a) Arrays:
The simplest type of data structure is a linear (or one dimensional) array. A
list of a finite number n of similar data referenced respectively by a set of n
consecutive numbers, usually 1, 2, 3 . . . . . . . n. if we choose the name A for the
array, then the elements of A are denoted by subscript notation
A1, A2, A3 . . . . An
or by the parenthesis notation
A (1), A (2), A (3) . . . . . . A (n)
or by the bracket notation
A [1], A [2], A [3] . . . . . . A [n]
16
Categories of Data Structures
Example:
A linear array A[8] consisting of numbers is pictured in following figure.
17
Categories of Data Structures
b) Linked List
A linked list, or one way list is a linear collection of data elements, called
nodes, where the linear order is given by means of pointers. Each node is
divided into two parts:
The first part contains the information of the element/node
The second part contains the address of the next node (link /next pointer field) in
the list.
There is a special pointer Start/List contains the address of first node in the
list. If this special pointer contains null, means that List is empty
18
Categories of Data Structures
c) Trees
19
Categories of Data Structures
d) Graph:
20
Categories of Data Structures
e) Queue:
A queue, also called FIFO system, is a linear list in which deletions can take
place only at one end of the list, “the Front” of the list and insertion can take place
only at the other end “Rear”.
This structure operates in much similar way as a line of people waiting at a bus stop
as shown in the following figure. The first person in the line is the first person to
board the bus.
21
Categories of Data Structures
f) Stack
It is an ordered group of homogeneous items of elements. Elements are added to
and removed from the top of the stack (the most recently added items are at the
top of the stack). The last element to be added is the first to be removed (LIFO:
Last In, First Out). (OR)
Stack also known as last-in-first-out (LIFO) system, is a linear list in which insertion and
deletions can take place only at one end called top . This structure is similar in its
operation to a stack of dishes on the spring system as shown in the following figure.
Note that dishes are inserted only at the top of the stack and dishes can be deleted
only from the top of the stack
22
Data Structure operations
The data appearing in our data structures are processed by means of certain operations.
In fact, the particular data structure that one chooses for a given situation
depends largely in the frequency with which specific operations are performed.
23
Algorithms: Complexity, Time-Space Tradeoff
24
General working of an Algorithm
Algorithm
Example: sorting
input: A sequence of numbers.
output: An ordered permutation of the input.
issues: correctness, efficiency, storage, etc.
25
Algorithms: Complexity, Time-Space Tradeoff
For every algorithm its efficiency/complexity is measured in term of its execution time
and
the amount of space it consume in computer memory.
Although a data structure depends on many factors/things including the type of data and
the frequency with which various data operation are applied however; there also involve
time-space tradeoff which make selection of the most efficient algorithm difficult.
time-space tradeoff: by increasing the amount of space for storing the data, one may
be able to reduce the time needed for processing the data or vice versa
26
Applications
Multimedia
CD player, DVD, MP3, JPG, DivX, HDTV
Internet
Packet routing, data retrieval (Google)
Communication
Cell-phones, e-commerce
Computers
Circuit layout, file systems
Science
Human genome
Transportation
Airline crew scheduling, UPS deliveries
27