SlideShare a Scribd company logo
CS1101
Introduction toComputer Programming and
Data Structures
Dr. B Ramachandra Reddy
Outline
• Algorithm
• Flow Charts
• Pseudo Code
Program Planning
 To write a correct program, a programmer must write each and every
instruction in the correct sequence
 Logic (instruction sequence) of a program can be very complex
 Hence, programs must be planned before they are written to ensure
program instructions are:
 Appropriate for the problem
 In the correct sequence
Algorithm
 Refers to the logic of a program and a step-by-step description of how to
arrive at the solution of a given problem.
 In order to qualify as an algorithm, a sequence of instructions must
have following characteristics:
 Each and every instruction should be precise and unambiguous
 Each instruction should be such that it can be performed in a finite time
 One or more instructions should not be repeated infinitely. This ensures that the
algorithm will ultimately terminate
 After performing the instructions, that is after the algorithm terminates, the
desired results must be obtained
SampleAlgorithm (Example 1)
• There are 50 students in a class who appeared in their
final examination. Their mark sheets have been given to
you.
• The division column of the mark sheet contains the
division (FIRST, SECOND, THIRD or FAIL) obtained by the
student.
• Write an algorithm to calculate and print the total
number of students who passed in FIRST division.
SampleAlgorithm (Example 1)
Step 1: Initialize Total_First_Division and
Total_Marksheets_Checked to zero.
Step 2: Take the mark sheet of the next student.
Step 3: Check the division column of the mark sheet to see if it is
FIRST, if no, go to Step 5.
Step 4: Add 1 to Total_First_Division.
Step 5: Add 1 to Total_Marksheets_Checked.
Step 6: Is Total_Marksheets_Checked = 50, if no, go to Step 2.
Step 7: Print Total_First_Division.
Step 8: Stop.
Representation ofAlgorithms
 As flowcharts
 As pseudocodes
Flowchart
 Flowchart is a pictorial representation of an algorithm
 Uses symbols (boxes of different shapes) that have
standardized meanings to denote different types of
instructions
 Actual instructions are written within the boxes
 Boxes are connected by solid lines having arrow marks
to indicate the exact sequence in which the instructions
are to be executed
 Process of drawing a flowchart for an algorithm is called
flowcharting
Basic FlowchartSymbols
Examples of Decision Symbol
Is I = 10?
No
Yes
(a) A two-way branch decision. (b) A three-way branch decision.
A > B
A = B
A < B Compare
A & B
Examples of Decision Symbol
I = ?
(c) A multiple-way branch decision.
= 0 = 1 = 2 = 3 = 4 = 5 = Other
Sample Flowchart
Sample Flowchart
Pseudocode
 A program planning tool where program logic is written in
an ordinary natural language using a structure that
resembles computer instructions
 “ Pseudo” means imitation or false and “ Code” refers to
the instructions written in a programming language.
Hence, pseudocode is an imitation of actual computer
instructions
 Because it emphasizes the design of the program,
pseudocode is also called Program Design Language
(PDL)
Basic Logic (Control) Structures
• Any program logic can be expressed by using only
following three simple logic structures:
1. Sequence logic,
2. Selection logic, and
3. Iteration (or looping) logic
• Programs structured by using only these three logic
structures are called structured programs, and the
technique of writing such programs is known as structured
programming
Pseudocode
• read/get – indicates a user will be inputting something
• display/print/show – indicates that an output will appear on the screen
• SET, INIT: To initialize values
• Expressions
• ←Assignment (like = inC)
• = Equality testing (like = = inC)
• n2 superscripts and other mathematical formatting allowed
• Method call
• var.method (arg [, arg…])
• Return value
• return expression
SequenceLogic
Process 1
(b) Pseudocode
Process 2
Process 1
Process 2
(a) Flowchart
Selection Logic
• Also known as decision logic, it is used for making decisions
• Three popularly used selection logic structures are
1. IF…THEN…ELSE
2. IF…THEN
3. CASE
Selection Logic (IF…THEN…ELSE Structure)
THEN
ELSE
Process 1
Process 2
IF Condition
ENDIF
(b) Pseudocode
THEN
Process 1
ELSE
Process 2
Yes No
(a) Flowchart
IF (condition)
Selection Logic (IF…THEN Structure)
(b) Pseudocode
THEN
ENDIF
IF Condition
Process 1
THEN
Process 1
Yes No
(a) Flowchart
IF (condition)
Selection Logic (CASE Structure)
(b) Pseudocode
CASE Type
Case Type 1:
Case Type 2:
Process 1
Process 2
ENDCASE
Case Type n: Process n
Type 1
Type n
Process 2
Process 1
Process n
Yes
Yes
Yes
No
Type 2
No
No
(a) Flowchart
Iteration (or Looping) Logic
 Used to produce loops in program logic when one or more instructions may
be executed several times depending on some conditions
 Two popularly used iteration logic structures are
