SlideShare a Scribd company logo
2
Most read
How to Create Programs
For an improvement in creating programs, some discipline should be applied.  Creating a program can be processed better with the five phases stated below: Requirements:  Make sure you understand the information you are given (the input) and what results you are to produce (the output). Try to write down a rigorous description of the input and output which covers all cases.  Design :  You may have several data objects (such as a maze, a polynomial, or a list of names). For each object there will be some basic operations to perform on it (such as print the maze, add two polynomials, or find a name in the list.) Assume that these operations already exist in the form of procedures and write an algorithm which solves the problem according to the requirements. Use a notation which is natural to the way you wish to describe the order of processing.  Analysis:  If you can think of another algorithm, then write it down. Next try to compare the two algorithms you have in hand. It may already be possible to tell if one will be more desirable than the other. If you cannot distinguish between two, choose one to work on for now.  Refinement and coding:  You must now choose representations for your data objects (a maze as a two dimensional array of degree and coefficients, a list of names possibly as an array) and write algorithms for each of the operations on these objects.  Verification:  Verification consists of three distinct aspects: program proving, testing and debugging. Each of these is an art in itself. Before executing your program you should attempt tp prove it is correct. Testing is the art of creating sample data upon which to run your program. If the program fails to run correctly then debugging is needed to determine what went wrong and how to correct it.
Suppose we devise a program for sorting a set of n>=1 integers. One of the simplest solutions is given by the following:  &quot;from those integers which remain unsorted, find the smallest and place it next in the sorted list.&quot;   This statement is sufficient to construct a sorting program. However several issues are not fully specified such as where and how the integers are initially stored and where result is to be placed. One solution is to store the values in an array in such a way that the i-th integer is stored in the i-th array position,  a[i] 1<=i<=n . Below is a second refinement of the solution:  for  i :=1 to  n  do  begin   examine  a [i] to  a [n] and suppose the smallest integer is at  a [ j ];   interchange  a [ i ] and  a [ j ];  end;   There now remain two clearly defined subtasks: (i) to find the minimum integer and (ii) to interchange it with a[i]. This latter problem can be solved by the code  t:=a[i];    a[i]:=a[j];    a[j]:=t;   The first subtask can be solved by assuming the minimum is a[i], checking a[i] with a[i+1], a[i+2],...and whenever a smaller element is found, regarding it as the new minimum. Eventually a[n] is compared to the current minimum and we are done. Putting all these observations together we get the procedure sort.
Let us develop another program.  We assume that we have n>=1 distinct integers which are already sorted and stored in the array a[1..n].  Our task is to determine  if the integer x is present and if so to return j such that x=a[j];  otherwise return j=0.   By making use of the fact that the set is sorted we conceive of the following efficient method:  &quot;let a[mid] be the middle element. There are three possibilities.  Either x<a[mid] in which case x can only occur as a[1] to a[mid-1];  or x>a[mid] in which case x can only occur as a[mid+1] to a[n];  or x=a[mid] in which case set j to mid and return. Result in the next Slide
procedure   binsrch (a: elementlist; x: element;  var   n,j:  integer );  {search the sorted array a[1..n] for x}  initialize lower and upper  begin        while   there are more elements  do        begin           let a[mid] be the middle element;           case  compare (x, a[mid])  of                '>': set lower to mid + 1;               '<': set upper to mid - 1;               '=': found x;           end ;  {of  case  }       end ;  {of  while   }      not found;  end  ;{of binsrch}
How to Analyze Programs
There are many criteria upon which we can judge a program, for instance:   Does it do what we want it to do?  Does it work correctly according to the original specifications of the task?  Is there documentation which describes how to use it and how it works?  Are procedures created in such a way that they perform logical sub-functions?  Is the code readable?
These have to do with computing time and storage requirements of the algorithms.  Performance evaluation can be loosely divided into 2 major phases:  (a) a priori estimates and  (b) a postpriori testing. Both of these are equally important. Consider the examples below:  x:=x+1; We assume that the statement x:=x+1 is not contained within any loop either explicit or implicit. Then its frequency count is one.  for  i:=1  to  n  do     x:=x+1; Now, the same statement will be executed n times.  for  i:=1  to  n  do     for  i:=1  to  n  do    x:=x+1;  It will be executed (n*n) times now.  There are other criteria for judging programs which have a more direct relationship to performance.
To clarify some of the ideas stated in this section, take a look at a simple program for computing the  n-th  Fibonacci number.  The Fibonacci sequence starts as  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,....   Each new term is obtained by taking the sum of the two previous terms. If we call the first term of the sequence  F[0]  then  F[0]=0, F[1]=1  and in general  F[n] = F[n-1] + F [n-2], n>=2.

