SlideShare a Scribd company logo
1 of 30
Balochistan University of I.T &
M.S
1
Lecture 6
Programming, Algorithm Design &
Development
CS106
Programming Methodology
& Abstractions
Spring 20023
Balochistan University
of I.T & M.S
Faculty of System Sciences
Sadique Ahmed Bugti
Balochistan University of I.T &
M.S
2
Programming
• Programming is a problem-solving activity.
• Programming is more than just writing code.
• Programming has a life cycle.
Balochistan University of I.T &
M.S
3
The Programming Life Cycle
1. Define the program requirements
2. Analyze the problem (specification)
3. Design an algorithm
4. Implement the algorithm (write code)
5. Compile and run the code
6. Test and debugging
Balochistan University of I.T &
M.S
4
So… what is the problem?
• Specifying the problem statement forces
you to state the problem clearly and
unambiguously in order to gain a clear
understanding of what is required for its
solution.
Balochistan University of I.T &
M.S
5
Analyzing the problem
• Analyzing the problem involves identifying
the problem inputs, outputs, and any
additional requirements or constraints
upon the solution.
• List the problem variables and their
relationships (expressed as formulas)
Balochistan University of I.T &
M.S
6
What is an Algorithm?
• Programs consist of algorithms.
• An algorithm is just a well-outlined method
for completing a task.
• This high-level abstraction is not actual
code. However, it does express the ideas
of a program, and is called pseudo-code.
Balochistan University of I.T &
M.S
7
Etymology?
• The term algorithm is derived from the name of
Abu Abdullah Allah Muhammed ben
Musa al- Khwarizmi (c.783--847),
a Persian mathematician.
– Founder of algebra (Al-jabr)
– It was translated as "Algorismus" in Latin
– Algorthmi de numero Indorum (Latin)
• Algorithms for computing with Hindu numerals, base-10
with 0.
• Derived the decimal system of numeration, using the so-
called “Arabic numerals”.
Balochistan University of I.T &
M.S
8
History of algorithms
Euclid, Greek Mathematician, 300BC
– The prototype of an algorithm
– An algorithm for computing the Greatest
Common Divisor of two numbers
– Archimedes (287-212BC) used the algorithm
in his work “The Measurement of a Circle”
– Earliest known attempt to formalize the
algorithmic process.
Balochistan University of I.T &
M.S
9
History of algorithms
• Rhind Papyrus (Egypt, 1650BC),
describes a “rule” for calculating the area
of a circle given its diameter
Balochistan University of I.T &
M.S
10
Designing an algorithm
• Don’t attempt to solve every detail of the
problem at the beginning.
• Use top-down design:
– Also known as stepwise-refinement, it
consists of repeatedly decomposing a
problem into smaller problems.
1. List the major steps, or sub-problems
2. Solve the original problem by solving
each of the sub-problems.
Balochistan University of I.T &
M.S
11
e.g. Area of a Circle
• An algorithm for calculating the area of a
circle:
area = p r2
could be as follows:
– Obtain the value of the radius of the circle
– Obtain the value of p
– Square the radius and multiply by p
Balochistan University of I.T &
M.S
12
Implementing the algorithm
• Write the algorithm as a C program
• Convert each algorithm step into one or
more statements in a programming
language.
Balochistan University of I.T &
M.S
13
e.g. Area of a Circle
#include <stdio.h>
#define PI 3.14159
void main(void)
{
double radius; /* radius of the circle, cm */
double area; /* area of the circle, cm^2 */
/* Get the radius of the circle */
printf(“Enter the radius in cm> “);
scanf(“%lf”, &radius);
/* Calculate the area of the circle */
area = PI * radius * radius;
/* Display the area */
printf(“The area is %f cm^2.n”, area);
getch();
}
Balochistan University of I.T &
M.S
14
An Example
• Requirements:
– Write a program to convert miles to kilometers.
• Analysis:
– Conversion from one system of measurement to
another.
– Convert distance measurements from miles to
kilometers (km).
– Input distance in miles
– Output distance in kilometres
– Need to know the relationship between miles and km.
• 1 miles equals 1.609km
Balochistan University of I.T &
M.S
15
An Example
• – List the three major steps of the algorithm:
 Get the distance in miles
 Convert the distance to kilometers
 Display the distance in kilometers
