SlideShare ist ein Scribd-Unternehmen logo
1 von 64
PseudoCode
Damian Gordon
Pseudocode
• The first thing we do when designing a
program is to decide on a name for the
program.
Pseudocode
• The first thing we do when designing a
program is to decide on a name for the
program.
• Let’s say we want to write a program to
calculate interest, a good name for the
program would be CalculateInterest.
Pseudocode
• The first thing we do when designing a
program is to decide on a name for the
program.
• Let’s say we want to write a program to
calculate interest, a good name for the
program would be CalculateInterest.
• Note the use of CamelCase.
Pseudocode
• The first thing we do when designing a
program is to decide on a name for the
program.
• Let’s say we want to write a program to
calculate interest, a good name for the
program would be CalculateInterest.
• Note the use of CamelCase.
Pseudocode
• So we start the program as:
PROGRAM CalculateInterest:
Pseudocode
• So we start the program as:
PROGRAM CalculateInterest:
• And in general it’s:

PROGRAM <ProgramName>:
Pseudocode
• Our program will finish with the following:
END.
Pseudocode
• Our program will finish with the following:
END.
• And in general it’s the same:

END.
Pseudocode
• So the general structure of all programs is:
PROGRAM <ProgramName>:
<Do stuff>
END.
SEQUENCE
Pseudocode
• When we write programs, we assume that the
computer executes the program starting at
the beginning and working its way to the end.
• This is a basic assumption of all algorithm
design.
Pseudocode
• When we write programs, we assume that the
computer executes the program starting at
the beginning and working its way to the end.
• This is a basic assumption of all algorithm
design.
• We call this SEQUENCE.
Pseudocode
• In Pseudo code it looks like this:
Statement1;
Statement2;
Statement3;
Statement4;
Statement5;
Statement6;
Statement7;
Statement8;
Pseudocode
• For example, for making a cup of tea:

Organise everything together;
Plug in kettle;
Put teabag in cup;
Put water into kettle;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk and/or sugar;
Serve;
Pseudocode
• Or as a program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
Put water into kettle;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk and/or sugar;
Serve;
END.
Pseudocode
• Or as a program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
Put water into kettle;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk and/or sugar;
Serve;
END.
SELECTION
Pseudocode
• What if we want to make a choice, for
example, do we want to add sugar or not to
the tea?
Pseudocode
• What if we want to make a choice, for
example, do we want to add sugar or not to
the tea?
• We call this SELECTION.
Pseudocode
• So, we could state this as:
IF (sugar is required)
THEN add sugar;
ELSE don’t add sugar;
ENDIF;
Pseudocode
• Or, in general:
IF (<CONDITION>)
THEN <Statements>;
ELSE <Statements>;
ENDIF;
Pseudocode
• Or to check which number is biggest:
IF (A > B)
THEN Print A + “is bigger”;
ELSE Print B + “is bigger”;
ENDIF;
Pseudocode
•

Adding a selection statement in the program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
Put water into kettle;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk;
IF (sugar is required)
THEN add sugar;
ELSE do nothing;
ENDIF;
Serve;
END.
Pseudocode
•

