SlideShare a Scribd company logo
1 of 27
Chapter One
Introduction to Data Structure
and Algorithm
1
Outline
 Data Structures
 Abstract Data Types
 Abstraction
 Algorithms
 Properties of an algorithm
2
Introduction to Data Structures and Algorithms Analysis
A program
 A set of instruction which is written in order
to solve a problem.
 A solution to a problem actually consists of
two things:
 A way to organize the data
 Sequence of steps to solve the problem
3
4
 The way data are organized in a computers
memory is said to be Data Structure.
 The sequence of computational steps to solve a
problem is said to be an Algorithm.
 Therefore, a program is Data structures plus
Algorithm.
Introduction....(continued)
Introduction to Data Structures
 Data structures are used to model the world or part of
the world. How?
1. The value held by a data structure represents some specific
characteristic of the world.
2. The characteristic being modeled restricts the possible values
held by a data structure and the operations to be performed
on the data structure
 The first step to solve the problem is obtaining
ones own abstract view, or model, of the
problem.
 This process of modeling is called abstraction.
5
6
Introduction....(continued)
 The model defines an abstract view to the
problem.
 The model should only focus on problem
related stuff
Abstraction
Abstraction
 Abstraction is a process of classifying characteristics as
relevant and irrelevant for the particular purpose at hand
and ignoring the irrelevant ones.
 Example: model students of DDU.
 Relevant:
Char Name[15];
Char ID[11];
Char Dept[20];
int Age, year;
 Non relevant
float hight, weight;
7
8
 Using the model, a programmer tries to
define the properties of the problem.
 These properties include
 The data which are affected and
 The operations that are involved in the problem
 An entity with the properties just described
is called an abstract data type (ADT).
Abstraction....(continued)
9
Abstract Data Types
 Consists of data to be stored and operations supported on
them.
 Is a specification that describes a data set and the
operation on that data.
 The ADT specifies:
 What data is stored.
 What operations can be done on the data.
 Does not specify how to store or how to implement the
operation.
 Is independent of any programming language
10
Example: ADT employees of an organization:
 This ADT stores employees with their relevant attributes
and discarding irrelevant attributes.
Relevant:- Name, ID, Sex, Age, Salary, Dept, Address
Non Relevant :- weight, color, height
 This ADT supports hiring, firing, retiring, …
operations.
ADT....(continued)
11
Data Structure
 In Contrast a data structure is a language
construct that the programmer has defined in
order to implement an abstract data type.
 What is the purpose of data structures in programs?
 Data structures are used to model a problem.
12
Data Structure
 Example:
struct Student_Record
{
char name[20];
char ID_NO[10];
char Department[10];
int age;
};
 Attributes of each variable:
 Name: Textual label.
 Address: Location in memory.
 Scope: Visibility in statements of a program.
 Type: Set of values that can be stored + set of operations that can be performed.
 Size: The amount of storage required to represent the variable.
 Life time: The time interval during execution of a program while the variable exists.
13
Algorithm
 Is a brief specification of an operation for solving a
problem.
 is a well-defined computational procedure that takes
some value or a set of values as input and produces
some value or a set of values as output.
Inputs Algorithm Outputs
 An algorithm is a specification of a behavioral
process. It consists of a finite set of instructions that
govern behavior step-by-step.
 Is part of what constitutes a data structure
14
 Data structures model the static part of the world.
They are unchanging while the world is changing.
 In order to model the dynamic part of the world
we need to work with algorithms.
 Algorithms are the dynamic part of a program’s
world model.
Algorithm
15
 An algorithm transforms data structures from one
state to another state.
 What is the purpose of algorithms in programs?
 Take values as input. Example: cin>>age;
 Change the values held by data structures. Example: age=age+1;
 Change the organization of the data structure:
Example:
Sort students by name
 Produce outputs:
Example: Display student’s information
Algorithm
16
 The quality of a data structure is related to its
ability to successfully model the characteristics
of the world (problem).
 Similarly, the quality of an algorithm is related
to its ability to successfully simulate the
changes in the world.
Algorithm
17
 However, the quality of data structure and algorithms
is determined by their ability to work together well.
 Generally speaking, correct data structures lead to
simple and efficient algorithms.
 And correct algorithms lead to accurate and efficient
data structures.
Algorithm
18
Properties of Algorithms
Algorithm must complete after a finite number of
steps.
 Algorithm should have a finite number of
steps.
Finite  int i=0; Infinite while(true){
while(i>10){ cout<<“Hello”;
cout<< i; }
i++;
}
Finiteness:
19
Definiteness (Absence of ambiguity):
 Each step must be clearly defined, having
one and only one interpretation.
 At each point in computation, one should be
able to tell exactly what happens next.
20
Sequential:
 Each step must have a uniquely defined
preceding and succeeding step.
 The first step (start step) and last step (halt
step) must be clearly noted.
21
Feasibility:
It must be possible to perform each
instruction.
 Each instruction should have possibility to
