SlideShare ist ein Scribd-Unternehmen logo
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.

Weitere ähnliche Inhalte

Ähnlich wie 02 Algorithms and flowcharts - computers.pptx

Unit 1 psp
Unit 1 pspUnit 1 psp
Unit 1 psp
Karthi Vel
 
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
TeddyDaka
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Sangheethaa Sukumaran
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
Md. Rakibuzzaman Khan Pathan
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu 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
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
Faiza Gull
 
algorithm
algorithmalgorithm
algorithm
kokilabe
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
Chaya64047
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
NenavathSurendhar
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
baabtra.com - No. 1 supplier of quality freshers
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
TAlha MAlik
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
miansaad18
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
PmarkNorcio
 
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
ssuser586772
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
Bom Khati
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures
jabirMemon
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 

Kürzlich hochgeladen (20)

Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 

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.