Data Structure and Algorithms (CSC-216)

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Data Structure and

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.

Alfered V. Aho, John E. Hopcraft, Jeffray D. Ulman, Data Structures


and Algorithms.

Reference Books:
Seymour Lipschutz, Theory and Problems of Data structures, 2nd
Edition.

Authentic Web resources


Course Roadmap
 Intro to algorithm design ,Implementation and applications.
 Main Data Structures
Array
Stack
Queues
String
Recursion
 Searching & Hashing Techniques
Sequential search
Binary Search
 Sorting Techniques
Bubble sort
Selection sort
Heap sort
Quick Sort
 Linked lists
Single Linked List
Double linked List
 Tree
Insertion, Traversing , Deletion
 Graphs
 File Structures etc

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.

Group Items & Elementary Items


 Data items that are divided into sub items are group items; those that are not
are called elementary items.
 For example, a student’s name may be divided into three sub items – [first name, middle name and last
name] but the ID of a student would normally be treated as a single item.

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

 In computer science, a data structure is a particular way of storing and


organizing data in a computer’s memory so that it can be used efficiently.
 Data may be organized in many different ways; the logical or mathematical
model of a particular organization of data is called a data structure.
 The choice of a particular data model depends on different factors in which as
important one is:
 the structure should be simple enough that one can effectively process the data
whenever necessary.

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

1. 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

2. Non-linear Data Structure:

This structure is mainly used to represent data containing a hierarchical


relationship between elements. e.g. graphs, family trees and table of contents.

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

Data frequently contain a hierarchical relationship between various elements.


The data structure which reflects this relationship is called a rooted tree graph
or, simply, a tree.

19
Categories of Data Structures

d) Graph:

Data sometimes contains a relationship between pairs of elements which is


not necessarily hierarchical in nature, e.g. an airline flies only between two cities
connected by lines as shown in the following figure.
This data structure is called 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.

Another analogy is with the automobiles waiting to pass through an intersection-the


first car in the line is the first car through.

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.

FOUR main operations play a major role in this context

1. Traversing: Accessing each record


2. Searching: Finding the location of each value/record
3. Inserting: Adding a new record to the structure
4. Deleting: Removing a record from structure
However the following operations which are used in special situations may also be
considered.
a) Sorting
b) Merging
c) Copying and Concatenation

23
Algorithms: Complexity, Time-Space Tradeoff

An algorithm is a precise, step-by-step method of doing a task in a finite amount


of time.
OR
A tool for solving a well-specified computational problem

24
General working of an Algorithm

 Algorithm

Input Algorithm Output

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.

Each and every algorithm involve a particular data structure.

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

You might also like