SlideShare a Scribd company logo
1 of 29
CE-128T COMPUTING FUNDAMENTALS
ALGORITHMS
Computer Programming
What is Computer Programming?
Computer programming is a way of giving computers instructions about
what they should do next. These instructions are known as code, and
computer programmers write code to solve problems or perform a task.
ALGORITHM
S
WHAT IS AN ALGORITHM?
• An algorithm is a set of instructions designed to perform a specific
task.
• An algorithm is a step by step procedure to solve logical and
mathematical problems.
• A recipe is a good example of an algorithm because it says what must be
done, step by step. It takes inputs (ingredients) and produces an output
(the completed dish).
WHAT IS AN ALGORITHM?
ALGORITHM
S
WHAT IS AN ALGORITHM?
• Example: Given 𝑚 ≥ 1 and two positive numbers each containing 𝑚
digits, 𝑎𝑚−1𝑎𝑚−2 ⋯ 𝑎0 and 𝑏𝑚−1𝑏𝑚−2 ⋯ 𝑏0, add the two numbers.
ALGORITHMS WHAT IS AN ALGORITHM?
ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 4
Step 1: Set the value of 𝑐𝑎𝑟𝑟𝑦 to 0
Step 2: Set the value of 𝑖 to 0
Step 3: While the value of 𝑖 is less than or equal to 𝑚 − 1, repeat the instructions
in Steps 4 through 6
Step 4: Add the two digits 𝑎𝑖 and 𝑏𝑖 to the current value of 𝑐𝑎𝑟𝑟𝑦 to get 𝑐𝑖
Step 5: If 𝑐𝑖 ≥ 10, then reset 𝑐𝑗 to (𝑐𝑗 − 10) and reset the value of 𝑐𝑎𝑟𝑟𝑦 to 1;
otherwise, set the new value of 𝑐𝑎𝑟𝑟𝑦 to 0
Step 6: Add 1 to 𝑖, effectively moving one column to the left
Step 7: Set 𝑐𝑚 to the value of 𝑐𝑎𝑟𝑟𝑦
Step 8: Print out the final answer, 𝑐𝑚𝑐𝑚−1𝑐𝑚−2 ⋯ 𝑐0
Step 9: Stop
GENERAL FORM OF ALGORITHMS
• Algorithms are all around us!
ALGORITHMS GENERAL FORM OF ALGORITHMS
Step 1: Do something
Step 2: Do something
Step 3: Do something
⋮ ⋮
⋮ ⋮
Step N: Stop, you’re finished.
EXAMPLE
The algorithm from the back of a shampoo bottle.
• Is this a good algorithm?
• No!
• When to stop? Ambiguity!
ALGORITHMS EXAMPLE
Step 1: Wet hair
Step 2: Lather
Step 3: Rinse
Step 4: Repeat
EXAMPLE
An improved version of the shampoo bottle algorithm.
• One possible solution.
ALGORITHMS EXAMPLE
Step 1: Wet your hair
Step 2: Lather your hair
Step 3: Rinse your hair
Step 4: Lather your hair
Step 5: Rinse your hair
Step 6: Stop, you have finished shampooing your hair.
EXAMPLE
The algorithm to make a pie.
• Is this a good algorithm?
• No!
• How to make the crust? Ambiguity! Not primitives.
• What to do after Step 4?
ALGORITHMS EXAMPLE
Step 1: Make the crust
Step 2: Make the cherry filling
Step 3: Pour the filling into the crust
Step 4: Bake at 350 F for 45 minutes
EXAMPLE
The algorithm to display the 100th prime number.
• Is this a good algorithm?
• No!
• Not doable! The list of prime numbers is unending.
ALGORITHMS EXAMPLE
Step 1: Generate a list 𝐿 of all the prime numbers: 𝐿1, 𝐿2, 𝐿3, 𝐿4, ⋯
Step 2: Sort the list 𝐿 into ascending order.
Step 3: Print the 100th element in the list, 𝐿100
Step 4: Stop
PSEUDOCODE
• English-language constructs designed to resemble statements in
programming but do not actually run on a computer.
• Pseudo – Not real, not genuine, pretended.
• Notation resembling simplified programming language.
• Not actually a programming language but pretending to be a programming
language.
• Simple, highly readable, and has virtually no grammatical rules.
• Sometimes jokingly referred to as “a programming language without the
details.”
• Informal design notation used to solely express algorithms.
ALGORITHMS PSEUDOCODE
• Natural language is in the form of paragraphs and may lead to
ambiguities.
• High-level language is code which is difficult for even programmers to
understand.
• Pseudocode offers a compromise between the two.
• Not a formal language with rigidly standard syntactic and semantic
rules and regulations.
• Benefits
• Makes it easy to visualize the algorithm.
• Allows easy translation of the algorithm into high-level language because of
closeness in resemblance to such languages.
ALGORITHMS TYPES OF OPERATIONS
CS1210 – INTRODUCTION TO COMPUTING 11
FLOWCHART
• The diagrammatic representation of an algorithm.
• A diagram that represents a workflow or process.
• A picture of the separate steps of a process in a sequential order.
• Flowcharts use rectangles, ovals, diamonds and potentially numerous
other shapes to define the type of step, along with connecting arrows
to define flow and sequence.
• Flowcharts can be used to
• Demonstrate the way code is organized.
• Visualize the execution of code within a program.
• Show the structure of a website or application.
• Understand how users navigate a website or program.
ALGORITHMS FLOWCHART
ALGORITHMS FLOWCHART
SYMBOL NAME FUNCTION
Start/End
An oval (or ellipse) represents the start and end points of a flowchart.
Start written within the shape indicates the starting point, and
End/Stop/Exit indicates the ending point of the flowchart.
Arrows
Arrows are used to represent the workflow path. They connect the
shapes in a flow chart to show the relationship between them and the
flow or sequence of the problem-solving process.
Input/
Output
A parallelogram is used to read data (input) or print data (output).
Process
A rectangle is used to show the processing that takes place in the
flowchart.
Decision
A diamond with two branches is used to show the decision-making
step in a flowchart. A Yes/No question is specified in the diamond and
the next step in the sequence is based on the answer to that question
along the arrow labeled “Yes” or “No”.
ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 13
• As with algorithms, the three basic operations (sequential,
conditional, and iterative) can be represented using flowcharts as
well.
ALGORITHMS FLOWCHART
ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 14
EXAMPLE
Find the sum of two numbers A and B
ALGORITHMS EXAMPLE
Start
↓
A = 845
↓
B = 247
SUM OF 845 AND 247 ↓
Sum = 845 + 247
↓
Sum = 1092
↓
End
EXAMPLE
Flowchart to calculate the profit and loss.
ALGORITHMS EXAMPLE
Start
↓
FINDING PROFIT
AND LOSS WHEN
COST PRICE IS
$325 AND SELLING
PRICE IS $458
CP = 325
SP = 458
↓
Is 458 > 325? → Profit = 458 - 325
↓
Profit = $133
↓
End
EXAMPLE
Portion of a flowchart
illustrating the discount applied
on movie tickets.
ALGORITHMS EXAMPLE
EXAMPLE
Portion of a flowchart for
discount applicable.
ALGORITHMS EXAMPLE
ITEMS
ORDERED
DISCOUNT
RATE (%)
0 to 10 0
11 to 24 10
25 to 50 15
51 or more 20
EXAMPLE
Flowchart to generate the
multiplication table of a number N
ALGORITHMS EXAMPLE
Start
N = 12
Count = 1
MULTIPLICATION
TABLE OF 12
12 × 1 = 12
Count = 1 + 1 = 2
12 × 2 = 24
Count = 2 + 1 = 3
⋮
Count = 9 + 1 = 10
12 × 10 = 120
Count = 10
End
Three Programming Constructs
Three Programming Constructs are:
• Sequence
• Selection
• Iteration
Three Programming Constructs
Computer Languages
• The programming language is the medium of communication
between human and computer systems. It is the set of
instructions written in a specific style (coding) to instruct the
computer to perform a specific task.
• Three types of Computer Languages
• The computer language is used to communicate with computers.
• Broadly the computer language can be classified into three
categories
• Low level orAssembly language, machine language, and
high-level language.
Computer Languages
Machine language
• Machine language or machine code is the native language directly
understood by the computer's central processing unit or CPU.
• This type of computer language is not easy to understand, as it only uses a
binary system, an element of notations containing only a series of numbers
consisting of one and zero, to produce commands.
Computer Languages
Assembly Level or Low-Level Language
• Assembly Level Language is a set of codes that can run directly on the
computer's processor.
• This type of language is most appropriate in writing operating systems
and maintaining desktop applications.
• It allows the programmer to perform several tasks like registry access,
memory management and clock cycle correspondence.
Computer Languages
High-level programming languages
• These are the machine-independent programming languages, which
are easy to write, read, edit, and understand.
• Languages like Java, .Net, Python, JavaScript, C++, C, C#, and others
(which are very popular now to develop user-end applications). These
languages come under the category of high-level programming
language.
Middle-level programming languages
Middle-level programming languages
• The programming languages which have features of Low Level as
well as High-Level programming languages known as "Middle Level"
programming language.
• C programming languages is the best example of Middle-Level
Programming languages as it has features of low level and high-level
programming languages both.
Relationship between HLP and MLP
• The High level program(HLP) is called the Source Program and the
Machine language Program translate(MLP) it into Object Program.
Compiler VS Interpreter
• A compiler takes entire program and converts it into object code which is
typically stored in a file. The object code is also refereed as binary code
and can be directly executed by the machine after linking. Examples of
compiled programming languages are C and C++.
• Interpreters convert code into machine code when the program is run.
Execute code line by line.
• An Interpreter directly executes instructions written in a programming or
scripting language without previously converting them to an object code
or machine code. Examples of interpreted languages are Perl, Python and
Matlab.
BASIS FOR COMPARISON COMPILER INTERPRETER
Input It takes an entire program at a time. It takes a single line of code or instruction
at a time.
Output It generates intermediate object code. It does not produce any intermediate object
code.
Working mechanism The compilation is done before execution. Compilation and execution take place
simultaneously.
Speed Comparatively faster Slower
Memory Memory requirement is more due to the
creation of object code.
It requires less memory as it does not
create intermediate object code.
Errors Display all errors after compilation, all at
the same time.
Displays error of each line one by one.
Error detection Difficult Easier comparatively
Pertaining Programming languages C, C++, C#, Scala, typescript uses
compiler.
PHP, Perl, Python, Ruby uses an
interpreter.

