SlideShare a Scribd company logo
Algorithm Specification and Data Abstraction
Dr. Ashutosh Satapathy
Assistant Professor, Department of CSE
VR Siddhartha Engineering College
Kanuru, Vijayawada
September 22, 2022
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 1 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 2 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 3 / 40
Introduction to Algorithm
An algorithm is a well defined computational procedure that takes
some value, or set of values, as input and produces some value, or set
of values as output.
It is thus a sequence of computational steps that transform the input
into the output.
The algorithm describes a computational procedure for achieving that
input/output relationship.
An algorithm is a finite set of instructions which accomplish a
particular task.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 4 / 40
Introduction to Algorithm
Every algorithm must satisfy the following criteria.
1 Input: There are some (possibly empty) input data which are
externally supplied to the algorithm.
2 Output: There will be at least one output.
3 Definiteness: Each instruction/step of the algorithm must be clear
and unambiguous.
4 Finiteness: If we trace out the instruction/step of an algorithm, then
for all cases, the algorithm will terminate after a finite number of
steps.
5 Effectiveness: The steps of an algorithm must be sufficiently basic
that it can be carried out by a person mechanically using pen and
paper.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 5 / 40
Introduction to Algorithm
Algorithm 1 Swap two numbers using third variable
1: start
2: read two values into two variables a, b
3: declare third variable, temp
4: temp = a
5: a = b
6: b = temp
7: write a, b ▷ Display a and b values
8: stop
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 6 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 7 / 40
Algorithm Design and Data Structure
To write a computer program for solving a problem we must start with the
following four tasks:
Identify the data items and their relationship.
Find the operations that must be performed on these data items.
Determine the best method to represent these data items in
computer’s memory.
Select a suitable programming language which can efficiently code the
identified data representation.
Note
These data items can be arranged in different ways depending on the
logical relationship between them. Arrangement of these data items is
called data structures. E.g., arrays, records, lists, and files
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 8 / 40
Algorithm Design and Data Structure
Important
The storage of data in primary memory is called as data structure
where as the storage of data in secondary memory is called file
structure.
The representation or the data structure in computer’s memory which
is known as storage structure.
Selection of a programming language best suited to represent the
data structure.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 9 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 10 / 40
Analyzing an Algorithm
Algorithms are designed using basic program constructs like sequence,
selection or branching, repetition, etc.
We need methods to separate bad algorithm from good ones and to
choose the most effective approach for our problem.
In analyzing an algorithm, the first approach is to check the
correctness of the algorithm.
Tracing the algorithm.
Checking the algorithm for logical correctness.
Implementing the algorithm.
Testing the algorithm, which can yield correct output for all possible
combinations of input values. This is called program proving or
program verification.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 11 / 40
Analyzing an Algorithm
Another approach of analysis is to check the simplicity of the
algorithm.
The simplest way of solving the problem is not always the best one.
It is necessary to evaluate the complexity of the algorithm.
The complexity of the algorithm is determined in terms of time and
space.
These determine the amount of time and storage an algorithm may
require for execution.
Finally, predict the performance of the algorithm in the best, worst,
and average cases.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 12 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 13 / 40
Algorithm Design Approaches
Figure 1.1: Top-down and bottom-up design approaches
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 14 / 40
Algorithm Design Approaches
A complicated algorithm is split into small parts called modules, and
the process of splitting is known as modularization.
Modularization significantly reduces the complications of designing an
algorithm and make its process more easier to design and implement.
It is necessary to evaluate the complexity of the algorithm.
In the top-down approach, the complex module is divided into
submodules.
In bottom-up approach begins with elementary modules and then
combine them further.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 15 / 40
Algorithm Design Approaches
Basis for
Comparison
Top-down
Approach
Bottom-up
Approach
Basic
- Break the massive
problem into multiple
subproblems.
- Solves the low-level
problems and integrate
them into a larger one.
Process
- Submodules are
solitarily analyzed.
- Examine what data is
to be encapsulated, and
implies the concept of
information hiding.
Communication
- The communications
is less among modules.
- In this, modules must
have communication.
Redundancy
- Contain redundant
information.
- Redundancy can be
eliminated.
Table 1.1: Comparison between top-down and bottom-up design approaches.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 16 / 40
Algorithm Design Approaches
Algorithm 2 Top-down approach: nth number in the Fibonacci sequence
Require: non-negative integer n
Ensure: F(n); nth number in the Fibonacci sequence.
1: function F(n)
2: if n ≤ 1 then
3: return n
4: else
5: return F(n − 1) + F(n − 2)
6: end if
7: end function
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 17 / 40
Algorithm Design Approaches
Algorithm 3 Bottom-up approach: nth number in the Fibonacci sequence
Require: non-negative integer n
Ensure: nth number in the Fibonacci sequence.
1: if n = 0 or n = 1 then
2: print n
3: else
4: A ← 0
5: B ← 1
6: for I ← 2 to n do
7: Temp ← A + B
8: A ← B
9: B ← Temp
10: end for
11: write B
12: end if
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 18 / 40
Algorithm Design Approaches
Algorithm 4 Top-down approach: Multiplication of 1 to n numbers
Require: non-negative integer n
Ensure: PRODUCT(n); Multiplication of 1 to n numbers.
1: function PRODUCT(n)
2: if n = 1 then
3: return 1
4: else
5: return n ∗ PRODUCT(n − 1)
6: end if
7: end function
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 19 / 40
Algorithm Design Approaches
Algorithm 5 Bottom-up approach: Multiplication of 1 to n numbers
Require: non-negative integer n
Ensure: Multiplication of 1 to n numbers.
1: Result ← 1
2: for I ← 1 to n do
3: Result ← Result ∗ I
4: end for
5: write Result
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 20 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 21 / 40
Pseudocode Conventions
Till now, we have described each step of an algorithm using natural
language like English. Here, we present most of our algorithms using
pseudocodes that resemble C and Pascal.
1 Comments begin with // and continue until the end of line.
2 Blocks are indicated with matching braces: { and }. The body of a
procedure also forms a block. Statements are delimited by ;
3 An identifier begins with a letter. The data types of variables are not
explicitly declared. The types will be clear from the context. Whether
it is global or local to a procedure will also be evident from context.
4 Compound data types can be formed with records.
node = record
{ datatype 1 data 1;
datatype 2 data 2;
node ∗ link; }
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 22 / 40
Pseudocode Conventions
5 link is a pointer to the record type node. For example, if p points to
a record of type node, p←data 1 stands for the value of the first
field. If q is a record of type node, q.data 1 denotes its first field.
6 Assignment of values to variables is done using the assignment
operator or leftwards arrow symbol.
variable := expression; or variable ← expression;
7 There are two boolean values true and false. In order to produce
these values, the logical operators and, or and not and the relational
operators <, ≤, =, ̸=, ≥ and > are provided.
8 Elements of multidimensional arrays are accessed using [ and ]. E.g.,
if A is a two dimensional array, the (i, j)th element of the array is
denoted as A[i, j]. Array indices start at zero.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 23 / 40
Pseudocode Conventions
9 The following statements are employed for while, for and do...while.
while < condition > do
Statement 1
Statement 2
Statement n
end while
while < condition > do {
Statement 1;
Statement 2;
Statement n; }
10 The general form of a for loop is
for I ← l to m step s do
Statement 1
Statement 2
Statement n
end for
for I := l to m step s do {
Statement 1;
Statement 2;
Statement n; }
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 24 / 40
Pseudocode Conventions
11 The general form of a do...while loop is
do
Statement 1
Statement 2
Statement n
while< condition >
do{
Statement 1;
Statement 2;
Statement n; }
while< condition >
12 A conditional statement has the following forms.
if < condition > then < statement >
if < condition > then < statement1 > else < statement2 > =0
13 We also employ the following case statement.
case {
:< condition1 >: < statement 1 >
:< condition2 >: < statement 2 >
: else : < statement n > }
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 25 / 40
Pseudocode Conventions
14 Input and output are done using the instructions read and write.
15 There is only one type of procedure: Algorithm or Procedure. An
algorithm consists of a heading and a body. The heading takes the
form.
Algorithm Name (< P1, P2, ..., P3 >)
Algorithm 6 Maximum of n given numbers
1: procedure MAX(A, n)
2: Result ← A[1]
3: for i ← 2 to n do
4: if A[i] > Result then Result ← A[i]
5: end if
6: end for
7: return Result
8: end procedure
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 26 / 40
Pseudocode Conventions
Algorithm 7 Selection Sort
1: procedure SelectionSort(a, n)
2: //Sort the array a[1 : n] into ascending order.
3: for i ← 1 to n do
4: j ← i
5: for k ← i + 1 to n do
6: if a[k] < a[j] then j ← k
7: end if
8: end for
9: t ← a[i]
10: a[i] ← a[j]
11: a[j] ← t
12: end for
13: end procedure
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 27 / 40
Pseudocode Conventions
Algorithm 8 Towers of Hanoi
1: procedure TowerOfHanoi(n, x, y, z)
2: {
3: //Move the top n disks from tower x to tower y.
4: if n ≥ 1 then {
5: TOWEROFHANOI(n − 1, x, y, z);
6: write (”move top disk from tower”, x, ”to top of tower”, y);
7: TOWEROFHANOI(n − 1, z, y, x);
8: }
9: }
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 28 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 29 / 40
Data Types
We are familiar with the basic data types of C. These include char,
int, float, and double. Some of these data types may be modified by
the keywords short, long, and unsigned.
In addition to these basic types, C helps us by providing two
mechanisms for grouping data together. These are the array and the
structure.
For example, An array is a collection of elements of the same basic
data type.
They are declared implicitly, for example, int list[5] defines a
five-element array of integers whose legitimate subscripts are in the
range 0 ... 4.
Structures are collections of elements whose data types need not be
the same.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 30 / 40
Data Types
Data types are declarations for variables. This determines the type
and size of data associated with variables, and a set of operations
that act on those objects.
Whether your program is dealing with predefined data types or
user-defined data types, these two aspects must be considered:
objects and operations.
For example, the data type int consists of the objects {0, +1, -1,
+2, -2, ..., INT MAX, INT MIN}, where INT MAX and
INT MIN are the largest and smallest integers that can be
represented on your machine.
The operations on integers are many, and would certainly include the
arithmetic operators +, -, *, /, and %.
There is also testing for equality/inequality and the operation that
assigns an integer to a variable.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 31 / 40
Data Types
Knowing all of the facts about the operations on a data type, we
might also want to know about how the objects of the data type are
represented.
E.g., a char is represented as a bit string occupying 1 byte of
memory on most computers, where as an int might occupy 2 or
possibly 4 bytes of memory. If 2 eight-bit bytes are used, then
INT MAX is 215 -1 = 32,767.
Knowing the representation of the objects of a data type can be
useful and dangerous.
It has been observed by many software designers that hiding the
representation of objects of a data type from its users is a good
design strategy.
In that case, the user is constrained to manipulate the objects solely
through the functions that are provided.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 32 / 40
Outline
1 Algorithm Specification
Introduction to Algorithm
Algorithm Design and Data Structure
Analyzing an Algorithm
Algorithm Design Approaches
Pseudocode Conventions
2 Data Abstraction
Data Types
Abstract Data Types
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 33 / 40
Abstract Data Types
An Abstract Data Type (ADT) is a data type that is organized in
such a way that the specification of the objects and the operations
on the objects is separated from the representation of the objects
and the implementation of the operations.
The specification consists of the names of every function, the type
of its arguments and result.
There should also be a description of what the function does, but
without appealing to internal representation or implementation
details.
This requirement is quite important, and it implies that an abstract
data type is implementation-independent.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 34 / 40
Abstract Data Types
ADT NaturalNumber is
Objects: An ordered sub-range of the integers starting at zero and ending
at the maximum integer (INT-MAX) on the computer.
Functions: for all x, y ∈ NaturalNumber; TRUE, FALSE ∈ Boolean,
where +, -, <, and == are the usual integer operations.
Functions Operations
NaturalNumber Zero() 0
Boolean IsZero(x)
if (x) return FALSE
else return TRUE
Boolean Equal(x, y)
if (x == y) return TRUE
else return FALSE
NaturalNumber Successor(x)
if (x == INT MAX) return x
else return x+1
Table 2.1: Abstract data type NautralNumber
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 35 / 40
Abstract Data Types
Functions Operations
NaturalNumber Add(x, y)
if (x+y <= INT MAX) return x+y
else return INT MAX
NaturalNumber Subtract(x, y)
if(x<y) return 0
else return x-y
Table 2.2: Abstract data type NautralNumber
The ADT definition begins with the name of the ADT. There are two
main sections in the definition: the objects and the functions.
The objects are defined in terms of the integers, but we make no
explicit reference to their representation.
For each function, we place the result type to the left of the function
name and a definition of the function to the right.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 36 / 40
Abstract Data Types
ADT is a type (or class) for objects whose behavior is defined by a
set of value and a set of operations.
The definition of ADT only mentions what operations are to be
performed but not how these operations will be implemented.
It does not specify how data will be organized in memory and what
algorithms will be used for implementing the operations.
It is called abstract because it gives an implementation-independent
view. The process of providing only the essentials and hiding the
details is known as abstraction.
A user only needs to know what a data type can do, but not how it
will be implemented. Think of ADT as a black box which hides the
inner structure and design of the data type.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 37 / 40
Abstract Data Types
Figure 2.1: Abstract data types in data structures
If Stack, Queue and Linked List are the ADTs, then {push(),
pop(), peep()}, {enque(), dequeqe()}, {insert(), delete()} are
the few operations performed on these data structures.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 38 / 40
Summary
Here, we have discussed
Algorithm and characteristics of an algorithm.
Rules to be followed for design and analysis of an algorithm.
The differentiation of data structures, file structures, and storage
structures.
Top-down and bottom-up design approaches through examples.
Rules to be followed while writing the pseudo code of an algorithm.
Abstract data type and its necessity in a program.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 39 / 40
For Further Reading I
H. Sahni and A. Freed.
Fundamentals of Data Structures in C (2nd edition).
Universities Press, 2008.
A. K. Rath and A. K. Jagadev.
Data Structures Using C (2nd edition).
Scitech Publications, 2011.
Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 40 / 40