be executed.
1) for(int i=0; i<0; i++){
cout<< i; // there is no possibility
} that this statement to
be executed.
2) if(5>7) {
cout<<“hello”; // not executed.
}
22
Correctness
 It must compute correct answer for all
possible legal inputs.
 The output should be as expected and required and
correct.
 It must not depend on any one programming
language.
 It must solve the problem completely.
Language Independence:
Completeness:
23
Effectiveness:
 Doing the right thing. It should yield the correct
result all the time for all of the possible cases.
 It must solve with the least amount of
computational resources such as time and
space.
 Producing an output as per the requirement
within the given resources (constraints).
Efficiency:
24
Example:
Write a program that takes a number and displays
the square of the number.
1) int x;
cin>>x;
cout<<x*x;
2) int x,y;
cin>>x;
y=x*x;
cout<<y;
25
Example:
Write a program that takes two numbers and
displays the sum of the two.
Program a Program b Program c
cin>>a; cin>>a; cin>>a;
cin>>b; cin>>b; cin>>b;
sum = a+b; a = a+b; cout<<a+b;
cout<<sum; cout<<a;
Which one is most efficient and which are effective?
Program c the most efficient
All are effective but with different efficiencies.
26
Input/output:
There must be a specified number of input
values, and one or more result values.
 Zero or more inputs and one or more outputs.
 A good general rule is that each step should carry out one
logical step.
 What is simple to one processor may not be simple to another.
Simplicity:
Next Class
Complexity Analysis
Formal Approach to Analysis
Asymptotic Analysis
The Big-Oh Notation
Big-Omega Notation
Theta Notation
Algorithm Analysis Concepts
27

More Related Content

Similar to Lecture 1.pptx

Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Prashanth Shivakumar
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptxwondmhunegn
 
Data structures using C
Data structures using CData structures using C
Data structures using CPdr Patnaik
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Salman Qamar
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure Prof Ansari
 
Data Structure Notes unit 1.docx
Data Structure Notes unit 1.docxData Structure Notes unit 1.docx
Data Structure Notes unit 1.docxkp370932
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]Rome468
 
Introduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxIntroduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxMMCOE, Karvenagar, Pune
 
Analysis modeling in software engineering
Analysis modeling in software engineeringAnalysis modeling in software engineering
Analysis modeling in software engineeringMuhammadTalha436
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 DsQundeel
 
Data Structure
Data StructureData Structure
Data Structuresheraz1
 

Similar to Lecture 1.pptx (20)

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
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptx
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Unit 1 dsa
Unit 1 dsaUnit 1 dsa
Unit 1 dsa
 
Data Structure Notes unit 1.docx
Data Structure Notes unit 1.docxData Structure Notes unit 1.docx
Data Structure Notes unit 1.docx
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
C++
C++C++
C++
 
Book management system
Book management systemBook management system
Book management system
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
Analysis modeling
Analysis modelingAnalysis modeling
Analysis modeling
 
Introduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxIntroduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptx
 
Analysis modeling in software engineering
Analysis modeling in software engineeringAnalysis modeling in software engineering
Analysis modeling in software engineering
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Data Structure
Data StructureData Structure
Data Structure
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