More Related Content

Similar to 02 Algorithms and flowcharts - computers.pptx

Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxTeddyDaka
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow chartsChinnu Edwin
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptxChaya64047
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_progTAlha MAlik
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptxmiansaad18
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptxssuser586772
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartBom Khati
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures jabirMemon
 

Similar to 02 Algorithms and flowcharts - computers.pptx (20)

Unit 1 psp
Unit 1 pspUnit 1 psp
Unit 1 psp
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
algorithm
algorithmalgorithm
algorithm
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures
 

Recently uploaded

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

02 Algorithms and flowcharts - computers.pptx

  • 2. Computer Programming What is Computer Programming? Computer programming is a way of giving computers instructions about what they should do next. These instructions are known as code, and computer programmers write code to solve problems or perform a task. ALGORITHM S WHAT IS AN ALGORITHM?
  • 3. • An algorithm is a set of instructions designed to perform a specific task. • An algorithm is a step by step procedure to solve logical and mathematical problems. • A recipe is a good example of an algorithm because it says what must be done, step by step. It takes inputs (ingredients) and produces an output (the completed dish). WHAT IS AN ALGORITHM? ALGORITHM S WHAT IS AN ALGORITHM?
  • 4. • Example: Given 𝑚 ≥ 1 and two positive numbers each containing 𝑚 digits, 𝑎𝑚−1𝑎𝑚−2 ⋯ 𝑎0 and 𝑏𝑚−1𝑏𝑚−2 ⋯ 𝑏0, add the two numbers. ALGORITHMS WHAT IS AN ALGORITHM? ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 4 Step 1: Set the value of 𝑐𝑎𝑟𝑟𝑦 to 0 Step 2: Set the value of 𝑖 to 0 Step 3: While the value of 𝑖 is less than or equal to 𝑚 − 1, repeat the instructions in Steps 4 through 6 Step 4: Add the two digits 𝑎𝑖 and 𝑏𝑖 to the current value of 𝑐𝑎𝑟𝑟𝑦 to get 𝑐𝑖 Step 5: If 𝑐𝑖 ≥ 10, then reset 𝑐𝑗 to (𝑐𝑗 − 10) and reset the value of 𝑐𝑎𝑟𝑟𝑦 to 1; otherwise, set the new value of 𝑐𝑎𝑟𝑟𝑦 to 0 Step 6: Add 1 to 𝑖, effectively moving one column to the left Step 7: Set 𝑐𝑚 to the value of 𝑐𝑎𝑟𝑟𝑦 Step 8: Print out the final answer, 𝑐𝑚𝑐𝑚−1𝑐𝑚−2 ⋯ 𝑐0 Step 9: Stop
  • 5. GENERAL FORM OF ALGORITHMS • Algorithms are all around us! ALGORITHMS GENERAL FORM OF ALGORITHMS Step 1: Do something Step 2: Do something Step 3: Do something ⋮ ⋮ ⋮ ⋮ Step N: Stop, you’re finished.
  • 6. EXAMPLE The algorithm from the back of a shampoo bottle. • Is this a good algorithm? • No! • When to stop? Ambiguity! ALGORITHMS EXAMPLE Step 1: Wet hair Step 2: Lather Step 3: Rinse Step 4: Repeat
  • 7. EXAMPLE An improved version of the shampoo bottle algorithm. • One possible solution. ALGORITHMS EXAMPLE Step 1: Wet your hair Step 2: Lather your hair Step 3: Rinse your hair Step 4: Lather your hair Step 5: Rinse your hair Step 6: Stop, you have finished shampooing your hair.
  • 8. EXAMPLE The algorithm to make a pie. • Is this a good algorithm? • No! • How to make the crust? Ambiguity! Not primitives. • What to do after Step 4? ALGORITHMS EXAMPLE Step 1: Make the crust Step 2: Make the cherry filling Step 3: Pour the filling into the crust Step 4: Bake at 350 F for 45 minutes
  • 9. EXAMPLE The algorithm to display the 100th prime number. • Is this a good algorithm? • No! • Not doable! The list of prime numbers is unending. ALGORITHMS EXAMPLE Step 1: Generate a list 𝐿 of all the prime numbers: 𝐿1, 𝐿2, 𝐿3, 𝐿4, ⋯ Step 2: Sort the list 𝐿 into ascending order. Step 3: Print the 100th element in the list, 𝐿100 Step 4: Stop
  • 10. PSEUDOCODE • English-language constructs designed to resemble statements in programming but do not actually run on a computer. • Pseudo – Not real, not genuine, pretended. • Notation resembling simplified programming language. • Not actually a programming language but pretending to be a programming language. • Simple, highly readable, and has virtually no grammatical rules. • Sometimes jokingly referred to as “a programming language without the details.” • Informal design notation used to solely express algorithms. ALGORITHMS PSEUDOCODE
  • 11. • Natural language is in the form of paragraphs and may lead to ambiguities. • High-level language is code which is difficult for even programmers to understand. • Pseudocode offers a compromise between the two. • Not a formal language with rigidly standard syntactic and semantic rules and regulations. • Benefits • Makes it easy to visualize the algorithm. • Allows easy translation of the algorithm into high-level language because of closeness in resemblance to such languages. ALGORITHMS TYPES OF OPERATIONS CS1210 – INTRODUCTION TO COMPUTING 11
  • 12. FLOWCHART • The diagrammatic representation of an algorithm. • A diagram that represents a workflow or process. • A picture of the separate steps of a process in a sequential order. • Flowcharts use rectangles, ovals, diamonds and potentially numerous other shapes to define the type of step, along with connecting arrows to define flow and sequence. • Flowcharts can be used to • Demonstrate the way code is organized. • Visualize the execution of code within a program. • Show the structure of a website or application. • Understand how users navigate a website or program. ALGORITHMS FLOWCHART
  • 13. ALGORITHMS FLOWCHART SYMBOL NAME FUNCTION Start/End An oval (or ellipse) represents the start and end points of a flowchart. Start written within the shape indicates the starting point, and End/Stop/Exit indicates the ending point of the flowchart. Arrows Arrows are used to represent the workflow path. They connect the shapes in a flow chart to show the relationship between them and the flow or sequence of the problem-solving process. Input/ Output A parallelogram is used to read data (input) or print data (output). Process A rectangle is used to show the processing that takes place in the flowchart. Decision A diamond with two branches is used to show the decision-making step in a flowchart. A Yes/No question is specified in the diamond and the next step in the sequence is based on the answer to that question along the arrow labeled “Yes” or “No”. ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 13
  • 14. • As with algorithms, the three basic operations (sequential, conditional, and iterative) can be represented using flowcharts as well. ALGORITHMS FLOWCHART ENGR. ARIFA QAZI CS1210 – INTRODUCTION TO COMPUTING 14
  • 15. EXAMPLE Find the sum of two numbers A and B ALGORITHMS EXAMPLE Start ↓ A = 845 ↓ B = 247 SUM OF 845 AND 247 ↓ Sum = 845 + 247 ↓ Sum = 1092 ↓ End
  • 16. EXAMPLE Flowchart to calculate the profit and loss. ALGORITHMS EXAMPLE Start ↓ FINDING PROFIT AND LOSS WHEN COST PRICE IS $325 AND SELLING PRICE IS $458 CP = 325 SP = 458 ↓ Is 458 > 325? → Profit = 458 - 325 ↓ Profit = $133 ↓ End
  • 17. EXAMPLE Portion of a flowchart illustrating the discount applied on movie tickets. ALGORITHMS EXAMPLE
  • 18. EXAMPLE Portion of a flowchart for discount applicable. ALGORITHMS EXAMPLE ITEMS ORDERED DISCOUNT RATE (%) 0 to 10 0 11 to 24 10 25 to 50 15 51 or more 20
  • 19. EXAMPLE Flowchart to generate the multiplication table of a number N ALGORITHMS EXAMPLE Start N = 12 Count = 1 MULTIPLICATION TABLE OF 12 12 × 1 = 12 Count = 1 + 1 = 2 12 × 2 = 24 Count = 2 + 1 = 3 ⋮ Count = 9 + 1 = 10 12 × 10 = 120 Count = 10 End
  • 20. Three Programming Constructs Three Programming Constructs are: • Sequence • Selection • Iteration
  • 22. Computer Languages • The programming language is the medium of communication between human and computer systems. It is the set of instructions written in a specific style (coding) to instruct the computer to perform a specific task. • Three types of Computer Languages • The computer language is used to communicate with computers. • Broadly the computer language can be classified into three categories • Low level orAssembly language, machine language, and high-level language.
  • 23. Computer Languages Machine language • Machine language or machine code is the native language directly understood by the computer's central processing unit or CPU. • This type of computer language is not easy to understand, as it only uses a binary system, an element of notations containing only a series of numbers consisting of one and zero, to produce commands.
  • 24. Computer Languages Assembly Level or Low-Level Language • Assembly Level Language is a set of codes that can run directly on the computer's processor. • This type of language is most appropriate in writing operating systems and maintaining desktop applications. • It allows the programmer to perform several tasks like registry access, memory management and clock cycle correspondence.
  • 25. Computer Languages High-level programming languages • These are the machine-independent programming languages, which are easy to write, read, edit, and understand. • Languages like Java, .Net, Python, JavaScript, C++, C, C#, and others (which are very popular now to develop user-end applications). These languages come under the category of high-level programming language.
  • 26. Middle-level programming languages Middle-level programming languages • The programming languages which have features of Low Level as well as High-Level programming languages known as "Middle Level" programming language. • C programming languages is the best example of Middle-Level Programming languages as it has features of low level and high-level programming languages both.
  • 27. Relationship between HLP and MLP • The High level program(HLP) is called the Source Program and the Machine language Program translate(MLP) it into Object Program.
  • 28. Compiler VS Interpreter • A compiler takes entire program and converts it into object code which is typically stored in a file. The object code is also refereed as binary code and can be directly executed by the machine after linking. Examples of compiled programming languages are C and C++. • Interpreters convert code into machine code when the program is run. Execute code line by line. • An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Examples of interpreted languages are Perl, Python and Matlab.
  • 29. BASIS FOR COMPARISON COMPILER INTERPRETER Input It takes an entire program at a time. It takes a single line of code or instruction at a time. Output It generates intermediate object code. It does not produce any intermediate object code. Working mechanism The compilation is done before execution. Compilation and execution take place simultaneously. Speed Comparatively faster Slower Memory Memory requirement is more due to the creation of object code. It requires less memory as it does not create intermediate object code. Errors Display all errors after compilation, all at the same time. Displays error of each line one by one. Error detection Difficult Easier comparatively Pertaining Programming languages C, C++, C#, Scala, typescript uses compiler. PHP, Perl, Python, Ruby uses an interpreter.