More Related Content

What's hot

Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
introduction to database
 introduction to database introduction to database
introduction to database
Akif shexi
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Rabin BK
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalizationdaxesh chauhan
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Abhishek L.R
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
Rai University
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Hoang Nguyen
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting TechniquesRafay Farooq
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
FarihaHabib123
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
chauhankapil
 

What's hot (20)

Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
introduction to database
 introduction to database introduction to database
introduction to database
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 

Similar to Algorithm Specification and Data Abstraction

Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
Nisha Soms
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
Unit i
Unit iUnit i
Unit i
guna287176
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Ds new
Ds newDs new
Ds new
CS_GDRCST
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
RavishankarBhaganaga
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
MuhammadTalhaAwan1
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
Prof Ansari
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
subhashchandra197
 
Basic.ppt
Basic.pptBasic.ppt
Basic.ppt
VandanaBharti21
 
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTIONGRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
IJCSEA Journal
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
Prashanth Shivakumar
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
SamridhiGulati4
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
SisayNegash4
 
BATCH 1 FIRST REVIEW-1.pptx
BATCH 1 FIRST REVIEW-1.pptxBATCH 1 FIRST REVIEW-1.pptx
BATCH 1 FIRST REVIEW-1.pptx
SurajRavi16
 

Similar to Algorithm Specification and Data Abstraction (20)

Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Slide1
Slide1Slide1
Slide1
 