– Step needs some refinement
• The distance in kilometers is 1.609 times
the distance in miles.
Balochistan University of I.T &
M.S
16
Case Study: Implementation
#include <stdio.h>
#define KMS_PER_MILE 1.609
int main(void)
{
double miles; /* distance in miles */
double kms; /* distance in kilometres */
/* Get the distance in miles */
printf(“Enter the distance in miles> “);
scanf(“%lf”, &miles);
/* Convert the distance to kilometres */
kms = KMS_PER_MILE * miles;
/* Display the distance in kilometres */
printf(“That equals %lf kilometres.n”, kms);
}
Balochistan University of I.T &
M.S
17
Style
• A properly designed program is easy to
read and understand, and is esthetically
pleasing.
• Good coding style is essential to the art of
programming.
– Good style uses white spaces and comments.
Balochistan University of I.T &
M.S
18
Indentation
• Indentation is used to make programs easier
to understand.
– In C indent one level for each new block, or
conditional/loop statement.
– For example:
if (marks < 40)
{
printf(“Fail”);
}
The if statement is the outermost, the
statements inside the if are at the next level.
Balochistan University of I.T &
M.S
19
Clarity
• A program should be concise and easy to
read:
– Organize code into paragraphs
– Begin a paragraph with a topic-sentence
comment
Balochistan University of I.T &
M.S
20
Simplicity
• Your program should be simple. Some general
rules of thumb are:
– A single function should not be longer
than two or three pages.
– Avoid complex logic like multiple nested
ifs. The more complex your code, the
more indentation levels you will need.
– C statements should not go on forever!
If an equation is going to be longer than
one or two lines, split it into two shorter
equations.
Balochistan University of I.T &
M.S
21
An example of what not to do!
#include <stdio.h>
main(t,_,a)
char *a;
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_, main(-86, 0,
a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, +1, "%s %d %dn"
):9:16:t<0?t<-
72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%
+,/w#q#n+,/#{l,+,/n{n+ ,/+#n+,/#;#q#n+,/+k#;*+,/'r
:'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d
}rw' i;# ){n l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw'
iK{;[{nl]'/w#q# n'wk nw' iwk{KK{nl]!/w{%'l##w#' i;
:{nl]'/*{q#'ld;r'}{nlwb!/*de}'c  ;;{nl'-
{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+; #'rdq#w! nr'/ ')
}+}{rl#'{n' ')# }'+}##(!!/") :t<-50?_==*a
?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a
+1 ):0<t?main ( 2, 2 , "%s"):*a=='/'||main(0,main(-
61,*a, "!ek;dc 
i@bK'(q)-[w]*%n+r3#l,{}:nuwloca-O;m
Balochistan University of I.T &
M.S
22
Optimization
• Optimization is the art of going through a
program and making code more
efficient, so that it runs faster.
– using a more efficient algorithm
• A word on optimization don’t!
• Most programs do not need to be
optimized!
Balochistan University of I.T &
M.S
23
Program Aesthetics
• Rule: Use white space to break a function into
paragraphs.
• Code paragraphs
– A C program consists of statements, and
multiple statements on the same subject form a
conceptual block or “paragraph”.
– You can separate “paragraphs” in C using a
blank line.
– Statements are grouped together if they
belong together logically.
Balochistan University of I.T &
M.S
24
Program Aesthetics
• Rule: Put each statement on a line by itself
• There are aesthetic issues at the level of the
sentence; or in C, the statement.
– A statement expresses a single thought, idea, or
operation.
– Putting each statement on a line by itself makes
the statement stand out and reserves the use of
indentations for showing program structure.
Balochistan University of I.T &
M.S
25
Program Aesthetics
• For example:
x = 12; y = x * 2; z = PI * y
* y;
• is better expressed using the form:
x = 12;
y = x * 2;
z = PI * y * y;
Balochistan University of I.T &
M.S
26
Program Aesthetics
• Rule: Avoid very long statements. Use
multiple shorter statements instead.
– A clearly written C statement should not go on
forever. Complex statements can easily be
divided into smaller, more concise statements.
Balochistan University of I.T &
M.S
27
Program Aesthetics
• For example
m = 3*(12*(1- (lambda/ (2*(lambda+mu))))–1)*LOG(x)–(18* (1–
(lambda/(2*(lambda+mu))))–2);
is better expressed using the form:
v = (lambda/(2*(lambda+mu)));
alpha = (12*(1–v)–1);
beta = (18*(1–v)–2);
m = 3*alpha*LOG(x)–beta;
Balochistan University of I.T &
M.S
28
Program Aesthetics
• Rule: Write all programs in lowercase.
– Lowercase text is easier to understand.
– Uppercase letters can be used in special
circumstances, such as declaring constant
values.
Balochistan University of I.T &
M.S
29
Program Aesthetics
• Rule: Keep program files to no longer than
2000-3000 lines.
• Rule: Keep all lines in your program down
to 72 characters or fewer.
Balochistan University of I.T &
M.S
30
The End

More Related Content

Similar to Algorithm

CS8451 DAA Unit-I.pptx
CS8451 DAA Unit-I.pptxCS8451 DAA Unit-I.pptx
CS8451 DAA Unit-I.pptxBolliniNivas
 
1.01.Introduction.pptx
1.01.Introduction.pptx1.01.Introduction.pptx
1.01.Introduction.pptxBinish Raza
 
Numerical inflation: simulation of observational parameters
Numerical inflation: simulation of observational parametersNumerical inflation: simulation of observational parameters
Numerical inflation: simulation of observational parametersMilan Milošević
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.pptArumugam90
 
Control systems R18 course
Control systems R18 course Control systems R18 course
Control systems R18 course satyaSatyant234
 
Project management
Project managementProject management
Project managementsmumbahelp
 
Software testing - EXAMPLE
Software testing  - EXAMPLESoftware testing  - EXAMPLE
Software testing - EXAMPLEpriyasoundar
 
Design and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfDesign and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfHarshNagda5
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
K-12 Computer Science Framework GaDOE Update
K-12 Computer Science Framework GaDOE UpdateK-12 Computer Science Framework GaDOE Update
K-12 Computer Science Framework GaDOE UpdateTony Vlachakis
 
vtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdfvtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdfLPSChandana
 
Wireless Communications courses and research at COMNET
Wireless Communications courses and research at COMNET Wireless Communications courses and research at COMNET
Wireless Communications courses and research at COMNET ProjectENhANCE
 
(Final) Feedback and Control System.docx
(Final) Feedback and Control System.docx(Final) Feedback and Control System.docx
(Final) Feedback and Control System.docxRechieJohnRelator
 

Similar to Algorithm (20)

plc learn
plc learnplc learn
plc learn
 
CS8451 DAA Unit-I.pptx
CS8451 DAA Unit-I.pptxCS8451 DAA Unit-I.pptx
CS8451 DAA Unit-I.pptx
 
1.01.Introduction.pptx
1.01.Introduction.pptx1.01.Introduction.pptx
1.01.Introduction.pptx
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
 
Numerical inflation: simulation of observational parameters
Numerical inflation: simulation of observational parametersNumerical inflation: simulation of observational parameters
Numerical inflation: simulation of observational parameters
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
 
Control systems R18 course
Control systems R18 course Control systems R18 course
Control systems R18 course
 
Project management
Project managementProject management
Project management
 
CSE0105 Class 0.pdf
CSE0105 Class 0.pdfCSE0105 Class 0.pdf
CSE0105 Class 0.pdf
 
Software testing - EXAMPLE
Software testing  - EXAMPLESoftware testing  - EXAMPLE
Software testing - EXAMPLE
 
Design and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdfDesign and Analysis Algorithms.pdf
Design and Analysis Algorithms.pdf
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
Cyclomatic complexity
Cyclomatic complexityCyclomatic complexity
Cyclomatic complexity
 
K-12 Computer Science Framework GaDOE Update
K-12 Computer Science Framework GaDOE UpdateK-12 Computer Science Framework GaDOE Update
K-12 Computer Science Framework GaDOE Update
 
Cs 331 Data Structures
Cs 331 Data StructuresCs 331 Data Structures
Cs 331 Data Structures
 
vtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdfvtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdf
 
Wireless Communications courses and research at COMNET
Wireless Communications courses and research at COMNET Wireless Communications courses and research at COMNET
Wireless Communications courses and research at COMNET
 
(Final) Feedback and Control System.docx
(Final) Feedback and Control System.docx(Final) Feedback and Control System.docx
(Final) Feedback and Control System.docx
 

More from yarkhosh

Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If conditionyarkhosh
 
Arithmetic Operator in C
Arithmetic Operator in CArithmetic Operator in C
Arithmetic Operator in Cyarkhosh
 
Math Functions in C Scanf Printf
Math Functions in C Scanf PrintfMath Functions in C Scanf Printf
Math Functions in C Scanf Printfyarkhosh
 
Operators in C
Operators in COperators in C
Operators in Cyarkhosh
 
Data Types in C
Data Types in CData Types in C
Data Types in Cyarkhosh
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variablesyarkhosh
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programmingyarkhosh
 

More from yarkhosh (7)

Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If condition
 
Arithmetic Operator in C
Arithmetic Operator in CArithmetic Operator in C
Arithmetic Operator in C
 
Math Functions in C Scanf Printf
Math Functions in C Scanf PrintfMath Functions in C Scanf Printf
Math Functions in C Scanf Printf
 
Operators in C
Operators in COperators in C
Operators in C
 
Data Types in C
Data Types in CData Types in C
Data Types in C
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programming
 

Recently uploaded

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Algorithm

  • 1. Balochistan University of I.T & M.S 1 Lecture 6 Programming, Algorithm Design & Development CS106 Programming Methodology & Abstractions Spring 20023 Balochistan University of I.T & M.S Faculty of System Sciences Sadique Ahmed Bugti
  • 2. Balochistan University of I.T & M.S 2 Programming • Programming is a problem-solving activity. • Programming is more than just writing code. • Programming has a life cycle.
  • 3. Balochistan University of I.T & M.S 3 The Programming Life Cycle 1. Define the program requirements 2. Analyze the problem (specification) 3. Design an algorithm 4. Implement the algorithm (write code) 5. Compile and run the code 6. Test and debugging
  • 4. Balochistan University of I.T & M.S 4 So… what is the problem? • Specifying the problem statement forces you to state the problem clearly and unambiguously in order to gain a clear understanding of what is required for its solution.
  • 5. Balochistan University of I.T & M.S 5 Analyzing the problem • Analyzing the problem involves identifying the problem inputs, outputs, and any additional requirements or constraints upon the solution. • List the problem variables and their relationships (expressed as formulas)
  • 6. Balochistan University of I.T & M.S 6 What is an Algorithm? • Programs consist of algorithms. • An algorithm is just a well-outlined method for completing a task. • This high-level abstraction is not actual code. However, it does express the ideas of a program, and is called pseudo-code.
  • 7. Balochistan University of I.T & M.S 7 Etymology? • The term algorithm is derived from the name of Abu Abdullah Allah Muhammed ben Musa al- Khwarizmi (c.783--847), a Persian mathematician. – Founder of algebra (Al-jabr) – It was translated as "Algorismus" in Latin – Algorthmi de numero Indorum (Latin) • Algorithms for computing with Hindu numerals, base-10 with 0. • Derived the decimal system of numeration, using the so- called “Arabic numerals”.
  • 8. Balochistan University of I.T & M.S 8 History of algorithms Euclid, Greek Mathematician, 300BC – The prototype of an algorithm – An algorithm for computing the Greatest Common Divisor of two numbers – Archimedes (287-212BC) used the algorithm in his work “The Measurement of a Circle” – Earliest known attempt to formalize the algorithmic process.
  • 9. Balochistan University of I.T & M.S 9 History of algorithms • Rhind Papyrus (Egypt, 1650BC), describes a “rule” for calculating the area of a circle given its diameter
  • 10. Balochistan University of I.T & M.S 10 Designing an algorithm • Don’t attempt to solve every detail of the problem at the beginning. • Use top-down design: – Also known as stepwise-refinement, it consists of repeatedly decomposing a problem into smaller problems. 1. List the major steps, or sub-problems 2. Solve the original problem by solving each of the sub-problems.
  • 11. Balochistan University of I.T & M.S 11 e.g. Area of a Circle • An algorithm for calculating the area of a circle: area = p r2 could be as follows: – Obtain the value of the radius of the circle – Obtain the value of p – Square the radius and multiply by p
  • 12. Balochistan University of I.T & M.S 12 Implementing the algorithm • Write the algorithm as a C program • Convert each algorithm step into one or more statements in a programming language.
  • 13. Balochistan University of I.T & M.S 13 e.g. Area of a Circle #include <stdio.h> #define PI 3.14159 void main(void) { double radius; /* radius of the circle, cm */ double area; /* area of the circle, cm^2 */ /* Get the radius of the circle */ printf(“Enter the radius in cm> “); scanf(“%lf”, &radius); /* Calculate the area of the circle */ area = PI * radius * radius; /* Display the area */ printf(“The area is %f cm^2.n”, area); getch(); }
  • 14. Balochistan University of I.T & M.S 14 An Example • Requirements: – Write a program to convert miles to kilometers. • Analysis: – Conversion from one system of measurement to another. – Convert distance measurements from miles to kilometers (km). – Input distance in miles – Output distance in kilometres – Need to know the relationship between miles and km. • 1 miles equals 1.609km
  • 15. Balochistan University of I.T & M.S 15 An Example • – List the three major steps of the algorithm:  Get the distance in miles  Convert the distance to kilometers  Display the distance in kilometers – Step needs some refinement • The distance in kilometers is 1.609 times the distance in miles.
  • 16. Balochistan University of I.T & M.S 16 Case Study: Implementation #include <stdio.h> #define KMS_PER_MILE 1.609 int main(void) { double miles; /* distance in miles */ double kms; /* distance in kilometres */ /* Get the distance in miles */ printf(“Enter the distance in miles> “); scanf(“%lf”, &miles); /* Convert the distance to kilometres */ kms = KMS_PER_MILE * miles; /* Display the distance in kilometres */ printf(“That equals %lf kilometres.n”, kms); }
  • 17. Balochistan University of I.T & M.S 17 Style • A properly designed program is easy to read and understand, and is esthetically pleasing. • Good coding style is essential to the art of programming. – Good style uses white spaces and comments.
  • 18. Balochistan University of I.T & M.S 18 Indentation • Indentation is used to make programs easier to understand. – In C indent one level for each new block, or conditional/loop statement. – For example: if (marks < 40) { printf(“Fail”); } The if statement is the outermost, the statements inside the if are at the next level.
  • 19. Balochistan University of I.T & M.S 19 Clarity • A program should be concise and easy to read: – Organize code into paragraphs – Begin a paragraph with a topic-sentence comment
  • 20. Balochistan University of I.T & M.S 20 Simplicity • Your program should be simple. Some general rules of thumb are: – A single function should not be longer than two or three pages. – Avoid complex logic like multiple nested ifs. The more complex your code, the more indentation levels you will need. – C statements should not go on forever! If an equation is going to be longer than one or two lines, split it into two shorter equations.
  • 21. Balochistan University of I.T & M.S 21 An example of what not to do! #include <stdio.h> main(t,_,a) char *a; {return!0<t?t<3?main(-79,-13,a+main(-87,1-_, main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a )&&t == 2 ?_<13 ?main ( 2, +1, "%s %d %dn" ):9:16:t<0?t<- 72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{% +,/w#q#n+,/#{l,+,/n{n+ ,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/ +k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d }rw' i;# ){n l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q# n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'- {}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+; #'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/") :t<-50?_==*a ?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a +1 ):0<t?main ( 2, 2 , "%s"):*a=='/'||main(0,main(- 61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:nuwloca-O;m
  • 22. Balochistan University of I.T & M.S 22 Optimization • Optimization is the art of going through a program and making code more efficient, so that it runs faster. – using a more efficient algorithm • A word on optimization don’t! • Most programs do not need to be optimized!
  • 23. Balochistan University of I.T & M.S 23 Program Aesthetics • Rule: Use white space to break a function into paragraphs. • Code paragraphs – A C program consists of statements, and multiple statements on the same subject form a conceptual block or “paragraph”. – You can separate “paragraphs” in C using a blank line. – Statements are grouped together if they belong together logically.
  • 24. Balochistan University of I.T & M.S 24 Program Aesthetics • Rule: Put each statement on a line by itself • There are aesthetic issues at the level of the sentence; or in C, the statement. – A statement expresses a single thought, idea, or operation. – Putting each statement on a line by itself makes the statement stand out and reserves the use of indentations for showing program structure.
  • 25. Balochistan University of I.T & M.S 25 Program Aesthetics • For example: x = 12; y = x * 2; z = PI * y * y; • is better expressed using the form: x = 12; y = x * 2; z = PI * y * y;
  • 26. Balochistan University of I.T & M.S 26 Program Aesthetics • Rule: Avoid very long statements. Use multiple shorter statements instead. – A clearly written C statement should not go on forever. Complex statements can easily be divided into smaller, more concise statements.
  • 27. Balochistan University of I.T & M.S 27 Program Aesthetics • For example m = 3*(12*(1- (lambda/ (2*(lambda+mu))))–1)*LOG(x)–(18* (1– (lambda/(2*(lambda+mu))))–2); is better expressed using the form: v = (lambda/(2*(lambda+mu))); alpha = (12*(1–v)–1); beta = (18*(1–v)–2); m = 3*alpha*LOG(x)–beta;
  • 28. Balochistan University of I.T & M.S 28 Program Aesthetics • Rule: Write all programs in lowercase. – Lowercase text is easier to understand. – Uppercase letters can be used in special circumstances, such as declaring constant values.
  • 29. Balochistan University of I.T & M.S 29 Program Aesthetics • Rule: Keep program files to no longer than 2000-3000 lines. • Rule: Keep all lines in your program down to 72 characters or fewer.
  • 30. Balochistan University of I.T & M.S 30 The End