Adding a selection statement in the program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
Put water into kettle;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk;
IF (sugar is required)
THEN add sugar;
ELSE do nothing;
ENDIF;
Serve;
END.
ITERATION
Pseudocode
• What if we need to tell the computer to keep
doing something until some condition occurs?
Pseudocode
• What if we need to tell the computer to keep
doing something until some condition occurs?
• Let’s say we wish to indicate that the you need
to keep filling the kettle with water until it is
full.
Pseudocode
• What if we need to tell the computer to keep
doing something until some condition occurs?
• Let’s say we wish to indicate that the you need
to keep filling the kettle with water until it is
full.
• We need a loop, or ITERATION.
Pseudocode
• So, we could state this as:
WHILE (Kettle is not full)
DO keep filling kettle;
ENDWHILE;
Pseudocode
• Or, in general:
WHILE (<CONDITION>)
DO <Statements>;
ENDWHILE;
Pseudocode
• Or to print out the numbers 1 to 5:
A = 1;
WHILE(A < 5)
DO Print A;
A = A + 1;
ENDWHILE;
Pseudocode
• What is the benefit of using a loop?
Pseudocode
• Consider the problem of searching for an
entry in a phone book with only condition:
Pseudocode
• Consider the problem of searching for an
entry in a phone book with only condition:
Get first entry
If this is the required entry
Then write down phone number
Else get next entry
If this is the correct entry
then write done entry
else get next entry
if this is the correct entry
…………….
Pseudocode
• This could take forever to specify.
Pseudocode
• This could take forever to specify.
• There must be a better way to do it.
Pseudocode
• We may rewrite this as follows:
Get first entry;
Call this entry N;
WHILE N is NOT the required entry
DO Get next entry;
Call this entry N;
ENDWHILE;
Pseudocode
• We may rewrite this as follows:
Get first entry;
Call this entry N;
WHILE N is NOT the required entry
DO Get next entry;
Call this entry N;
ENDWHILE;

• This is why we love loops!
Pseudocode
•

Or as a program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
WHILE (Kettle is not full)
DO keep filling kettle;
ENDWHILE;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk;
IF (sugar is required)
THEN add sugar;
ELSE do nothing;
ENDIF;
Serve;
END.
Pseudocode
•

Or as a program:

PROGRAM MakeACupOfTea:
Organise everything together;
Plug in kettle;
Put teabag in cup;
WHILE (Kettle is not full)
DO keep filling kettle;
ENDWHILE;
Wait for kettle to boil;
Add water to cup;
Remove teabag with spoon/fork;
Add milk;
IF (sugar is required)
THEN add sugar;
ELSE do nothing;
ENDIF;
Serve;
END.
EXAMPLES
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and print it out.
Pseudocode
PROGRAM PrintNumber:
Read A;
Print A;
END.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and print it out double the number.
Pseudocode
PROGRAM PrintDoubleNumber:
Read A;
B = A*2;
Print B;
END.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number, check if it is odd or even.
Pseudocode
PROGRAM IsOddOrEven:
Read A;
IF (A/2 gives a remainder)
THEN Print “It’s Odd”;
ELSE Print “It’s Even”;
ENDIF;
END.
Pseudocode
• So let’s say we want to express the
following algorithm to print out the bigger
of two numbers:
– Read in two numbers, call them A and B. Is A is bigger
than B, print out A, otherwise print out B.
Pseudocode
PROGRAM PrintBiggerOfTwo:
Read A;
Read B;
IF (A>B)
THEN Print A;
ELSE Print B;
ENDIF;
END.
Pseudocode
• So let’s say we want to express the
following algorithm to print out the bigger
of three numbers:
– Read in three numbers, call them A, B and C.
• If A is bigger than B, then if A is bigger than C, print out
A, otherwise print out C.
• If B is bigger than A, then if B is bigger than C, print out
B, otherwise print out C.
Pseudocode
PROGRAM BiggerOfThree:
Read A;
Read B;
Read C;
IF (A>B)
THEN IF (A>C)
THEN Print A;
ELSE Print C;
END IF;
ELSE IF (B>C)
THEN Print B;
ELSE Print C;
END IF;