Lec1
Lec1Lec1
Lec1
 
Unit i
Unit iUnit i
Unit i
 
chapter 1
chapter 1chapter 1
chapter 1
 
Ds new
Ds newDs new
Ds new
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Unit i
Unit iUnit i
Unit i
 
Basic.ppt
Basic.pptBasic.ppt
Basic.ppt
 
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTIONGRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
GRID COMPUTING: STRATEGIC DECISION MAKING IN RESOURCE SELECTION
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
BATCH 1 FIRST REVIEW-1.pptx
BATCH 1 FIRST REVIEW-1.pptxBATCH 1 FIRST REVIEW-1.pptx
BATCH 1 FIRST REVIEW-1.pptx
 

More from Ashutosh Satapathy

Introduction to Data Structures .
Introduction to Data Structures        .Introduction to Data Structures        .
Introduction to Data Structures .
Ashutosh Satapathy
 
Searching and Sorting Algorithms
Searching and Sorting AlgorithmsSearching and Sorting Algorithms
Searching and Sorting Algorithms
Ashutosh Satapathy
 
Multidimensional Data
Multidimensional DataMultidimensional Data
Multidimensional Data
Ashutosh Satapathy
 
ORAM
ORAMORAM
ObliVM
ObliVMObliVM
Secure Multi-Party Computation
Secure Multi-Party ComputationSecure Multi-Party Computation
Secure Multi-Party Computation
Ashutosh Satapathy
 