More Related Content

What's hot (20)

PDF
Php tutorial(w3schools)
Arjun Shanka
 
PPT
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
PPT
3 Tier Architecture
Webx
 
PPT
Javascript
Manav Prasad
 
PPTX
OOP Introduction with java programming language
Md.Al-imran Roton
 
PPT
Binary Search
kunj desai
 
PPTX
Intermediate code
Vishal Agarwal
 
PPT
Dbms relational model
Chirag vasava
 
PPTX
Java Server Pages
Kasun Madusanke
 
PPTX
Programming Fundamentals lecture 1
REHAN IJAZ
 
PPTX
Client server architecture
Bhargav Amin
 
PDF
Syntax analysis
Akshaya Arunan
 
PDF
Introduction to asp.net
SHADAB ALI
 
PDF
Complete dbms notes
Tanya Makkar
 
PPTX
Dbms architecture
Shubham Dwivedi
 
PPT
.Net Debugging Techniques
Bala Subra
 
PDF
Query trees
Shefa Idrees
 
PPT
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
PPT
Code Optimization
guest9f8315
 
Php tutorial(w3schools)
Arjun Shanka
 
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
3 Tier Architecture
Webx
 
Javascript
Manav Prasad
 
OOP Introduction with java programming language
Md.Al-imran Roton
 
Binary Search
kunj desai
 
Intermediate code
Vishal Agarwal
 
Dbms relational model
Chirag vasava
 
Java Server Pages
Kasun Madusanke
 
Programming Fundamentals lecture 1
REHAN IJAZ
 
Client server architecture
Bhargav Amin
 
Syntax analysis
Akshaya Arunan
 
Introduction to asp.net
SHADAB ALI
 
Complete dbms notes
Tanya Makkar
 
Dbms architecture
Shubham Dwivedi
 
.Net Debugging Techniques
Bala Subra
 
Query trees
Shefa Idrees
 
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
Code Optimization
guest9f8315
 

Viewers also liked (7)

PPTX
Modos de aprendizaje
jeronimo udea
 
PPS
Consejos Saludables
William Abanto Quintos
 
PPT
Address Labels & Envelope Seals
Faith Chandler
 
PPSX
Awesomepenny
Harlan Russo
 
PPT
Proclamatie juni 2011
Koninklijk Atheneum Ukkel
 
DOC
Prefeitura adia entrevistas do processo seletivo da saúde e assistência social
Lucas Vitorino
 
PPT
Ovarian
ELITE IMAGING
 
Modos de aprendizaje
jeronimo udea
 
Consejos Saludables
William Abanto Quintos
 
Address Labels & Envelope Seals
Faith Chandler
 
Awesomepenny
Harlan Russo
 
Proclamatie juni 2011
Koninklijk Atheneum Ukkel
 
Prefeitura adia entrevistas do processo seletivo da saúde e assistência social
Lucas Vitorino
 
Ovarian
ELITE IMAGING
 
Ad

Similar to Create and analyse programs (20)

DOCX
UNIT-1.docx Design and Analysis of Algorithm
swethajosephsastry
 
PPTX
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
PDF
Data Structures (BE)
PRABHAHARAN429
 
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
PPT
Introducción al Análisis y diseño de algoritmos
luzenith_g
 
PPT
Alg1
luzenith_g
 
PPT
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
PPT
l01-intro (3).ppt
ssuser15a62a
 
PPT
Data structure and algorithm first chapter
amiyapal2408
 
PDF
Ch01
gurusodhii
 
PPTX
DAA 1 ppt.pptx
RAJESH S
 