1. DO…WHILE
2. REPEAT…UNTIL
Iteration (or Looping) Logic
(DO…WHILE Structure)
(b) Pseudocode
DO WHILE Condition
Process 1
Process n
ENDDO
Process 1
False
(a) Flowchart
Process n
True
Condition?
Block
Iteration (or Looping) Logic
(REPEAT…UNTIL Structure)
(b) Pseudocode
REPEAT
Process 1
Process n
UNTIL Condition
Process 1
Process n
True
(a) Flowchart
False
Condition?
SampleAlgorithm
SampleAlgorithm
Algorithms for c nit jamshedpur first year
Flowchart Pseudocode
Start/End Begin/End
Input/output Read: read x,y
Print: Print y
Process Computation: X<-y+6
Decision If/if-lse/case/while/
do-while/for
Connector Not Applicable
Predefined Process Not Applicable
FlowchartVs Pseudo code
FlowchartVs Pseudo code
• Flowchart Advantages
• Standard
• Visual
• Flowchart Disadvantages
• Hard to modify
• Structured design elements not
implemented
• Special software required
• Pseudocode Advantages
• Easily modified
• Implements structured concepts
• Done easy on Word Processor
• Pseudocode Disadvantages
• Not Visual
• Not accepted standard, varies
from company to company
Assignments
• Write a pseudo code and flowchart to find the given number is prime
or not?
• Write a pseudo code and flowchart to generate the Fibonacci series
upto n numbers.
• Write a pseudo code and flowchart to check the given number is
palindrome or not?

More Related Content

PPT
Programming algorithms and flowchart.ppt
PPT
Unit 1 psp
PPT
UNIT- 3-FOC.ppt
PPT
Proble, Solving & Automation
PDF
Cse115 lecture03problemsolving
PPTX
UNIT I.pptxpython unit 1 engineering full unit completed
PPT
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
PPTX
UNIT 1.pptx
Programming algorithms and flowchart.ppt
Unit 1 psp
UNIT- 3-FOC.ppt
Proble, Solving & Automation
Cse115 lecture03problemsolving
UNIT I.pptxpython unit 1 engineering full unit completed
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
UNIT 1.pptx

Similar to Algorithms for c nit jamshedpur first year (20)

PPTX
Data Structures_Introduction to algorithms.pptx
PPTX
programming part 1 introduction to python.pptx
PDF
Introduction to Problem Solving Techniques- Python
PPT
Algorithm Designs - Control Structures
PPTX
Algorithms and Flowcharts
PPT
Lect 3-4 Zaheer Abbas
PPT
Pengenalan kepada pengaturcaraan berstruktur
PDF
Notes on algorithms
PPTX
PPTX
UNIT 1.pptx Programming for Problem Solving
PDF
Algorithm.pdf
PPT
Algorithms and Flowchart.ppt
PPT
256958.ppt
DOCX
Com Ed 6 Prelim
PDF
Unit 1-problem solving with algorithm
PPT
01 Algorithms And Flowcharts.ppt
PPTX
Algorithmsandflowcharts1
PPTX
Problem Solving - Introduction to Flowcharts.pptx
PPTX
Algorithms-Flowcharts for programming fundamental
PDF
Com Ed 6 Prelim
Data Structures_Introduction to algorithms.pptx
programming part 1 introduction to python.pptx
Introduction to Problem Solving Techniques- Python
Algorithm Designs - Control Structures
Algorithms and Flowcharts
Lect 3-4 Zaheer Abbas
Pengenalan kepada pengaturcaraan berstruktur
Notes on algorithms
UNIT 1.pptx Programming for Problem Solving
Algorithm.pdf
Algorithms and Flowchart.ppt
256958.ppt
Com Ed 6 Prelim
Unit 1-problem solving with algorithm
01 Algorithms And Flowcharts.ppt
Algorithmsandflowcharts1
Problem Solving - Introduction to Flowcharts.pptx
Algorithms-Flowcharts for programming fundamental
Com Ed 6 Prelim
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Cell Types and Its function , kingdom of life
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Lesson notes of climatology university.
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Classroom Observation Tools for Teachers
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
RMMM.pdf make it easy to upload and study
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Cell Types and Its function , kingdom of life
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Microbial disease of the cardiovascular and lymphatic systems
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Lesson notes of climatology university.
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Ad

