SlideShare a Scribd company logo
1 of 23
Lecture 2 Introduction 
1 
Analysis of Algorithms 
Spring 2008 
Introduction 
Lec-1 
Prepared by 
Dr. Zahoor Jan 
Department of Computer Science, University of Peshawar 
11-02-08
Lecture 2 Introduction 
Yahoo group 
• Group name: Algo_UOP_Spring08 Group home 
• page: http://groups.yahoo.com/group/Algo_UOP_Spring08 
• Group email: Algo_UOP_Spring08@yahoogroups.com 
2 
11-02-08
3 
Analysis of Algo 
Steps involved in writing aa ccoommppuutteerr pprrooggrraamm:: 
• Problem formulation & specification 
• Design of solution 
• Implementation 
• Testing 
• Documentation 
• Evaluation of the solution 
11-02-08
Problem formulation && ssppeecciiffiiccaattiioonn 
• Half the battle is knowing what problem to solve. 
• Most problems have no simple precise specification. 
• Some problems are impossible to formulate. 
• Example: Gourmet recipe, World peace, Etc. 
4 
Analysis of Algo 
11-02-08
How to formulate && ssppeecciiffyy aa pprroobblleemm?? 
• Identify the problem parameters. 
• Expressing the problem by a formal model. 
• Looking for a solution for the model. 
• In the absence of a solution, discover about the model. 
5 
Analysis of Algo 
11-02-08
How ttoo mmooddeell aanndd ssoollvvee aa pprroobblleemm?? 
• Using any branch of Mathematics or Science. 
• Identifying problems of numerical nature. 
• With a suitable model, attempt to find a solution in terms of that 
model 
• Simultaneous linear equations for electrical circuits. 
• Differential equations for predicting chemical reaction rates. 
6 
Analysis of Algo 
11-02-08
7 
Analysis of Algo 
AAllggoorriitthhmm 
• Finite sequence of instructions. 
• Each instruction having a clear meaning. 
• Each instruction requiring finite amount of effort. 
• Each instruction requiring finite time to complete. 
11-02-08
AAllggoorriitthhmm 
• Finite sequence of instructions. 
An input should not take the program in an infinite loop 
• Each instruction having a clear meaning. 
Very subjective. What is clear to me, may not be clear to you. 
• Each instruction requiring finite amount of effort. 
Very subjective. Finite on a super computer or a P4? 
• Each instruction requiring finite time to complete. 
Very subjective. 1 min, 1 hr, 1 year or a lifetime? 
8 
Analysis of Algo 
11-02-08
Algorithm Definition 
A finite set of statements that guarantees an 
optimal solution in finite interval of time 
9 
Analysis of Algo 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
GIVEN: A complex intersection. 
OBJECTIVE: Traffic light with minimum phases. 
SOLUTION: 
• Identify permitted turns, going straight is a “turn”. 
• Make group of permitted turns. 
• Make the smallest possible number of groups. 
• Assign each phase of the traffic light to a group. 
10 
Analysis of Algo 
11-02-08
Analysis of Algo 
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
11 
A 
C 
B 
D 
E 
An intersection 
Charsadda 
Roads C and E are one way, others are two way. 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
There are 13 permitted turns. 
Some turns such as AB (from A to B) and AC can be 
carried out simultaneously. 
Other like AD and EB cross each other and can not 
be carried out simultaneously. 
The traffic light should permit AB and EC 
simultaneously, but should not allow AD and EB. 
12 
Analysis of Algo 
11-02-08
Analysis of Algo 
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
13 
A 
C 
B 
D 
E 
An intersection 
AB & AC 
AD & EB 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
SOLUTION: 
• We model the problem using a structure called graph 
G(V,E). 
• A graph consists of a set of points called vertices V, 
and lines connecting the points, called edges E. 
•Drawing a graph such that the vertices represent turns. 
• Edges between those turns that can NOT be 
performed simultaneously. 
14 
Analysis of Algo 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
15 
AD 
A 
C 
B 
D 
E 
An intersection 
BD 
AB AC 
BA BC 
DA DB DC 
EA EB 
EC ED 
Partial graph of incompatible turns 
Analysis of Algo 
11-02-08
Analysis of Algo 
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
16 
Partial table of incompatible turns 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
SOLUTION: 
The graph can aid in solving our problem. 
A coloring of a graph is an assignment of a color to 
each vertex of the graph, so that no two vertices 
connected by an edge have the same color. 
Our problem is of coloring the graph of incompatible 
turns using as few colors as possible. 
17 
Analysis of Algo 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
More on SOLUTION (Graph coloring): 
Graph coloring problem has been studied for decades. 
The theory of algorithms tells us a lot about it. 
Unfortunately this belongs to a class of problems called 
as NP-Complete problems. 
For such problems, all known solutions are basically “try 
all possibilities” 
In case of coloring, try all assignments of colors. 
18 
Analysis of Algo 
11-02-08
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
Approaches to attempting NP-Complete problems: 
1. If the problem is small, might attempt to find an 
optimal solution exhaustively. 
2. Look for additional information about the problem. 
3.Change the problem a little, and look for a good, but 
not necessarily optimal solution. 
An algorithm that quickly produces good but not 
necessarily optimal solutions is called a heuristic. 
19 
Analysis of Algo 
11-02-08
20 
Analysis of Algo 
11-02-08
Using model to solve complicated ttrraaffffiicc lliigghhtt pprroobblleemm 
A reasonable heuristic for graph coloring is the 
greedy “algorithm”. 
Try to color as many vertices as possible with the first 
color, and then as many uncolored vertices with the 
second color, and so on. 
The approach would be: 
1. Select some uncolored vertex, and color with new color. 
2. Scan the list of uncolored vertices. 
3. For each uncolored vertex, determine whether it has an 
edge to any vertex already colored with the new color. 
4. If there is no such edge, color the present vertices with the 
new color. 11-02-08 
21
UUssiinngg mmooddeell ttoo ssoollvvee ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm 
This is called “greedy”, because it colors a vertex, 
whenever it can, without considering potential 
drawbacks. 
22 
1 5 
3 
4 
22 
1 5 
3 
4 
2 
Three colors used 
Two colors used 
((ooppttiimmuumm)) 
11-02-08
Analysis of Algo 
Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc 
lliigghhtt pprroobblleemm 
Work SMART 
23 
not 
HARD  
11-02-08

