SlideShare a Scribd company logo
© 2020 Wael Badawy
1
Time Complexity
1
DISCLAIMER:
This video is optimized for HD large display using
patented and patent-pending “Nile Codec”, the first
Egyptian Video Codec for more information,
PLEASE check https://NileCodec.com
Also available as a PodCast
© 2020 Wael Badawy
Copyright © 2020 Wael Badawy. All rights reserved
n This video is subject to copyright owned by Wael Badawy “WB”. Any
reproduction or republication of all or part of this video is expressly prohibited
unless WB has explicitly granted its prior written consent. All other rights
reserved.
n This video is intended for education and information only and is offered AS IS,
without any warranty of the accuracy or the quality of the content. Any other
use is strictly prohibited. The viewer is fully responsible to verify the accuracy
of the contents received without any claims of costs or liability arising .
n The names, trademarks service marked as logos of WB or the sponsors
appearing in this video may not be used in any any product or service,
without prior express written permission from WB and the video sponsors
n Neither WB nor any party involved in creating, producing or delivering
information and material via this video shall be liable for any direction,
incidental, consequential, indirect of punitive damages arising out of access
to, use or inability to use this content or any errors or omissions in the
content thereof.
n If you will continue to watch this video, you agree to the terms above and
other terms that may be available on http://nu.edu.eg & https://caiwave.net
2
© 2020 Wael Badawy
© 2020 Wael Badawy
4
M
L
Consider a deterministic Turing Machine
which decides a language
© 2020 Wael Badawy
5
For any string the computation of
terminates in a finite amount of transitions
w M
!
Accept
or Reject w
Initial
state
© 2020 Wael Badawy
6
!
Accept
or Reject w
Decision Time = #transitions
Initial
state
© 2020 Wael Badawy
7
Consider now all strings of length n
)(nTM
= maximum time required to decide
any string of length n
© 2020 Wael Badawy
8
!
)(nTM
Max time to decide string of length n
1 2 3 4 n !
STRING LENGTH
TIME
© 2020 Wael Badawy
9
Time Complexity Class: ))(( nTTIME
All Languages decidable by a
deterministic Turing Machine
in time
1L 2L
3L
))(( nTO
© 2020 Wael Badawy
10
Example: }0:{1 ³= nbaL n
This can be decided in time)(nO
)(nTIME
}0:{1 ³= nbaL n
© 2020 Wael Badawy
11
)(nTIME
}0:{1 ³= nbaL n
}0,:{ ³knabaabn
}evenis:{ nbn
Other example problems in the same class
}3:{ knbn
=
© 2020 Wael Badawy
12
)( 2
nTIME
}0:{ ³nba nn
Examples in class:
}},{:{ bawww R
Î
}},{:{ bawww Î
© 2020 Wael Badawy
13
)( 3
nTIME
Examples in class:
}grammarfree-context
bygeneratedis:,{2
G
wwGL =
}and
matrices:,,{
321
3213
MMM
nnMMML
=´
´=
CYK algorithm
Matrix multiplication
© 2020 Wael Badawy
14
Polynomial time algorithms: )( k
nTIME
Represents tractable algorithms:
for small we can decide
the result fast
k
constant 0>k
© 2020 Wael Badawy
15
)( k
nTIME
)( 1+k
nTIME
)()( 1+
Ì kk
nTIMEnTIMEIt can be shown:
© 2020 Wael Badawy
16
!k
k
nTIMEP )(=
The Time Complexity Class P
•“tractable” problems
•polynomial time algorithms
Represents:
© 2020 Wael Badawy
17
P
CYK-algorithm
}{ nn
ba }{ww
Class
Matrix multiplication
}{ ban
© 2020 Wael Badawy
18
Exponential time algorithms: )2(
k
n
TIME
Represent intractable algorithms:
Some problem instances
may take centuries to solve
© 2020 Wael Badawy
19
Example: the Hamiltonian Path Problem
Question: is there a Hamiltonian path
from s to t?
s t
© 2020 Wael Badawy
20
s t
YES!
© 2020 Wael Badawy
21
)2()!(
k
n
TIMEnTIMEL »Î
Exponential time
Intractable problem
A solution: search exhaustively all paths
© 2020 Wael Badawy
22
The clique problem
Does there exist a clique of size k?
© 2020 Wael Badawy
23
The clique problem
Does there exist a clique of size k?
© 2020 Wael Badawy
24
Example: The Satisfiability Problem
Boolean expressions in
Conjunctive Normal Form:
ktttt ÙÙÙÙ !321
pi xxxxt ÚÚÚÚ= !321
Variables
Question: is the expression satisfiable?
clauses
© 2020 Wael Badawy
25
)()( 3121 xxxx ÚÙÚ
Satisfiable: 1,1,0 321 === xxx
1)()( 3121 =ÚÙÚ xxxx
Example:
© 2020 Wael Badawy
26
2121 )( xxxx ÙÙÚ
Not satisfiable
Example:
© 2020 Wael Badawy
27
e}satisfiablisexpression:{ wwL =
)2(
k
n
TIMEL Î
Algorithm:
search exhaustively all possible
binary values of the variables
exponential
© 2020 Wael Badawy
Non-Determinism
28
Language class: ))(( nTNTIME
A Non-Deterministic Turing Machine
decides each string of length
in time
1L
2L
3L
))(( nTO
n
29
0q
iq jq
…
…
…
…
accept
accept
reject
reject
)(nT
(deepest leaf)
depth
All computations
of on string w
nw =||
M
© 2020 Wael Badawy
30
Non-Deterministic Polynomial time algorithms:
)( k
nNTIMELÎ
© 2020 Wael Badawy
31
!k
k
nNTIMENP )(=
The class NP
Non-Deterministic Polynomial time
© 2020 Wael Badawy
32
Example: The satisfiability problem
Non-Deterministic algorithm:
•Guess an assignment of the variables
e}satisfiablisexpression:{ wwL =
•Check if this is a satisfying assignment
© 2020 Wael Badawy
33
Time for variables:n
)(nO
e}satisfiablisexpression:{ wwL =
Total time:
•Guess an assignment of the variables
•Check if this is a satisfying assignment )(nO
)(nO
© 2020 Wael Badawy
34
e}satisfiablisexpression:{ wwL =
NPLÎ
The satisfiability problem is a - ProblemNP
© 2020 Wael Badawy
35
Observation:
NPP Í
Deterministic
Polynomial
Non-Deterministic
Polynomial
© 2020 Wael Badawy
36
Open Problem: ?NPP =
WE DO NOT KNOW THE ANSWER
© 2020 Wael Badawy
37
Example: Does the Satisfiability problem
have a polynomial time
deterministic algorithm?
WE DO NOT KNOW THE ANSWER
Open Problem: ?NPP =

More Related Content

PDF
Universal turing
PDF
Regular pumping
PPTX
Np complete reductions
PDF
Regular expressions
PDF
Turing Machine
PPTX
N F A - Non Deterministic Finite Automata
PDF
Turing variations
PDF
Pda accept context free
Universal turing
Regular pumping
Np complete reductions
Regular expressions
Turing Machine
N F A - Non Deterministic Finite Automata
Turing variations
Pda accept context free

More from Wael Badawy (20)

PDF
HTML introduction
PPTX
Parsers -
PPTX
Computer Vision Cameras
PPTX
Computer Vision Gans
PPTX
Computer Vision image classification
PPTX
Computer Vision Structure from motion
PDF
Regular pumping examples
PDF
Regular properties
PDF
Pushdown Automota
PPTX
Computer Vision sfm
PPTX
Computer vision - photometric
PPTX
Computer vision - light
PPTX
Computer vision - two view geometry
PPTX
Computer Vision - Stereo Vision
PPTX
Computer Vision - Single View
PPTX
Computer Vision single view Modelling
PPTX
Computer Vision panoramas
PPTX
Computer Vision panoramas
PPTX
Computer Vision - cameras
PPTX
Computer Vision - RANSAC
HTML introduction
Parsers -
Computer Vision Cameras
Computer Vision Gans
Computer Vision image classification
Computer Vision Structure from motion
Regular pumping examples
Regular properties
Pushdown Automota
Computer Vision sfm
Computer vision - photometric
Computer vision - light
Computer vision - two view geometry
Computer Vision - Stereo Vision
Computer Vision - Single View
Computer Vision single view Modelling
Computer Vision panoramas
Computer Vision panoramas
Computer Vision - cameras
Computer Vision - RANSAC
Ad

Recently uploaded (20)

PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Classroom Observation Tools for Teachers
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
1_English_Language_Set_2.pdf probationary
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
advance database management system book.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Empowerment Technology for Senior High School Guide
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Classroom Observation Tools for Teachers
Digestion and Absorption of Carbohydrates, Proteina and Fats
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
Paper A Mock Exam 9_ Attempt review.pdf.
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
What if we spent less time fighting change, and more time building what’s rig...
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
1_English_Language_Set_2.pdf probationary
Final Presentation General Medicine 03-08-2024.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
advance database management system book.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Empowerment Technology for Senior High School Guide
Ad

Time complexity

  • 1. © 2020 Wael Badawy 1 Time Complexity 1 DISCLAIMER: This video is optimized for HD large display using patented and patent-pending “Nile Codec”, the first Egyptian Video Codec for more information, PLEASE check https://NileCodec.com Also available as a PodCast
  • 2. © 2020 Wael Badawy Copyright © 2020 Wael Badawy. All rights reserved n This video is subject to copyright owned by Wael Badawy “WB”. Any reproduction or republication of all or part of this video is expressly prohibited unless WB has explicitly granted its prior written consent. All other rights reserved. n This video is intended for education and information only and is offered AS IS, without any warranty of the accuracy or the quality of the content. Any other use is strictly prohibited. The viewer is fully responsible to verify the accuracy of the contents received without any claims of costs or liability arising . n The names, trademarks service marked as logos of WB or the sponsors appearing in this video may not be used in any any product or service, without prior express written permission from WB and the video sponsors n Neither WB nor any party involved in creating, producing or delivering information and material via this video shall be liable for any direction, incidental, consequential, indirect of punitive damages arising out of access to, use or inability to use this content or any errors or omissions in the content thereof. n If you will continue to watch this video, you agree to the terms above and other terms that may be available on http://nu.edu.eg & https://caiwave.net 2
  • 3. © 2020 Wael Badawy
  • 4. © 2020 Wael Badawy 4 M L Consider a deterministic Turing Machine which decides a language
  • 5. © 2020 Wael Badawy 5 For any string the computation of terminates in a finite amount of transitions w M ! Accept or Reject w Initial state
  • 6. © 2020 Wael Badawy 6 ! Accept or Reject w Decision Time = #transitions Initial state
  • 7. © 2020 Wael Badawy 7 Consider now all strings of length n )(nTM = maximum time required to decide any string of length n
  • 8. © 2020 Wael Badawy 8 ! )(nTM Max time to decide string of length n 1 2 3 4 n ! STRING LENGTH TIME
  • 9. © 2020 Wael Badawy 9 Time Complexity Class: ))(( nTTIME All Languages decidable by a deterministic Turing Machine in time 1L 2L 3L ))(( nTO
  • 10. © 2020 Wael Badawy 10 Example: }0:{1 ³= nbaL n This can be decided in time)(nO )(nTIME }0:{1 ³= nbaL n
  • 11. © 2020 Wael Badawy 11 )(nTIME }0:{1 ³= nbaL n }0,:{ ³knabaabn }evenis:{ nbn Other example problems in the same class }3:{ knbn =
  • 12. © 2020 Wael Badawy 12 )( 2 nTIME }0:{ ³nba nn Examples in class: }},{:{ bawww R Î }},{:{ bawww Î
  • 13. © 2020 Wael Badawy 13 )( 3 nTIME Examples in class: }grammarfree-context bygeneratedis:,{2 G wwGL = }and matrices:,,{ 321 3213 MMM nnMMML =´ ´= CYK algorithm Matrix multiplication
  • 14. © 2020 Wael Badawy 14 Polynomial time algorithms: )( k nTIME Represents tractable algorithms: for small we can decide the result fast k constant 0>k
  • 15. © 2020 Wael Badawy 15 )( k nTIME )( 1+k nTIME )()( 1+ Ì kk nTIMEnTIMEIt can be shown:
  • 16. © 2020 Wael Badawy 16 !k k nTIMEP )(= The Time Complexity Class P •“tractable” problems •polynomial time algorithms Represents:
  • 17. © 2020 Wael Badawy 17 P CYK-algorithm }{ nn ba }{ww Class Matrix multiplication }{ ban
  • 18. © 2020 Wael Badawy 18 Exponential time algorithms: )2( k n TIME Represent intractable algorithms: Some problem instances may take centuries to solve
  • 19. © 2020 Wael Badawy 19 Example: the Hamiltonian Path Problem Question: is there a Hamiltonian path from s to t? s t
  • 20. © 2020 Wael Badawy 20 s t YES!
  • 21. © 2020 Wael Badawy 21 )2()!( k n TIMEnTIMEL »Î Exponential time Intractable problem A solution: search exhaustively all paths
  • 22. © 2020 Wael Badawy 22 The clique problem Does there exist a clique of size k?
  • 23. © 2020 Wael Badawy 23 The clique problem Does there exist a clique of size k?
  • 24. © 2020 Wael Badawy 24 Example: The Satisfiability Problem Boolean expressions in Conjunctive Normal Form: ktttt ÙÙÙÙ !321 pi xxxxt ÚÚÚÚ= !321 Variables Question: is the expression satisfiable? clauses
  • 25. © 2020 Wael Badawy 25 )()( 3121 xxxx ÚÙÚ Satisfiable: 1,1,0 321 === xxx 1)()( 3121 =ÚÙÚ xxxx Example:
  • 26. © 2020 Wael Badawy 26 2121 )( xxxx ÙÙÚ Not satisfiable Example:
  • 27. © 2020 Wael Badawy 27 e}satisfiablisexpression:{ wwL = )2( k n TIMEL Î Algorithm: search exhaustively all possible binary values of the variables exponential
  • 28. © 2020 Wael Badawy Non-Determinism 28 Language class: ))(( nTNTIME A Non-Deterministic Turing Machine decides each string of length in time 1L 2L 3L ))(( nTO n
  • 30. © 2020 Wael Badawy 30 Non-Deterministic Polynomial time algorithms: )( k nNTIMELÎ
  • 31. © 2020 Wael Badawy 31 !k k nNTIMENP )(= The class NP Non-Deterministic Polynomial time
  • 32. © 2020 Wael Badawy 32 Example: The satisfiability problem Non-Deterministic algorithm: •Guess an assignment of the variables e}satisfiablisexpression:{ wwL = •Check if this is a satisfying assignment
  • 33. © 2020 Wael Badawy 33 Time for variables:n )(nO e}satisfiablisexpression:{ wwL = Total time: •Guess an assignment of the variables •Check if this is a satisfying assignment )(nO )(nO
  • 34. © 2020 Wael Badawy 34 e}satisfiablisexpression:{ wwL = NPLÎ The satisfiability problem is a - ProblemNP
  • 35. © 2020 Wael Badawy 35 Observation: NPP Í Deterministic Polynomial Non-Deterministic Polynomial
  • 36. © 2020 Wael Badawy 36 Open Problem: ?NPP = WE DO NOT KNOW THE ANSWER
  • 37. © 2020 Wael Badawy 37 Example: Does the Satisfiability problem have a polynomial time deterministic algorithm? WE DO NOT KNOW THE ANSWER Open Problem: ?NPP =