END IF;
END.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Print out the numbers from 1 to 5
Pseudocode
PROGRAM Print1to5:
A = 1;
WHILE (A != 6)
DO Print A;
A = A + 1;
ENDWHILE;
END.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Add up the numbers 1 to 5 and print out the result
Pseudocode
PROGRAM PrintSum1to5:
Total = 0;
A = 1;
WHILE (A != 6)
DO Total = Total + A;
A = A + 1;
ENDWHILE;
Print Total;
END.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and check if it’s a prime number.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and check if it’s a prime number.
– What’s a prime number?
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and check if it’s a prime number.
– What’s a prime number?
– A number that’s only divisible by itself and 1, e.g. 7.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and check if it’s a prime number.
– What’s a prime number?
– A number that’s only divisible by itself and 1, e.g. 7.
– Or to put it another way, every number other than itself and 1
gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder
then 7 is prime.
Pseudocode
• So let’s say we want to express the
following algorithm:
– Read in a number and check if it’s a prime number.
– What’s a prime number?
– A number that’s only divisible by itself and 1, e.g. 7.
– Or to put it another way, every number other than itself and 1
gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder
then 7 is prime.
– So all we need to do is divide 7 by all numbers less than it but
greater than one, and if any of them have no remainder, we
know it’s not prime.
Pseudocode
• So,
• If the number is 7, as long as 6, 5, 4, 3, and
2 give a remainder, 7 is prime.
• If the number is 9, we know that
8, 7, 6, 5, and 4, all give remainders, but 3
does not give a remainder, it goes evenly
into 9 so we can say 9 is not prime
Pseudocode
• So remember,
– if the number is 7, as long as 6, 5, 4, 3, and 2
give a remainder, 7 is prime.

• So, in general,
– if the number is A, as long as A-1, A-2, A-3, A4, ... 2 give a remainder, A is prime.
Pseudocode
PROGRAM Prime:
Read A;
B = A - 1;
IsPrime=True;
WHILE (B != 1)
DO IF (A/B gives no remainder)
THEN IsPrime= False;
ENDIF;
B = B – 1;
ENDWHILE;
IF (IsPrime == true)
THEN Print “Prime”;
ELSE Print “Not Prime”;
ENDIF;
END.

Weitere ähnliche Inhalte

Was ist angesagt?

Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsAr Kyu Dee
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartRabin BK
 
The pseudocode
The pseudocodeThe pseudocode
The pseudocodeAsha Sari
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart exampleshayrikk
 
New Trends in software development
New Trends in software developmentNew Trends in software development
New Trends in software developmentKabir Khanna
 
SPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartSPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartMohammad Imam Hossain
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and FlowchartsSURBHI SAROHA
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowchartsnicky_walters
 

Was ist angesagt? (20)

3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
The pseudocode
The pseudocodeThe pseudocode
The pseudocode
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
New Trends in software development
New Trends in software developmentNew Trends in software development
New Trends in software development
 
Computer Keyboard
Computer KeyboardComputer Keyboard
Computer Keyboard
 
SPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartSPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and Flowchart
 
Compilers
CompilersCompilers
Compilers
 
Iterative model
Iterative modelIterative model
Iterative model
 
Spiral model
Spiral modelSpiral model
Spiral model
 
Typing lesson
Typing lessonTyping lesson
Typing lesson
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and Flowcharts
 
Flow chart
Flow chartFlow chart
Flow chart
 
Software Evolution
Software EvolutionSoftware Evolution
Software Evolution
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Scratch Programming
Scratch ProgrammingScratch Programming
Scratch Programming
 

Andere mochten auch

Andere mochten auch (8)

Algorithms
AlgorithmsAlgorithms
Algorithms
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 

Ähnlich wie Introduction to Pseudocode

PyCon 2015 (Py.15): Python Beginner's Tutorial
PyCon 2015 (Py.15): Python Beginner's TutorialPyCon 2015 (Py.15): Python Beginner's Tutorial
PyCon 2015 (Py.15): Python Beginner's TutorialDamian T. Gordon
 
A complete course in Program Design using Pseudocode
A complete course in Program Design using Pseudocode A complete course in Program Design using Pseudocode
A complete course in Program Design using Pseudocode Damian T. Gordon
 
Simple programming
Simple programmingSimple programming
Simple programmingamcsquared
 
Sales and Operations Planning Worst Practices
Sales and Operations Planning Worst PracticesSales and Operations Planning Worst Practices
Sales and Operations Planning Worst PracticesPamela Stroud
 
Introduction to Flowol for Key Stage 3
Introduction to Flowol for Key Stage 3Introduction to Flowol for Key Stage 3
Introduction to Flowol for Key Stage 3mrpeddle
 