More Related Content

Similar to Analysis of Algorithms Lecture Introduction

Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Wei Lu
 
EGRE 310 RAMEYJM Final Project Writeup
EGRE 310 RAMEYJM Final Project WriteupEGRE 310 RAMEYJM Final Project Writeup
EGRE 310 RAMEYJM Final Project WriteupJacob Ramey
 
Proyecto tecnologia, Construyendo nuestro puente levadizo
Proyecto tecnologia, Construyendo nuestro puente levadizoProyecto tecnologia, Construyendo nuestro puente levadizo
Proyecto tecnologia, Construyendo nuestro puente levadizoFran Martin Morer
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxsatvikkushwaha1
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
L3-.pptx
L3-.pptxL3-.pptx
L3-.pptxasdq4
 
LCE-UNIT 2 PPT.pdf
LCE-UNIT 2 PPT.pdfLCE-UNIT 2 PPT.pdf
LCE-UNIT 2 PPT.pdfHODECE21
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsAsen Bozhilov
 
QA CHAPTER II.pptx
QA CHAPTER II.pptxQA CHAPTER II.pptx
QA CHAPTER II.pptxTeshome48
 
Pe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwardsPe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwardsCharlton Inao
 
EE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotEE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotPraneel Chand
 
Mit15 082 jf10_lec01
Mit15 082 jf10_lec01Mit15 082 jf10_lec01
Mit15 082 jf10_lec01Saad Liaqat
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptxSayanSen36
 
Linear programming models - U2.pptx
Linear programming models - U2.pptxLinear programming models - U2.pptx
Linear programming models - U2.pptxMariaBurgos55
 
EMERSON EDUARDO RODRIGUES Optimization and lp
EMERSON EDUARDO RODRIGUES Optimization and lpEMERSON EDUARDO RODRIGUES Optimization and lp
EMERSON EDUARDO RODRIGUES Optimization and lpEMERSON EDUARDO RODRIGUES
 