PPTX
DAA ppt.pptx
RAJESH S
 
PPTX
Daa unit 1
jinalgoti
 
PDF
Algorithm Design and Analysis
Sayed Chhattan Shah
 
RTF
Design and Analysis of algorithms
Dr. Rupa Ch
 
PDF
From programming to software engineering: ICSE keynote slides available
Celso Martins
 
PPTX
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
PDF
Introduction to analysis algorithm in computer Science
tissandavid
 
UNIT-1.docx Design and Analysis of Algorithm
swethajosephsastry
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
Data Structures (BE)
PRABHAHARAN429
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
Introducción al Análisis y diseño de algoritmos
luzenith_g
 
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
l01-intro (3).ppt
ssuser15a62a
 
Data structure and algorithm first chapter
amiyapal2408
 
DAA 1 ppt.pptx
RAJESH S
 
DAA ppt.pptx
RAJESH S
 
Daa unit 1
jinalgoti
 
Algorithm Design and Analysis
Sayed Chhattan Shah
 
Design and Analysis of algorithms
Dr. Rupa Ch
 
From programming to software engineering: ICSE keynote slides available
Celso Martins
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
Introduction to analysis algorithm in computer Science
tissandavid
 
Ad

More from Dr. C.V. Suresh Babu (20)

PPTX
Data analytics with R
Dr. C.V. Suresh Babu
 
PPTX
Association rules
Dr. C.V. Suresh Babu
 
PPTX
Clustering
Dr. C.V. Suresh Babu
 
PPTX
Classification
Dr. C.V. Suresh Babu
 
PPTX
Blue property assumptions.
Dr. C.V. Suresh Babu
 
PPTX
Introduction to regression
Dr. C.V. Suresh Babu
 
PPTX
Expert systems
Dr. C.V. Suresh Babu
 
PPTX
Dempster shafer theory
Dr. C.V. Suresh Babu
 
PPTX
Bayes network
Dr. C.V. Suresh Babu
 
PPTX
Bayes' theorem
Dr. C.V. Suresh Babu
 
PPTX
Knowledge based agents
Dr. C.V. Suresh Babu
 
PPTX
Rule based system
Dr. C.V. Suresh Babu
 
PPTX
Formal Logic in AI
Dr. C.V. Suresh Babu
 
PPTX
Production based system
Dr. C.V. Suresh Babu
 
PPTX
Game playing in AI
Dr. C.V. Suresh Babu
 
PPTX
Diagnosis test of diabetics and hypertension by AI
Dr. C.V. Suresh Babu
 
PPTX
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 
PDF
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 
Data analytics with R
Dr. C.V. Suresh Babu
 
Association rules
Dr. C.V. Suresh Babu
 
Classification
Dr. C.V. Suresh Babu
 
Blue property assumptions.
Dr. C.V. Suresh Babu
 
Introduction to regression
Dr. C.V. Suresh Babu
 
Expert systems
Dr. C.V. Suresh Babu
 
Dempster shafer theory
Dr. C.V. Suresh Babu
 
Bayes network
Dr. C.V. Suresh Babu
 
Bayes' theorem
Dr. C.V. Suresh Babu
 
Knowledge based agents
Dr. C.V. Suresh Babu
 
Rule based system
Dr. C.V. Suresh Babu
 
Formal Logic in AI
Dr. C.V. Suresh Babu
 
Production based system
Dr. C.V. Suresh Babu
 
Game playing in AI
Dr. C.V. Suresh Babu
 
Diagnosis test of diabetics and hypertension by AI
Dr. C.V. Suresh Babu
 
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 

Recently uploaded (20)

PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
community health nursing question paper 2.pdf
Prince kumar
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 