More from Ashutosh Satapathy (6)

Introduction to Data Structures .
Introduction to Data Structures        .Introduction to Data Structures        .
Introduction to Data Structures .
 
Searching and Sorting Algorithms
Searching and Sorting AlgorithmsSearching and Sorting Algorithms
Searching and Sorting Algorithms
 
Multidimensional Data
Multidimensional DataMultidimensional Data
Multidimensional Data
 
ORAM
ORAMORAM
ORAM
 
ObliVM
ObliVMObliVM
ObliVM
 
Secure Multi-Party Computation
Secure Multi-Party ComputationSecure Multi-Party Computation
Secure Multi-Party Computation
 

Recently uploaded

DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 

Recently uploaded (20)

DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 

Algorithm Specification and Data Abstraction

  • 1. Algorithm Specification and Data Abstraction Dr. Ashutosh Satapathy Assistant Professor, Department of CSE VR Siddhartha Engineering College Kanuru, Vijayawada September 22, 2022 Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 1 / 40
  • 2. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 2 / 40
  • 3. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 3 / 40
  • 4. Introduction to Algorithm An algorithm is a well defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output. It is thus a sequence of computational steps that transform the input into the output. The algorithm describes a computational procedure for achieving that input/output relationship. An algorithm is a finite set of instructions which accomplish a particular task. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 4 / 40
  • 5. Introduction to Algorithm Every algorithm must satisfy the following criteria. 1 Input: There are some (possibly empty) input data which are externally supplied to the algorithm. 2 Output: There will be at least one output. 3 Definiteness: Each instruction/step of the algorithm must be clear and unambiguous. 4 Finiteness: If we trace out the instruction/step of an algorithm, then for all cases, the algorithm will terminate after a finite number of steps. 5 Effectiveness: The steps of an algorithm must be sufficiently basic that it can be carried out by a person mechanically using pen and paper. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 5 / 40
  • 6. Introduction to Algorithm Algorithm 1 Swap two numbers using third variable 1: start 2: read two values into two variables a, b 3: declare third variable, temp 4: temp = a 5: a = b 6: b = temp 7: write a, b ▷ Display a and b values 8: stop Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 6 / 40
  • 7. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 7 / 40
  • 8. Algorithm Design and Data Structure To write a computer program for solving a problem we must start with the following four tasks: Identify the data items and their relationship. Find the operations that must be performed on these data items. Determine the best method to represent these data items in computer’s memory. Select a suitable programming language which can efficiently code the identified data representation. Note These data items can be arranged in different ways depending on the logical relationship between them. Arrangement of these data items is called data structures. E.g., arrays, records, lists, and files Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 8 / 40
  • 9. Algorithm Design and Data Structure Important The storage of data in primary memory is called as data structure where as the storage of data in secondary memory is called file structure. The representation or the data structure in computer’s memory which is known as storage structure. Selection of a programming language best suited to represent the data structure. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 9 / 40
  • 10. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 10 / 40
  • 11. Analyzing an Algorithm Algorithms are designed using basic program constructs like sequence, selection or branching, repetition, etc. We need methods to separate bad algorithm from good ones and to choose the most effective approach for our problem. In analyzing an algorithm, the first approach is to check the correctness of the algorithm. Tracing the algorithm. Checking the algorithm for logical correctness. Implementing the algorithm. Testing the algorithm, which can yield correct output for all possible combinations of input values. This is called program proving or program verification. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 11 / 40
  • 12. Analyzing an Algorithm Another approach of analysis is to check the simplicity of the algorithm. The simplest way of solving the problem is not always the best one. It is necessary to evaluate the complexity of the algorithm. The complexity of the algorithm is determined in terms of time and space. These determine the amount of time and storage an algorithm may require for execution. Finally, predict the performance of the algorithm in the best, worst, and average cases. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 12 / 40
  • 13. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 13 / 40
  • 14. Algorithm Design Approaches Figure 1.1: Top-down and bottom-up design approaches Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 14 / 40
  • 15. Algorithm Design Approaches A complicated algorithm is split into small parts called modules, and the process of splitting is known as modularization. Modularization significantly reduces the complications of designing an algorithm and make its process more easier to design and implement. It is necessary to evaluate the complexity of the algorithm. In the top-down approach, the complex module is divided into submodules. In bottom-up approach begins with elementary modules and then combine them further. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 15 / 40
  • 16. Algorithm Design Approaches Basis for Comparison Top-down Approach Bottom-up Approach Basic - Break the massive problem into multiple subproblems. - Solves the low-level problems and integrate them into a larger one. Process - Submodules are solitarily analyzed. - Examine what data is to be encapsulated, and implies the concept of information hiding. Communication - The communications is less among modules. - In this, modules must have communication. Redundancy - Contain redundant information. - Redundancy can be eliminated. Table 1.1: Comparison between top-down and bottom-up design approaches. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 16 / 40
  • 17. Algorithm Design Approaches Algorithm 2 Top-down approach: nth number in the Fibonacci sequence Require: non-negative integer n Ensure: F(n); nth number in the Fibonacci sequence. 1: function F(n) 2: if n ≤ 1 then 3: return n 4: else 5: return F(n − 1) + F(n − 2) 6: end if 7: end function Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 17 / 40
  • 18. Algorithm Design Approaches Algorithm 3 Bottom-up approach: nth number in the Fibonacci sequence Require: non-negative integer n Ensure: nth number in the Fibonacci sequence. 1: if n = 0 or n = 1 then 2: print n 3: else 4: A ← 0 5: B ← 1 6: for I ← 2 to n do 7: Temp ← A + B 8: A ← B 9: B ← Temp 10: end for 11: write B 12: end if Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 18 / 40
  • 19. Algorithm Design Approaches Algorithm 4 Top-down approach: Multiplication of 1 to n numbers Require: non-negative integer n Ensure: PRODUCT(n); Multiplication of 1 to n numbers. 1: function PRODUCT(n) 2: if n = 1 then 3: return 1 4: else 5: return n ∗ PRODUCT(n − 1) 6: end if 7: end function Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 19 / 40
  • 20. Algorithm Design Approaches Algorithm 5 Bottom-up approach: Multiplication of 1 to n numbers Require: non-negative integer n Ensure: Multiplication of 1 to n numbers. 1: Result ← 1 2: for I ← 1 to n do 3: Result ← Result ∗ I 4: end for 5: write Result Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 20 / 40
  • 21. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 21 / 40
  • 22. Pseudocode Conventions Till now, we have described each step of an algorithm using natural language like English. Here, we present most of our algorithms using pseudocodes that resemble C and Pascal. 1 Comments begin with // and continue until the end of line. 2 Blocks are indicated with matching braces: { and }. The body of a procedure also forms a block. Statements are delimited by ; 3 An identifier begins with a letter. The data types of variables are not explicitly declared. The types will be clear from the context. Whether it is global or local to a procedure will also be evident from context. 4 Compound data types can be formed with records. node = record { datatype 1 data 1; datatype 2 data 2; node ∗ link; } Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 22 / 40
  • 23. Pseudocode Conventions 5 link is a pointer to the record type node. For example, if p points to a record of type node, p←data 1 stands for the value of the first field. If q is a record of type node, q.data 1 denotes its first field. 6 Assignment of values to variables is done using the assignment operator or leftwards arrow symbol. variable := expression; or variable ← expression; 7 There are two boolean values true and false. In order to produce these values, the logical operators and, or and not and the relational operators <, ≤, =, ̸=, ≥ and > are provided. 8 Elements of multidimensional arrays are accessed using [ and ]. E.g., if A is a two dimensional array, the (i, j)th element of the array is denoted as A[i, j]. Array indices start at zero. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 23 / 40
  • 24. Pseudocode Conventions 9 The following statements are employed for while, for and do...while. while < condition > do Statement 1 Statement 2 Statement n end while while < condition > do { Statement 1; Statement 2; Statement n; } 10 The general form of a for loop is for I ← l to m step s do Statement 1 Statement 2 Statement n end for for I := l to m step s do { Statement 1; Statement 2; Statement n; } Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 24 / 40
  • 25. Pseudocode Conventions 11 The general form of a do...while loop is do Statement 1 Statement 2 Statement n while< condition > do{ Statement 1; Statement 2; Statement n; } while< condition > 12 A conditional statement has the following forms. if < condition > then < statement > if < condition > then < statement1 > else < statement2 > =0 13 We also employ the following case statement. case { :< condition1 >: < statement 1 > :< condition2 >: < statement 2 > : else : < statement n > } Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 25 / 40
  • 26. Pseudocode Conventions 14 Input and output are done using the instructions read and write. 15 There is only one type of procedure: Algorithm or Procedure. An algorithm consists of a heading and a body. The heading takes the form. Algorithm Name (< P1, P2, ..., P3 >) Algorithm 6 Maximum of n given numbers 1: procedure MAX(A, n) 2: Result ← A[1] 3: for i ← 2 to n do 4: if A[i] > Result then Result ← A[i] 5: end if 6: end for 7: return Result 8: end procedure Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 26 / 40
  • 27. Pseudocode Conventions Algorithm 7 Selection Sort 1: procedure SelectionSort(a, n) 2: //Sort the array a[1 : n] into ascending order. 3: for i ← 1 to n do 4: j ← i 5: for k ← i + 1 to n do 6: if a[k] < a[j] then j ← k 7: end if 8: end for 9: t ← a[i] 10: a[i] ← a[j] 11: a[j] ← t 12: end for 13: end procedure Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 27 / 40
  • 28. Pseudocode Conventions Algorithm 8 Towers of Hanoi 1: procedure TowerOfHanoi(n, x, y, z) 2: { 3: //Move the top n disks from tower x to tower y. 4: if n ≥ 1 then { 5: TOWEROFHANOI(n − 1, x, y, z); 6: write (”move top disk from tower”, x, ”to top of tower”, y); 7: TOWEROFHANOI(n − 1, z, y, x); 8: } 9: } Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 28 / 40
  • 29. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 29 / 40
  • 30. Data Types We are familiar with the basic data types of C. These include char, int, float, and double. Some of these data types may be modified by the keywords short, long, and unsigned. In addition to these basic types, C helps us by providing two mechanisms for grouping data together. These are the array and the structure. For example, An array is a collection of elements of the same basic data type. They are declared implicitly, for example, int list[5] defines a five-element array of integers whose legitimate subscripts are in the range 0 ... 4. Structures are collections of elements whose data types need not be the same. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 30 / 40
  • 31. Data Types Data types are declarations for variables. This determines the type and size of data associated with variables, and a set of operations that act on those objects. Whether your program is dealing with predefined data types or user-defined data types, these two aspects must be considered: objects and operations. For example, the data type int consists of the objects {0, +1, -1, +2, -2, ..., INT MAX, INT MIN}, where INT MAX and INT MIN are the largest and smallest integers that can be represented on your machine. The operations on integers are many, and would certainly include the arithmetic operators +, -, *, /, and %. There is also testing for equality/inequality and the operation that assigns an integer to a variable. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 31 / 40
  • 32. Data Types Knowing all of the facts about the operations on a data type, we might also want to know about how the objects of the data type are represented. E.g., a char is represented as a bit string occupying 1 byte of memory on most computers, where as an int might occupy 2 or possibly 4 bytes of memory. If 2 eight-bit bytes are used, then INT MAX is 215 -1 = 32,767. Knowing the representation of the objects of a data type can be useful and dangerous. It has been observed by many software designers that hiding the representation of objects of a data type from its users is a good design strategy. In that case, the user is constrained to manipulate the objects solely through the functions that are provided. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 32 / 40
  • 33. Outline 1 Algorithm Specification Introduction to Algorithm Algorithm Design and Data Structure Analyzing an Algorithm Algorithm Design Approaches Pseudocode Conventions 2 Data Abstraction Data Types Abstract Data Types Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 33 / 40
  • 34. Abstract Data Types An Abstract Data Type (ADT) is a data type that is organized in such a way that the specification of the objects and the operations on the objects is separated from the representation of the objects and the implementation of the operations. The specification consists of the names of every function, the type of its arguments and result. There should also be a description of what the function does, but without appealing to internal representation or implementation details. This requirement is quite important, and it implies that an abstract data type is implementation-independent. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 34 / 40
  • 35. Abstract Data Types ADT NaturalNumber is Objects: An ordered sub-range of the integers starting at zero and ending at the maximum integer (INT-MAX) on the computer. Functions: for all x, y ∈ NaturalNumber; TRUE, FALSE ∈ Boolean, where +, -, <, and == are the usual integer operations. Functions Operations NaturalNumber Zero() 0 Boolean IsZero(x) if (x) return FALSE else return TRUE Boolean Equal(x, y) if (x == y) return TRUE else return FALSE NaturalNumber Successor(x) if (x == INT MAX) return x else return x+1 Table 2.1: Abstract data type NautralNumber Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 35 / 40
  • 36. Abstract Data Types Functions Operations NaturalNumber Add(x, y) if (x+y <= INT MAX) return x+y else return INT MAX NaturalNumber Subtract(x, y) if(x<y) return 0 else return x-y Table 2.2: Abstract data type NautralNumber The ADT definition begins with the name of the ADT. There are two main sections in the definition: the objects and the functions. The objects are defined in terms of the integers, but we make no explicit reference to their representation. For each function, we place the result type to the left of the function name and a definition of the function to the right. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 36 / 40
  • 37. Abstract Data Types ADT is a type (or class) for objects whose behavior is defined by a set of value and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called abstract because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction. A user only needs to know what a data type can do, but not how it will be implemented. Think of ADT as a black box which hides the inner structure and design of the data type. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 37 / 40
  • 38. Abstract Data Types Figure 2.1: Abstract data types in data structures If Stack, Queue and Linked List are the ADTs, then {push(), pop(), peep()}, {enque(), dequeqe()}, {insert(), delete()} are the few operations performed on these data structures. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 38 / 40
  • 39. Summary Here, we have discussed Algorithm and characteristics of an algorithm. Rules to be followed for design and analysis of an algorithm. The differentiation of data structures, file structures, and storage structures. Top-down and bottom-up design approaches through examples. Rules to be followed while writing the pseudo code of an algorithm. Abstract data type and its necessity in a program. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 39 / 40
  • 40. For Further Reading I H. Sahni and A. Freed. Fundamentals of Data Structures in C (2nd edition). Universities Press, 2008. A. K. Rath and A. K. Jagadev. Data Structures Using C (2nd edition). Scitech Publications, 2011. Dr. Ashutosh Satapathy Algorithm Specification and Data Abstraction September 22, 2022 40 / 40