How ESUP-Portail contributes to open source software for higher ed
How ESUP-Portail contributes to open source software for higher edHow ESUP-Portail contributes to open source software for higher ed
How ESUP-Portail contributes to open source software for higher edmatguerin
 
Scientific Thinking for Agile teams - TOYOTA KATA
Scientific Thinking for Agile teams - TOYOTA KATAScientific Thinking for Agile teams - TOYOTA KATA
Scientific Thinking for Agile teams - TOYOTA KATAAndrea Darabos
 
Writing process workshop
Writing process workshopWriting process workshop
Writing process workshopweigansm
 
Testing antipatterns
Testing antipatternsTesting antipatterns
Testing antipatternsArdesco
 

Ähnlich wie Introduction to Pseudocode (13)

PyCon 2015 (Py.15): Python Beginner's Tutorial
PyCon 2015 (Py.15): Python Beginner's TutorialPyCon 2015 (Py.15): Python Beginner's Tutorial
PyCon 2015 (Py.15): Python Beginner's Tutorial
 
Algorithm and psuedocode
Algorithm and psuedocodeAlgorithm and psuedocode
Algorithm and psuedocode
 
A complete course in Program Design using Pseudocode
A complete course in Program Design using Pseudocode A complete course in Program Design using Pseudocode
A complete course in Program Design using Pseudocode
 
Simple programming
Simple programmingSimple programming
Simple programming
 
Sales and Operations Planning Worst Practices
Sales and Operations Planning Worst PracticesSales and Operations Planning Worst Practices
Sales and Operations Planning Worst Practices
 
User Story Sizing using Agile Relative Estimation
User Story Sizing using Agile Relative EstimationUser Story Sizing using Agile Relative Estimation
User Story Sizing using Agile Relative Estimation
 
Introduction to Flowol for Key Stage 3
Introduction to Flowol for Key Stage 3Introduction to Flowol for Key Stage 3
Introduction to Flowol for Key Stage 3
 
Week 1
Week 1Week 1
Week 1
 
How ESUP-Portail contributes to open source software for higher ed
How ESUP-Portail contributes to open source software for higher edHow ESUP-Portail contributes to open source software for higher ed
How ESUP-Portail contributes to open source software for higher ed
 
AS computing
AS computingAS computing
AS computing
 
Scientific Thinking for Agile teams - TOYOTA KATA
Scientific Thinking for Agile teams - TOYOTA KATAScientific Thinking for Agile teams - TOYOTA KATA
Scientific Thinking for Agile teams - TOYOTA KATA
 
Writing process workshop
Writing process workshopWriting process workshop
Writing process workshop
 
Testing antipatterns
Testing antipatternsTesting antipatterns
Testing antipatterns
 

Mehr von Damian T. Gordon

Universal Design for Learning, Co-Designing with Students.
Universal Design for Learning, Co-Designing with Students.Universal Design for Learning, Co-Designing with Students.
Universal Design for Learning, Co-Designing with Students.Damian T. Gordon
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to MicroservicesDamian T. Gordon
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud ComputingDamian T. Gordon
 
Evaluating Teaching: SECTIONS
Evaluating Teaching: SECTIONSEvaluating Teaching: SECTIONS
Evaluating Teaching: SECTIONSDamian T. Gordon
 
Evaluating Teaching: MERLOT
Evaluating Teaching: MERLOTEvaluating Teaching: MERLOT
Evaluating Teaching: MERLOTDamian T. Gordon
 
Evaluating Teaching: Anstey and Watson Rubric
Evaluating Teaching: Anstey and Watson RubricEvaluating Teaching: Anstey and Watson Rubric
Evaluating Teaching: Anstey and Watson RubricDamian T. Gordon
 
Designing Teaching: Pause Procedure
Designing Teaching: Pause ProcedureDesigning Teaching: Pause Procedure
Designing Teaching: Pause ProcedureDamian T. Gordon
 