Similar to Analysis of Algorithms Lecture Introduction (20)

Advance analysis of algo
Advance analysis of algoAdvance analysis of algo
Advance analysis of algo
 
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
 
EGRE 310 RAMEYJM Final Project Writeup
EGRE 310 RAMEYJM Final Project WriteupEGRE 310 RAMEYJM Final Project Writeup
EGRE 310 RAMEYJM Final Project Writeup
 
Proyecto tecnologia, Construyendo nuestro puente levadizo
Proyecto tecnologia, Construyendo nuestro puente levadizoProyecto tecnologia, Construyendo nuestro puente levadizo
Proyecto tecnologia, Construyendo nuestro puente levadizo
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
L3-.pptx
L3-.pptxL3-.pptx
L3-.pptx
 
LCE-UNIT 2 PPT.pdf
LCE-UNIT 2 PPT.pdfLCE-UNIT 2 PPT.pdf
LCE-UNIT 2 PPT.pdf
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
QA CHAPTER II.pptx
QA CHAPTER II.pptxQA CHAPTER II.pptx
QA CHAPTER II.pptx
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
 
Pe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwardsPe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwards
 
EE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotEE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robot
 
Mit15 082 jf10_lec01
Mit15 082 jf10_lec01Mit15 082 jf10_lec01
Mit15 082 jf10_lec01
 
IASTED.Presentation_05_09_06
IASTED.Presentation_05_09_06IASTED.Presentation_05_09_06
IASTED.Presentation_05_09_06
 
Cs2251 daa
Cs2251 daaCs2251 daa
Cs2251 daa
 
LP.ppt
LP.pptLP.ppt
LP.ppt
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptx
 
Linear programming models - U2.pptx
Linear programming models - U2.pptxLinear programming models - U2.pptx
Linear programming models - U2.pptx
 