Create and analyse programs

  • 1. How to Create Programs
  • 2. For an improvement in creating programs, some discipline should be applied. Creating a program can be processed better with the five phases stated below: Requirements: Make sure you understand the information you are given (the input) and what results you are to produce (the output). Try to write down a rigorous description of the input and output which covers all cases. Design : You may have several data objects (such as a maze, a polynomial, or a list of names). For each object there will be some basic operations to perform on it (such as print the maze, add two polynomials, or find a name in the list.) Assume that these operations already exist in the form of procedures and write an algorithm which solves the problem according to the requirements. Use a notation which is natural to the way you wish to describe the order of processing. Analysis: If you can think of another algorithm, then write it down. Next try to compare the two algorithms you have in hand. It may already be possible to tell if one will be more desirable than the other. If you cannot distinguish between two, choose one to work on for now. Refinement and coding: You must now choose representations for your data objects (a maze as a two dimensional array of degree and coefficients, a list of names possibly as an array) and write algorithms for each of the operations on these objects. Verification: Verification consists of three distinct aspects: program proving, testing and debugging. Each of these is an art in itself. Before executing your program you should attempt tp prove it is correct. Testing is the art of creating sample data upon which to run your program. If the program fails to run correctly then debugging is needed to determine what went wrong and how to correct it.
  • 3. Suppose we devise a program for sorting a set of n>=1 integers. One of the simplest solutions is given by the following: &quot;from those integers which remain unsorted, find the smallest and place it next in the sorted list.&quot; This statement is sufficient to construct a sorting program. However several issues are not fully specified such as where and how the integers are initially stored and where result is to be placed. One solution is to store the values in an array in such a way that the i-th integer is stored in the i-th array position, a[i] 1<=i<=n . Below is a second refinement of the solution: for i :=1 to n do begin  examine a [i] to a [n] and suppose the smallest integer is at a [ j ];  interchange a [ i ] and a [ j ]; end; There now remain two clearly defined subtasks: (i) to find the minimum integer and (ii) to interchange it with a[i]. This latter problem can be solved by the code t:=a[i];    a[i]:=a[j];    a[j]:=t; The first subtask can be solved by assuming the minimum is a[i], checking a[i] with a[i+1], a[i+2],...and whenever a smaller element is found, regarding it as the new minimum. Eventually a[n] is compared to the current minimum and we are done. Putting all these observations together we get the procedure sort.
  • 4. Let us develop another program. We assume that we have n>=1 distinct integers which are already sorted and stored in the array a[1..n]. Our task is to determine if the integer x is present and if so to return j such that x=a[j]; otherwise return j=0. By making use of the fact that the set is sorted we conceive of the following efficient method: &quot;let a[mid] be the middle element. There are three possibilities. Either x<a[mid] in which case x can only occur as a[1] to a[mid-1]; or x>a[mid] in which case x can only occur as a[mid+1] to a[n]; or x=a[mid] in which case set j to mid and return. Result in the next Slide
  • 5. procedure binsrch (a: elementlist; x: element; var n,j: integer ); {search the sorted array a[1..n] for x} initialize lower and upper begin      while there are more elements do      begin         let a[mid] be the middle element;          case compare (x, a[mid]) of              '>': set lower to mid + 1;              '<': set upper to mid - 1;              '=': found x;          end ; {of case }      end ; {of while }     not found; end ;{of binsrch}
  • 6. How to Analyze Programs
  • 7. There are many criteria upon which we can judge a program, for instance: Does it do what we want it to do? Does it work correctly according to the original specifications of the task? Is there documentation which describes how to use it and how it works? Are procedures created in such a way that they perform logical sub-functions? Is the code readable?
  • 8. These have to do with computing time and storage requirements of the algorithms. Performance evaluation can be loosely divided into 2 major phases: (a) a priori estimates and (b) a postpriori testing. Both of these are equally important. Consider the examples below: x:=x+1; We assume that the statement x:=x+1 is not contained within any loop either explicit or implicit. Then its frequency count is one. for i:=1 to n do    x:=x+1; Now, the same statement will be executed n times. for i:=1 to n do   for i:=1 to n do   x:=x+1; It will be executed (n*n) times now. There are other criteria for judging programs which have a more direct relationship to performance.
  • 9. To clarify some of the ideas stated in this section, take a look at a simple program for computing the n-th Fibonacci number. The Fibonacci sequence starts as 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,.... Each new term is obtained by taking the sum of the two previous terms. If we call the first term of the sequence F[0] then F[0]=0, F[1]=1 and in general F[n] = F[n-1] + F [n-2], n>=2.