Algorithms for c nit jamshedpur first year

  • 1. CS1101 Introduction toComputer Programming and Data Structures Dr. B Ramachandra Reddy
  • 2. Outline • Algorithm • Flow Charts • Pseudo Code
  • 3. Program Planning  To write a correct program, a programmer must write each and every instruction in the correct sequence  Logic (instruction sequence) of a program can be very complex  Hence, programs must be planned before they are written to ensure program instructions are:  Appropriate for the problem  In the correct sequence
  • 4. Algorithm  Refers to the logic of a program and a step-by-step description of how to arrive at the solution of a given problem.  In order to qualify as an algorithm, a sequence of instructions must have following characteristics:  Each and every instruction should be precise and unambiguous  Each instruction should be such that it can be performed in a finite time  One or more instructions should not be repeated infinitely. This ensures that the algorithm will ultimately terminate  After performing the instructions, that is after the algorithm terminates, the desired results must be obtained
  • 5. SampleAlgorithm (Example 1) • There are 50 students in a class who appeared in their final examination. Their mark sheets have been given to you. • The division column of the mark sheet contains the division (FIRST, SECOND, THIRD or FAIL) obtained by the student. • Write an algorithm to calculate and print the total number of students who passed in FIRST division.
  • 6. SampleAlgorithm (Example 1) Step 1: Initialize Total_First_Division and Total_Marksheets_Checked to zero. Step 2: Take the mark sheet of the next student. Step 3: Check the division column of the mark sheet to see if it is FIRST, if no, go to Step 5. Step 4: Add 1 to Total_First_Division. Step 5: Add 1 to Total_Marksheets_Checked. Step 6: Is Total_Marksheets_Checked = 50, if no, go to Step 2. Step 7: Print Total_First_Division. Step 8: Stop.
  • 7. Representation ofAlgorithms  As flowcharts  As pseudocodes
  • 8. Flowchart  Flowchart is a pictorial representation of an algorithm  Uses symbols (boxes of different shapes) that have standardized meanings to denote different types of instructions  Actual instructions are written within the boxes  Boxes are connected by solid lines having arrow marks to indicate the exact sequence in which the instructions are to be executed  Process of drawing a flowchart for an algorithm is called flowcharting
  • 10. Examples of Decision Symbol Is I = 10? No Yes (a) A two-way branch decision. (b) A three-way branch decision. A > B A = B A < B Compare A & B
  • 11. Examples of Decision Symbol I = ? (c) A multiple-way branch decision. = 0 = 1 = 2 = 3 = 4 = 5 = Other
  • 14. Pseudocode  A program planning tool where program logic is written in an ordinary natural language using a structure that resembles computer instructions  “ Pseudo” means imitation or false and “ Code” refers to the instructions written in a programming language. Hence, pseudocode is an imitation of actual computer instructions  Because it emphasizes the design of the program, pseudocode is also called Program Design Language (PDL)
  • 15. Basic Logic (Control) Structures • Any program logic can be expressed by using only following three simple logic structures: 1. Sequence logic, 2. Selection logic, and 3. Iteration (or looping) logic • Programs structured by using only these three logic structures are called structured programs, and the technique of writing such programs is known as structured programming
  • 16. Pseudocode • read/get – indicates a user will be inputting something • display/print/show – indicates that an output will appear on the screen • SET, INIT: To initialize values • Expressions • ←Assignment (like = inC) • = Equality testing (like = = inC) • n2 superscripts and other mathematical formatting allowed • Method call • var.method (arg [, arg…]) • Return value • return expression
  • 17. SequenceLogic Process 1 (b) Pseudocode Process 2 Process 1 Process 2 (a) Flowchart
  • 18. Selection Logic • Also known as decision logic, it is used for making decisions • Three popularly used selection logic structures are 1. IF…THEN…ELSE 2. IF…THEN 3. CASE
  • 19. Selection Logic (IF…THEN…ELSE Structure) THEN ELSE Process 1 Process 2 IF Condition ENDIF (b) Pseudocode THEN Process 1 ELSE Process 2 Yes No (a) Flowchart IF (condition)
  • 20. Selection Logic (IF…THEN Structure) (b) Pseudocode THEN ENDIF IF Condition Process 1 THEN Process 1 Yes No (a) Flowchart IF (condition)
  • 21. Selection Logic (CASE Structure) (b) Pseudocode CASE Type Case Type 1: Case Type 2: Process 1 Process 2 ENDCASE Case Type n: Process n Type 1 Type n Process 2 Process 1 Process n Yes Yes Yes No Type 2 No No (a) Flowchart
  • 22. Iteration (or Looping) Logic  Used to produce loops in program logic when one or more instructions may be executed several times depending on some conditions  Two popularly used iteration logic structures are 1. DO…WHILE 2. REPEAT…UNTIL
  • 23. Iteration (or Looping) Logic (DO…WHILE Structure) (b) Pseudocode DO WHILE Condition Process 1 Process n ENDDO Process 1 False (a) Flowchart Process n True Condition? Block
  • 24. Iteration (or Looping) Logic (REPEAT…UNTIL Structure) (b) Pseudocode REPEAT Process 1 Process n UNTIL Condition Process 1 Process n True (a) Flowchart False Condition?
  • 28. Flowchart Pseudocode Start/End Begin/End Input/output Read: read x,y Print: Print y Process Computation: X<-y+6 Decision If/if-lse/case/while/ do-while/for Connector Not Applicable Predefined Process Not Applicable FlowchartVs Pseudo code
  • 29. FlowchartVs Pseudo code • Flowchart Advantages • Standard • Visual • Flowchart Disadvantages • Hard to modify • Structured design elements not implemented • Special software required • Pseudocode Advantages • Easily modified • Implements structured concepts • Done easy on Word Processor • Pseudocode Disadvantages • Not Visual • Not accepted standard, varies from company to company
  • 30. Assignments • Write a pseudo code and flowchart to find the given number is prime or not? • Write a pseudo code and flowchart to generate the Fibonacci series upto n numbers. • Write a pseudo code and flowchart to check the given number is palindrome or not?