Lecture 1.pptx

  • 1. Chapter One Introduction to Data Structure and Algorithm 1
  • 2. Outline  Data Structures  Abstract Data Types  Abstraction  Algorithms  Properties of an algorithm 2
  • 3. Introduction to Data Structures and Algorithms Analysis A program  A set of instruction which is written in order to solve a problem.  A solution to a problem actually consists of two things:  A way to organize the data  Sequence of steps to solve the problem 3
  • 4. 4  The way data are organized in a computers memory is said to be Data Structure.  The sequence of computational steps to solve a problem is said to be an Algorithm.  Therefore, a program is Data structures plus Algorithm. Introduction....(continued)
  • 5. Introduction to Data Structures  Data structures are used to model the world or part of the world. How? 1. The value held by a data structure represents some specific characteristic of the world. 2. The characteristic being modeled restricts the possible values held by a data structure and the operations to be performed on the data structure  The first step to solve the problem is obtaining ones own abstract view, or model, of the problem.  This process of modeling is called abstraction. 5
  • 6. 6 Introduction....(continued)  The model defines an abstract view to the problem.  The model should only focus on problem related stuff Abstraction
  • 7. Abstraction  Abstraction is a process of classifying characteristics as relevant and irrelevant for the particular purpose at hand and ignoring the irrelevant ones.  Example: model students of DDU.  Relevant: Char Name[15]; Char ID[11]; Char Dept[20]; int Age, year;  Non relevant float hight, weight; 7
  • 8. 8  Using the model, a programmer tries to define the properties of the problem.  These properties include  The data which are affected and  The operations that are involved in the problem  An entity with the properties just described is called an abstract data type (ADT). Abstraction....(continued)
  • 9. 9 Abstract Data Types  Consists of data to be stored and operations supported on them.  Is a specification that describes a data set and the operation on that data.  The ADT specifies:  What data is stored.  What operations can be done on the data.  Does not specify how to store or how to implement the operation.  Is independent of any programming language
  • 10. 10 Example: ADT employees of an organization:  This ADT stores employees with their relevant attributes and discarding irrelevant attributes. Relevant:- Name, ID, Sex, Age, Salary, Dept, Address Non Relevant :- weight, color, height  This ADT supports hiring, firing, retiring, … operations. ADT....(continued)
  • 11. 11 Data Structure  In Contrast a data structure is a language construct that the programmer has defined in order to implement an abstract data type.  What is the purpose of data structures in programs?  Data structures are used to model a problem.
  • 12. 12 Data Structure  Example: struct Student_Record { char name[20]; char ID_NO[10]; char Department[10]; int age; };  Attributes of each variable:  Name: Textual label.  Address: Location in memory.  Scope: Visibility in statements of a program.  Type: Set of values that can be stored + set of operations that can be performed.  Size: The amount of storage required to represent the variable.  Life time: The time interval during execution of a program while the variable exists.
  • 13. 13 Algorithm  Is a brief specification of an operation for solving a problem.  is a well-defined computational procedure that takes some value or a set of values as input and produces some value or a set of values as output. Inputs Algorithm Outputs  An algorithm is a specification of a behavioral process. It consists of a finite set of instructions that govern behavior step-by-step.  Is part of what constitutes a data structure
  • 14. 14  Data structures model the static part of the world. They are unchanging while the world is changing.  In order to model the dynamic part of the world we need to work with algorithms.  Algorithms are the dynamic part of a program’s world model. Algorithm
  • 15. 15  An algorithm transforms data structures from one state to another state.  What is the purpose of algorithms in programs?  Take values as input. Example: cin>>age;  Change the values held by data structures. Example: age=age+1;  Change the organization of the data structure: Example: Sort students by name  Produce outputs: Example: Display student’s information Algorithm
  • 16. 16  The quality of a data structure is related to its ability to successfully model the characteristics of the world (problem).  Similarly, the quality of an algorithm is related to its ability to successfully simulate the changes in the world. Algorithm
  • 17. 17  However, the quality of data structure and algorithms is determined by their ability to work together well.  Generally speaking, correct data structures lead to simple and efficient algorithms.  And correct algorithms lead to accurate and efficient data structures. Algorithm
  • 18. 18 Properties of Algorithms Algorithm must complete after a finite number of steps.  Algorithm should have a finite number of steps. Finite  int i=0; Infinite while(true){ while(i>10){ cout<<“Hello”; cout<< i; } i++; } Finiteness:
  • 19. 19 Definiteness (Absence of ambiguity):  Each step must be clearly defined, having one and only one interpretation.  At each point in computation, one should be able to tell exactly what happens next.
  • 20. 20 Sequential:  Each step must have a uniquely defined preceding and succeeding step.  The first step (start step) and last step (halt step) must be clearly noted.
  • 21. 21 Feasibility: It must be possible to perform each instruction.  Each instruction should have possibility to be executed. 1) for(int i=0; i<0; i++){ cout<< i; // there is no possibility } that this statement to be executed. 2) if(5>7) { cout<<“hello”; // not executed. }
  • 22. 22 Correctness  It must compute correct answer for all possible legal inputs.  The output should be as expected and required and correct.  It must not depend on any one programming language.  It must solve the problem completely. Language Independence: Completeness:
  • 23. 23 Effectiveness:  Doing the right thing. It should yield the correct result all the time for all of the possible cases.  It must solve with the least amount of computational resources such as time and space.  Producing an output as per the requirement within the given resources (constraints). Efficiency:
  • 24. 24 Example: Write a program that takes a number and displays the square of the number. 1) int x; cin>>x; cout<<x*x; 2) int x,y; cin>>x; y=x*x; cout<<y;
  • 25. 25 Example: Write a program that takes two numbers and displays the sum of the two. Program a Program b Program c cin>>a; cin>>a; cin>>a; cin>>b; cin>>b; cin>>b; sum = a+b; a = a+b; cout<<a+b; cout<<sum; cout<<a; Which one is most efficient and which are effective? Program c the most efficient All are effective but with different efficiencies.
  • 26. 26 Input/output: There must be a specified number of input values, and one or more result values.  Zero or more inputs and one or more outputs.  A good general rule is that each step should carry out one logical step.  What is simple to one processor may not be simple to another. Simplicity:
  • 27. Next Class Complexity Analysis Formal Approach to Analysis Asymptotic Analysis The Big-Oh Notation Big-Omega Notation Theta Notation Algorithm Analysis Concepts 27