Designing Teaching: ASSURE
Designing Teaching: ASSUREDesigning Teaching: ASSURE
Designing Teaching: ASSUREDamian T. Gordon
 
Designing Teaching: Laurilliard's Learning Types
Designing Teaching: Laurilliard's Learning TypesDesigning Teaching: Laurilliard's Learning Types
Designing Teaching: Laurilliard's Learning TypesDamian T. Gordon
 
Designing Teaching: Gagne's Nine Events of Instruction
Designing Teaching: Gagne's Nine Events of InstructionDesigning Teaching: Gagne's Nine Events of Instruction
Designing Teaching: Gagne's Nine Events of InstructionDamian T. Gordon
 
Designing Teaching: Elaboration Theory
Designing Teaching: Elaboration TheoryDesigning Teaching: Elaboration Theory
Designing Teaching: Elaboration TheoryDamian T. Gordon
 
Universally Designed Learning Spaces: Some Considerations
Universally Designed Learning Spaces: Some ConsiderationsUniversally Designed Learning Spaces: Some Considerations
Universally Designed Learning Spaces: Some ConsiderationsDamian T. Gordon
 

Mehr von Damian T. Gordon (20)

Universal Design for Learning, Co-Designing with Students.
Universal Design for Learning, Co-Designing with Students.Universal Design for Learning, Co-Designing with Students.
Universal Design for Learning, Co-Designing with Students.
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
REST and RESTful Services
REST and RESTful ServicesREST and RESTful Services
REST and RESTful Services
 
Serverless Computing
Serverless ComputingServerless Computing
Serverless Computing
 
Cloud Identity Management
Cloud Identity ManagementCloud Identity Management
Cloud Identity Management
 
Containers and Docker
Containers and DockerContainers and Docker
Containers and Docker
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud Computing
 
Introduction to ChatGPT
Introduction to ChatGPTIntroduction to ChatGPT
Introduction to ChatGPT
 
How to Argue Logically
How to Argue LogicallyHow to Argue Logically
How to Argue Logically
 
Evaluating Teaching: SECTIONS
Evaluating Teaching: SECTIONSEvaluating Teaching: SECTIONS
Evaluating Teaching: SECTIONS
 
Evaluating Teaching: MERLOT
Evaluating Teaching: MERLOTEvaluating Teaching: MERLOT
Evaluating Teaching: MERLOT
 
Evaluating Teaching: Anstey and Watson Rubric
Evaluating Teaching: Anstey and Watson RubricEvaluating Teaching: Anstey and Watson Rubric
Evaluating Teaching: Anstey and Watson Rubric
 
Evaluating Teaching: LORI
Evaluating Teaching: LORIEvaluating Teaching: LORI
Evaluating Teaching: LORI
 
Designing Teaching: Pause Procedure
Designing Teaching: Pause ProcedureDesigning Teaching: Pause Procedure
Designing Teaching: Pause Procedure
 
Designing Teaching: ADDIE
Designing Teaching: ADDIEDesigning Teaching: ADDIE
Designing Teaching: ADDIE
 
Designing Teaching: ASSURE
Designing Teaching: ASSUREDesigning Teaching: ASSURE
Designing Teaching: ASSURE
 
Designing Teaching: Laurilliard's Learning Types
Designing Teaching: Laurilliard's Learning TypesDesigning Teaching: Laurilliard's Learning Types
Designing Teaching: Laurilliard's Learning Types
 
Designing Teaching: Gagne's Nine Events of Instruction
Designing Teaching: Gagne's Nine Events of InstructionDesigning Teaching: Gagne's Nine Events of Instruction
Designing Teaching: Gagne's Nine Events of Instruction
 
Designing Teaching: Elaboration Theory
Designing Teaching: Elaboration TheoryDesigning Teaching: Elaboration Theory
Designing Teaching: Elaboration Theory
 
Universally Designed Learning Spaces: Some Considerations
Universally Designed Learning Spaces: Some ConsiderationsUniversally Designed Learning Spaces: Some Considerations
Universally Designed Learning Spaces: Some Considerations
 