EMERSON EDUARDO RODRIGUES Optimization and lp
EMERSON EDUARDO RODRIGUES Optimization and lpEMERSON EDUARDO RODRIGUES Optimization and lp
EMERSON EDUARDO RODRIGUES Optimization and lp
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Analysis of Algorithms Lecture Introduction

  • 1. Lecture 2 Introduction 1 Analysis of Algorithms Spring 2008 Introduction Lec-1 Prepared by Dr. Zahoor Jan Department of Computer Science, University of Peshawar 11-02-08
  • 2. Lecture 2 Introduction Yahoo group • Group name: Algo_UOP_Spring08 Group home • page: http://groups.yahoo.com/group/Algo_UOP_Spring08 • Group email: Algo_UOP_Spring08@yahoogroups.com 2 11-02-08
  • 3. 3 Analysis of Algo Steps involved in writing aa ccoommppuutteerr pprrooggrraamm:: • Problem formulation & specification • Design of solution • Implementation • Testing • Documentation • Evaluation of the solution 11-02-08
  • 4. Problem formulation && ssppeecciiffiiccaattiioonn • Half the battle is knowing what problem to solve. • Most problems have no simple precise specification. • Some problems are impossible to formulate. • Example: Gourmet recipe, World peace, Etc. 4 Analysis of Algo 11-02-08
  • 5. How to formulate && ssppeecciiffyy aa pprroobblleemm?? • Identify the problem parameters. • Expressing the problem by a formal model. • Looking for a solution for the model. • In the absence of a solution, discover about the model. 5 Analysis of Algo 11-02-08
  • 6. How ttoo mmooddeell aanndd ssoollvvee aa pprroobblleemm?? • Using any branch of Mathematics or Science. • Identifying problems of numerical nature. • With a suitable model, attempt to find a solution in terms of that model • Simultaneous linear equations for electrical circuits. • Differential equations for predicting chemical reaction rates. 6 Analysis of Algo 11-02-08
  • 7. 7 Analysis of Algo AAllggoorriitthhmm • Finite sequence of instructions. • Each instruction having a clear meaning. • Each instruction requiring finite amount of effort. • Each instruction requiring finite time to complete. 11-02-08
  • 8. AAllggoorriitthhmm • Finite sequence of instructions. An input should not take the program in an infinite loop • Each instruction having a clear meaning. Very subjective. What is clear to me, may not be clear to you. • Each instruction requiring finite amount of effort. Very subjective. Finite on a super computer or a P4? • Each instruction requiring finite time to complete. Very subjective. 1 min, 1 hr, 1 year or a lifetime? 8 Analysis of Algo 11-02-08
  • 9. Algorithm Definition A finite set of statements that guarantees an optimal solution in finite interval of time 9 Analysis of Algo 11-02-08
  • 10. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm GIVEN: A complex intersection. OBJECTIVE: Traffic light with minimum phases. SOLUTION: • Identify permitted turns, going straight is a “turn”. • Make group of permitted turns. • Make the smallest possible number of groups. • Assign each phase of the traffic light to a group. 10 Analysis of Algo 11-02-08
  • 11. Analysis of Algo Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm 11 A C B D E An intersection Charsadda Roads C and E are one way, others are two way. 11-02-08
  • 12. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm There are 13 permitted turns. Some turns such as AB (from A to B) and AC can be carried out simultaneously. Other like AD and EB cross each other and can not be carried out simultaneously. The traffic light should permit AB and EC simultaneously, but should not allow AD and EB. 12 Analysis of Algo 11-02-08
  • 13. Analysis of Algo Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm 13 A C B D E An intersection AB & AC AD & EB 11-02-08
  • 14. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm SOLUTION: • We model the problem using a structure called graph G(V,E). • A graph consists of a set of points called vertices V, and lines connecting the points, called edges E. •Drawing a graph such that the vertices represent turns. • Edges between those turns that can NOT be performed simultaneously. 14 Analysis of Algo 11-02-08
  • 15. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm 15 AD A C B D E An intersection BD AB AC BA BC DA DB DC EA EB EC ED Partial graph of incompatible turns Analysis of Algo 11-02-08
  • 16. Analysis of Algo Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm 16 Partial table of incompatible turns 11-02-08
  • 17. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm SOLUTION: The graph can aid in solving our problem. A coloring of a graph is an assignment of a color to each vertex of the graph, so that no two vertices connected by an edge have the same color. Our problem is of coloring the graph of incompatible turns using as few colors as possible. 17 Analysis of Algo 11-02-08
  • 18. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm More on SOLUTION (Graph coloring): Graph coloring problem has been studied for decades. The theory of algorithms tells us a lot about it. Unfortunately this belongs to a class of problems called as NP-Complete problems. For such problems, all known solutions are basically “try all possibilities” In case of coloring, try all assignments of colors. 18 Analysis of Algo 11-02-08
  • 19. Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm Approaches to attempting NP-Complete problems: 1. If the problem is small, might attempt to find an optimal solution exhaustively. 2. Look for additional information about the problem. 3.Change the problem a little, and look for a good, but not necessarily optimal solution. An algorithm that quickly produces good but not necessarily optimal solutions is called a heuristic. 19 Analysis of Algo 11-02-08
  • 20. 20 Analysis of Algo 11-02-08
  • 21. Using model to solve complicated ttrraaffffiicc lliigghhtt pprroobblleemm A reasonable heuristic for graph coloring is the greedy “algorithm”. Try to color as many vertices as possible with the first color, and then as many uncolored vertices with the second color, and so on. The approach would be: 1. Select some uncolored vertex, and color with new color. 2. Scan the list of uncolored vertices. 3. For each uncolored vertex, determine whether it has an edge to any vertex already colored with the new color. 4. If there is no such edge, color the present vertices with the new color. 11-02-08 21
  • 22. UUssiinngg mmooddeell ttoo ssoollvvee ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm This is called “greedy”, because it colors a vertex, whenever it can, without considering potential drawbacks. 22 1 5 3 4 22 1 5 3 4 2 Three colors used Two colors used ((ooppttiimmuumm)) 11-02-08
  • 23. Analysis of Algo Using a mmooddeell ttoo ssoollvvee aa ccoommpplliiccaatteedd ttrraaffffiicc lliigghhtt pprroobblleemm Work SMART 23 not HARD  11-02-08