INTRODUCTION TO DATA
STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS
DATA STRUCTURE
Data Structure
specialized format to store and organize data in a
computer’s memory or disk
collection of variables, possibly of several
different data types connected in various ways
Types of Data Structures
Array
Linked list
Stacks
Trees
Hast tables
DATA STRUCTURE
Data Types
data that a variable can hold in a programming
language
all programming language has a set of built-in data
types
Examples:
char - data type representing character values
int - data type representing integer values
Abstract Data Types
specification of a set of data and set of operations
performed in a data
storage for data defined in terms of set of operations
to be performed on the data
ALGORITHMS
finite set of instructions that specify a sequence
of operations to be carried out
recipe for solving a problem
Example of simple algorithm
• Apply to wet hair
• Massage gently
• Leave on for a few moments
• Rinse Off
all the tasks that can be carried out by a
computer can be stated as algorithms
CRITERIA FOR ALGORITHM
Every algorithm must satisfy the following criteria:
Input - zero or more quantities are externally supplied
Output - at least one quantity is produced
Definiteness - each instruction must be clear and
unambiguous
Finiteness - all instructions of an algorithm will
terminate after a finite number of steps
Effectiveness - each operation must be definite, but
must also be feasible
CRITERIA FOR ALGORITHM
CRITERIA FOR ALGORITHM
Inputs are the data items presented to the
algorithm. An algorithm has either no input or a
predetermined number of them.
Output are the data items presented to the
outside world as the result of the execution of a
program based on the algorithm.
An algorithm ought to produce at least one
output.
REPRESENTING ALGORITHMS
Procedure
essential tool in programming that generalizes
the notion of an operator
Procedure can be used to encapsulate parts of an
algorithm by localizing in one section of a
program all the statements relevant to a certain
E h k
aspect of a program. 123 a
L
548
DATA STRUCTURES AND ALGORITHMS
Raw data is an input to a computer and an
algorithm is used to transform this into a refined
data
Computer Science also refers to the study of
data. It include:
Machines that holds data
Languages for describing data manipulation
Foundations which describe what kinds of
refined data can be produced from raw data
Structures for representing data
DATA STRUCTURES AND ALGORITHMS
PSEUDOCODE
textual presentation of a flowchart
close to a natural language
the control structures impose the logic
may become part of the program documentation
could be translated into a program
STEPWISE REFINEMENT
The process by which a programmer refines an
initial idea to a problem's solution into more
specific terms.
The last phase of refinement results in a program
ready to be coded for execution.
ANALYSIS OF ALGORITHMS
determining the amount of resources necessary
to execute it such as time and storage
usually in terms of CPU time and memory
requirements
Analysis of Algorithms
Best-case analysis
Worst-case analysis
Average-case analysis