Kürzlich hochgeladen

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 

Kürzlich hochgeladen (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Introduction to Pseudocode

  • 2. Pseudocode • The first thing we do when designing a program is to decide on a name for the program.
  • 3. Pseudocode • The first thing we do when designing a program is to decide on a name for the program. • Let’s say we want to write a program to calculate interest, a good name for the program would be CalculateInterest.
  • 4. Pseudocode • The first thing we do when designing a program is to decide on a name for the program. • Let’s say we want to write a program to calculate interest, a good name for the program would be CalculateInterest. • Note the use of CamelCase.
  • 5. Pseudocode • The first thing we do when designing a program is to decide on a name for the program. • Let’s say we want to write a program to calculate interest, a good name for the program would be CalculateInterest. • Note the use of CamelCase.
  • 6. Pseudocode • So we start the program as: PROGRAM CalculateInterest:
  • 7. Pseudocode • So we start the program as: PROGRAM CalculateInterest: • And in general it’s: PROGRAM <ProgramName>:
  • 8. Pseudocode • Our program will finish with the following: END.
  • 9. Pseudocode • Our program will finish with the following: END. • And in general it’s the same: END.
  • 10. Pseudocode • So the general structure of all programs is: PROGRAM <ProgramName>: <Do stuff> END.
  • 12. Pseudocode • When we write programs, we assume that the computer executes the program starting at the beginning and working its way to the end. • This is a basic assumption of all algorithm design.
  • 13. Pseudocode • When we write programs, we assume that the computer executes the program starting at the beginning and working its way to the end. • This is a basic assumption of all algorithm design. • We call this SEQUENCE.
  • 14. Pseudocode • In Pseudo code it looks like this: Statement1; Statement2; Statement3; Statement4; Statement5; Statement6; Statement7; Statement8;
  • 15. Pseudocode • For example, for making a cup of tea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve;
  • 16. Pseudocode • Or as a program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve; END.
  • 17. Pseudocode • Or as a program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve; END.
  • 19. Pseudocode • What if we want to make a choice, for example, do we want to add sugar or not to the tea?
  • 20. Pseudocode • What if we want to make a choice, for example, do we want to add sugar or not to the tea? • We call this SELECTION.
  • 21. Pseudocode • So, we could state this as: IF (sugar is required) THEN add sugar; ELSE don’t add sugar; ENDIF;
  • 22. Pseudocode • Or, in general: IF (<CONDITION>) THEN <Statements>; ELSE <Statements>; ENDIF;
  • 23. Pseudocode • Or to check which number is biggest: IF (A > B) THEN Print A + “is bigger”; ELSE Print B + “is bigger”; ENDIF;
  • 24. Pseudocode • Adding a selection statement in the program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.
  • 25. Pseudocode • Adding a selection statement in the program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.
  • 27. Pseudocode • What if we need to tell the computer to keep doing something until some condition occurs?
  • 28. Pseudocode • What if we need to tell the computer to keep doing something until some condition occurs? • Let’s say we wish to indicate that the you need to keep filling the kettle with water until it is full.
  • 29. Pseudocode • What if we need to tell the computer to keep doing something until some condition occurs? • Let’s say we wish to indicate that the you need to keep filling the kettle with water until it is full. • We need a loop, or ITERATION.
  • 30. Pseudocode • So, we could state this as: WHILE (Kettle is not full) DO keep filling kettle; ENDWHILE;
  • 31. Pseudocode • Or, in general: WHILE (<CONDITION>) DO <Statements>; ENDWHILE;
  • 32. Pseudocode • Or to print out the numbers 1 to 5: A = 1; WHILE(A < 5) DO Print A; A = A + 1; ENDWHILE;
  • 33. Pseudocode • What is the benefit of using a loop?
  • 34. Pseudocode • Consider the problem of searching for an entry in a phone book with only condition:
  • 35. Pseudocode • Consider the problem of searching for an entry in a phone book with only condition: Get first entry If this is the required entry Then write down phone number Else get next entry If this is the correct entry then write done entry else get next entry if this is the correct entry …………….
  • 36. Pseudocode • This could take forever to specify.
  • 37. Pseudocode • This could take forever to specify. • There must be a better way to do it.
  • 38. Pseudocode • We may rewrite this as follows: Get first entry; Call this entry N; WHILE N is NOT the required entry DO Get next entry; Call this entry N; ENDWHILE;
  • 39. Pseudocode • We may rewrite this as follows: Get first entry; Call this entry N; WHILE N is NOT the required entry DO Get next entry; Call this entry N; ENDWHILE; • This is why we love loops!
  • 40. Pseudocode • Or as a program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; WHILE (Kettle is not full) DO keep filling kettle; ENDWHILE; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.
  • 41. Pseudocode • Or as a program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; WHILE (Kettle is not full) DO keep filling kettle; ENDWHILE; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.
  • 43. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and print it out.
  • 45. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and print it out double the number.
  • 47. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number, check if it is odd or even.
  • 48. Pseudocode PROGRAM IsOddOrEven: Read A; IF (A/2 gives a remainder) THEN Print “It’s Odd”; ELSE Print “It’s Even”; ENDIF; END.
  • 49. Pseudocode • So let’s say we want to express the following algorithm to print out the bigger of two numbers: – Read in two numbers, call them A and B. Is A is bigger than B, print out A, otherwise print out B.
  • 50. Pseudocode PROGRAM PrintBiggerOfTwo: Read A; Read B; IF (A>B) THEN Print A; ELSE Print B; ENDIF; END.
  • 51. Pseudocode • So let’s say we want to express the following algorithm to print out the bigger of three numbers: – Read in three numbers, call them A, B and C. • If A is bigger than B, then if A is bigger than C, print out A, otherwise print out C. • If B is bigger than A, then if B is bigger than C, print out B, otherwise print out C.
  • 52. Pseudocode PROGRAM BiggerOfThree: Read A; Read B; Read C; IF (A>B) THEN IF (A>C) THEN Print A; ELSE Print C; END IF; ELSE IF (B>C) THEN Print B; ELSE Print C; END IF; END IF; END.
  • 53. Pseudocode • So let’s say we want to express the following algorithm: – Print out the numbers from 1 to 5
  • 54. Pseudocode PROGRAM Print1to5: A = 1; WHILE (A != 6) DO Print A; A = A + 1; ENDWHILE; END.
  • 55. Pseudocode • So let’s say we want to express the following algorithm: – Add up the numbers 1 to 5 and print out the result
  • 56. Pseudocode PROGRAM PrintSum1to5: Total = 0; A = 1; WHILE (A != 6) DO Total = Total + A; A = A + 1; ENDWHILE; Print Total; END.
  • 57. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
  • 58. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number?
  • 59. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7.
  • 60. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1 gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime.
  • 61. Pseudocode • So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1 gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime. – So all we need to do is divide 7 by all numbers less than it but greater than one, and if any of them have no remainder, we know it’s not prime.
  • 62. Pseudocode • So, • If the number is 7, as long as 6, 5, 4, 3, and 2 give a remainder, 7 is prime. • If the number is 9, we know that 8, 7, 6, 5, and 4, all give remainders, but 3 does not give a remainder, it goes evenly into 9 so we can say 9 is not prime
  • 63. Pseudocode • So remember, – if the number is 7, as long as 6, 5, 4, 3, and 2 give a remainder, 7 is prime. • So, in general, – if the number is A, as long as A-1, A-2, A-3, A4, ... 2 give a remainder, A is prime.
  • 64. Pseudocode PROGRAM Prime: Read A; B = A - 1; IsPrime=True; WHILE (B != 1) DO IF (A/B gives no remainder) THEN IsPrime= False; ENDIF; B = B – 1; ENDWHILE; IF (IsPrime == true) THEN Print “Prime”; ELSE Print “Not Prime”; ENDIF; END.