Академический Документы
Профессиональный Документы
Культура Документы
Jump to: navigation, search This article needs additional citations for verification.
Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (January 2010)
n computer science, the time complexity of an algorithm !uantifies the amount of time taken by an algorithm to run as a function of the si"e of the input to the problem. The time comple#ity of an algorithm is commonly e#pressed using big $ notation, %hich suppresses multiplicative constants and lo%er order terms. When e#pressed this %ay, the time comple#ity is said to be described asymptotically, i.e., as the input si"e goes to infinity. For e#ample, if the time re!uired by an algorithm on all inputs of si"e n is at most &n' ( 'n, the asymptotic time comple#ity is $)n'*. Time comple#ity is commonly estimated by counting the number of elementary operations performed by the algorithm, %here an elementary operation takes a fi#ed amount of time to perform. Thus the amount of time taken and the number of elementary operations performed by the algorithm differ by at most a constant factor. +ince an algorithm may take a different amount of time even on inputs of the same si"e, the most commonly used measure of time comple#ity, the %orst,case time comple#ity of an algorithm, denoted as T(n), is the ma#imum amount of time taken on any input of si"e n. Time comple#ities are classified by the nature of the function T)n*. For instance, an algorithm %ith T)n* - $)n* is called a linear time algorithm, and an algorithm %ith T)n* $).n* is said to be an e#ponential time algorithm.
Contents
/hide0
1 Table of common time comple#ities . 2onstant time ' 3ogarithmic time 4 Polylogarithmic time & +ub,linear time 5 3inear time 6 3inearithmic7!uasilinear time 8 +ub,!uadratic time 9 Polynomial time o 9.1 +trongly and %eakly polynomial time o 9.. 2omple#ity classes 1: +uperpolynomial time
11 ;uasi,polynomial time o 11.1 <elation to =P,complete problems 1. +ub,e#ponential time o 1..1 First definition o 1... +econd definition 1....1 >#ponential time hypothesis 1' >#ponential time 14 ?ouble e#ponential time 1& +ee also 15 <eferences
?etermining if a number is even or odd inverse @morti"ed time per O)A)n** @ckermann operation using a disBoint set iterated ?istributed coloring of O)logC n* logarithmic cycles @morti"ed time per log,logarithmic O)log log n* operation using a bounded priority !ueue/10 . logarithmic time ?3$DT E> O)log n* log n, log)n * Finary search polylogarithmic poly)log n* )log n*. time O)nGc*, fractional po%er n1/2, n2/3 +earching in a kd,tree :HcH1 Finding the smallest item in linear time O)n* n an unsorted array +eidelJs polygon triangulation algorithm. Ilog In log star nI O)n logC n* star nI is the iterated logarithm Fastest possible comparison linearithmic time O)n log n* n log n, log nK sort . . !uadratic time O )n * n Fubble sortL nsertion sort cubic time O)n'* n' =aive multiplication of t%o
polynomial time P !uasi,polynomial ;P time sub,e#ponential time +UF>OP )first definition* sub,e#ponential time )second definition* e#ponential time > e#ponential time >OPT E> factorial time
nMn matrices. 2alculating partial correlation. NarmarkarJs algorithm for .O)log n* n, n log n, n1: linear programmingL @N+ poly)n* primality test Fest,kno%n $)log. n*, appro#imation algorithm for .poly)log n* nlog log n, nlog n the directed +teiner tree problem. @ssuming comple#ity O).n* for all O).log nlog log n* theoretic conBectures, FPP is P: contained in +UF>OP./.0 .
o)n*
n17'
Fest,kno%n algorithm for integer factori"ation and graph isomorphism +olving the traveling salesman problem using dynamic programming +olving the traveling salesman problem via brute, force search ?eciding the truth of a given statement in Presburger arithmetic
Qere are some e#amples of code fragments that run in constant time:
int index = 5; int item = list[index]; if (condition true) then perform some operation that runs in constant time else perform some other operation that runs in constant time for i = 1 to 100 for j = 1 to 200 perform some operation that runs in constant time
f T)n* is $)any constant value*, this is e!uivalent to and stated in standard notation as T)n* being $)1*.
do*. $ther%ise, a sub,linear time algorithm %ould not be able to read or learn the entire input prior to providing its output. The specific term sublinear time al#orithm is usually reserved to algorithms that are unlike the above in that they are run over classical serial machine models and are not allo%ed prior assumptions on the input./40 They are ho%ever allo%ed to be randomi"ed, and indeed must be randomi"ed for all but the most trivial of tasks. @s such an algorithm must provide an ans%er %ithout reading the entire input, its particulars heavily depend on the access allo%ed to the input. Usually for an input that is represented as a binary string b1,...,b% it is assumed that the algorithm can in time $)1* re!uest and obtain the value of bi for any i. +ublinear time algorithms are typically randomi"ed, and provide only appro#imate solutions. n fact, the property of a binary string having only "eros )and no ones* can be easily proved not to be decidable by a )non,appro#imate* sublinear time algorithm. +ublinear time algorithms arise naturally in the investigation of property testing.
@n algorithm is said to run in (uasilinear time if T)n* - !(n logk n) for any constant %. ;uasilinear time algorithms are also o)n1(V* for every V P :, and thus run faster than any polynomial in n %ith e#ponent strictly greater than 1. n many cases, the n T log n running time is simply the result of performing a W)log n* operation n times. For e#ample, Finary tree sort creates a Finary tree by inserting each element of the n,si"ed array one by one. +ince the insert operation on a self,balancing binary search tree takes $)log n* time, the entire algorithm takes linearithmic time. 2omparison sorts re!uire at least linearithmic number of comparisons in the %orst case because log)nK* - W)n log n*. They also fre!uently arise from the recurrence relation T)n* - . T)n7.* ( $)n*. +ome famous algorithms that run in linearithmic time include:
2omb sort, in the average and %orst case ;uicksort in the average case Qeapsort, merge sort, introsort, binary tree sort, smoothsort, patience sorting, etc. in the %orst case Fast Fourier transforms Eonge array calculation
The !uicksort sorting algorithm on n integers performs at most &n. operations for some constant &. Thus it runs in time O)n.* and is a polynomial time algorithm.
@ll the basic arithmetic operations )addition, subtraction, multiplication, division, and comparison* can be done in polynomial time. Ea#imum matchings in graphs can be found in polynomial time.
The concept of polynomial time leads to several comple#ity classes in computational comple#ity theory. +ome important classes defined using polynomial time are the follo%ing.
$: The comple#ity class of decision problems that can be solved on a deterministic Turing machine in polynomial time. N$: The comple#ity class of decision problems that can be solved on a non, deterministic Turing machine in polynomial time. +$$: The comple#ity class of decision problems that can be solved %ith "ero error on a probabilistic Turing machine in polynomial time. R$: The comple#ity class of decision problems that can be solved %ith 1,sided error on a probabilistic Turing machine in polynomial time. ,$$: The comple#ity class of decision problems that can be solved %ith .,sided error on a probabilistic Turing machine in polynomial time. ,-$: The comple#ity class of decision problems that can be solved %ith .,sided error on a !uantum Turing machine in polynomial time.
P is the smallest time,comple#ity class on a deterministic machine %hich is robust in terms of machine model changes. )For e#ample, a change from a single,tape Turing machine to a multi,tape machine can lead to a !uadratic speedup, but any algorithm that runs in polynomial time under one model also does so on the other.* @ny given abstract machine %ill have a comple#ity class corresponding to the problems %hich can be solved in polynomial time on that machine.
The term sub&exponential time is used to e#press that the running time of some algorithm may gro% faster than any polynomial but is still significantly smaller than an e#ponential. n this sense, problems that have sub,e#ponential time algorithms are some%hat more tractable than those that only have e#ponential algorithms. The precise definition of Isub,e#ponentialI is not generally agreed upon,/1.0 and %e list the t%o most %idely,used ones belo%.
?ecision procedures for Presburger arithmetic 2omputing a Dr]bner basis )in the %orst case* Finding a complete set of associative,commutative unifiers/.:0 +atisfying 2T3( )%hich is, in fact, .,>OPT E>,complete*/.10 ;uantifier elimination on real closed fields takes at least doubly,e#ponential time )but is not even kno%n to be computable in >3>E>=T@<^*
3,notation
[edit] References
1. 3 Eehlhorn, NurtL =aher, +tefan )199:*. IFounded ordered dictionaries in $)log log =* time and $)n* spaceI. 'n ormation (rocessin# "etters. .. G a b Fabai, 3_s"l`L Fortno%, 3anceL =isan, =.L Wigderson, @vi )199'*. IFPP has sube#ponential time simulations unless >OPT E> has publishable proofsI. )omputational )omplexity )Ferlin, =e% ^ork: +pringer,aerlag* 4 )4*: ':6Y'18. doi:1:.1::67FF:1.6&485. '. 3 Fradford, Phillip D.L <a%lins, Dregory J. >.L +hannon, Dregory >. )1998*. I>fficient Eatri# 2hain $rdering in Polylog TimeI. *'&+ Journal on )omputin# )Philadelphia: +ociety for ndustrial and @pplied Eathematics* 56 ).*: 455Y49:. doi:1:.11'67+::96&'9694.6:598. ++= 1:9&,6111. 4. 3 Numar, <aviL <ubinfeld, <onitt ).::'*. I+ublinear time algorithmsI. *',&)T -e$s 47 )4*: &6Y56.
http:77%%%.cs.princeton.edu7courses7archive7spr:47cos&98F7bib7kumar<, survey.pdf. &. 3 Papadimitriou, 2hristos Q. )1994*. )omputational complexity. <eading, Eass.: @ddison,Wesley. +F= :,.:1,&':8.,1. 5. 3 +ipser, Eichael ).::5*. 'ntro.uction to the Theory o )omputation. 2ourse Technology nc. +F= :,519,.1654,.. 6. 3 2obham, @lan )195&*. IThe intrinsic computational difficulty of functionsI. (roc/ "o#ic0 +etho.olo#y0 an. (hilosophy o *cience ''. =orth Qolland. 8. 3 Dr]tschel, EartinL 3_s"l` 3ov_s", @le#ander +chriBver )1988*. I2omple#ity, $racles, and =umerical 2omputationI. ,eometric &l#orithms an. )ombinatorial Optimi1ation. +pringer. +F= :'861'5.4O. 9. 3 +chriBver, @le#ander ).::'*. IPreliminaries on algorithms and 2omple#ityI. )ombinatorial Optimi1ation! (olyhe.ra an. 2 iciency. ". +pringer. +F= '&4:44'894. 1:. 3 )omplexity 3oo: 2lass ;P: ;uasipolynomial,Time 11. G a b mpaglia""o, <.L Paturi, <. ).::1*. I$n the comple#ity of k,+@TI. Journal o )omputer an. *ystem *ciences )>lsevier* 85 ).*: '56Y'6&. doi:1:.1::57Bcss..:::.16.6. ++= 1:9:,.6.4. 1.. 3 @aronson, +cott )& @pril .::9*. I@ not,!uite,e#ponential dilemmaI. *htetl4 Optimi1e.. http:77scottaaronson.com7blog7bp-'94. <etrieved . ?ecember .::9. 1'. 3 )omplexity 3oo: 2lass +UF>OP: ?eterministic +ube#ponential,Time 14. 3 Eoser, P. ).::'*. IFaireJs 2ategories on +mall 2omple#ity 2lassesI. "ecture -otes in )omputer *cience )Ferlin, =e% ^ork: +pringer,aerlag*: '''Y'4.. ++= :':.,964'. 1&. 3 Eiltersen, P.F. ).::1*. I?><@=?$E c =D 2$EP3>O T^ 23@++>+I. 5an.boo% o 6an.omi1e. )omputin# )Nlu%er @cademic Pub*: 84'. 15. 3 Nuperberg, Dreg ).::&*. I@ +ube#ponential,Time ;uantum @lgorithm for the ?ihedral Qidden +ubgroup ProblemI. *'&+ Journal on )omputin# )Philadelphia: +ociety for ndustrial and @pplied Eathematics* 49 )1*: 188. ++= 1:9&,6111. 16. 3 $ded <egev ).::4*. I@ +ube#ponential Time @lgorithm for the ?ihedral Qidden +ubgroup Problem %ith Polynomial +paceI. ar7iv!8uant4ph/090:1;1v1 /!uant,ph0. 18. 3 Flum, J]rgL Drohe, Eartin ).::5*. (arameteri1e. )omplexity Theory. +pringer. p. 416. +F= 968,',&4:,.99&.,'. http:77%%%.springer.com7east7home7generic7search7resultsb+DW ?-&,4:1:9,.., 141'&8'..,:. <etrieved .:1:,:',:&. 19. 3 mpaglia""o, <.L Paturi, <.L cane, F. ).::1*. IWhich problems have strongly e#ponential comple#itybI. Journal o )omputer an. *ystem *ciences 84 )4*: &1.Y &':. doi:1:.1::57Bcss..::1.1664. .:. 3 Napur, ?eepakL =arendran, Paliath )199.*. IProc. 6th >>> +ymp. 3ogic in 2omputer +cience )3 2+ 199.*I. pp. 11Y.1. doi:1:.11:973 2+.199..18&&1&. http:77citeseer.ist.psu.edu7''6'5'.html. .1. 3 Johannse, JanL 3ange, Eartin ).::'*. I2T3( is complete for double e#ponential timeI. in Faeten, Jos 2. E.L 3enstra, Jan NarelL Parro%, Joachim et al.. (roc/ 30th 'nt/ )ollo8/ &utomata0 "an#ua#es0 an. (ro#rammin# (')&"( 2003). 3ecture
Jump to: navigation, search The introduction to this article provides insufficient context for t ose unfamiliar )it t e sub;ect. Please help improve the article %ith a good introductory style.
(October 200<)
n theoretical computer science, a Turing machine is a theoretical machine that is used in thought e#periments to e#amine the abilities and limitations of computers. n essence, a Turing machine is imagined to be a simple computer that reads and %rites symbols one at a time on an endless strip of paper tape by strictly follo%ing a set of rules. t determines %hat action it should perform ne#t according to its internal IstateI and %hat number it currently sees. @n e#ample of one of a Turing EachineJs rules might thus be: I f you are in state . and you see an J@J, change it to a F and move left.I n a deterministic Turing mac ine, the set of rules prescribes at most one action to be performed for any given situation. @ non&deterministic Turing mac ine )NT<*, by contrast, may have a set of rules that prescribes more than one action for a given situation. For e#ample, a non,deterministic Turing machine may have both I f you are in state . and you see an J@J, change it to a JFJ and move leftI and I f you are in state . and you see an J@J, change it to a J2J and move rightI in its rule set. @n ordinary )deterministic* Turing machine )?TE* has a transition function that, for a given state and symbol under the tape head, specifies three things: the symbol to be %ritten to the tape, the direction )left or right* in %hich the head should move, and the subse!uent state of the finite control. For e#ample, an O on the tape in state ' might make the ?TE %rite a ^ on the tape, move the head one position to the right, and s%itch to state &. @ non,deterministic Turing machine )=TE* differs in that the state and tape symbol no longer uni8uely specify these thingsL rather, many different actions may apply for the same combination of state and symbol. For e#ample, an O on the tape in state ' might no% allo% the =TE to %rite a ^, move right, and s%itch to state & or to %rite an O, move left, and stay in state '.
Contents
/hide0
1 ?efinition o 1.1 <esolution of multiple rules . aariations ' >!uivalence %ith ?TEs 4 Founded non,determinism & 2omparison %ith !uantum computers 5 +ee also 6 <eferences 8 >#ternal links
[edit] 2efinition
@ nondeterministic Turing machine can be formally defined as a 5,tuple , %here
The difference %ith a standard )deterministic* Turing machine is that for those, the transition relation is a function )the transition function*. 2onfigurations and the yiel.s relation on configurations, %hich describes the possible actions of the Turing machine given any possible contents of the tape, are as for standard Turing machines, e#cept that the yields relation is no longer single,valued. The notion of string acceptance is unchanged: a non,deterministic Turing machine accepts a string if, %hen the machine is started on the configuration in %hich the tape head is on the first character of the string )if any*, and the tape is all blank other%ise, at least one of the machineJs possible computations from that configuration puts the machine into a state in &. ) f the machine is deterministic, the possible computations are the prefi#es of a single, possibly infinite, path.*
The suspected shape of the range of problems solvable by !uantum computers in polynomial time. =ote that the figure suggests and , if this is not true then the figure should look other%ise. t is a common misconception that !uantum computers are =TEs./.0 t is believed but has not been proven that the po%er of !uantum computers is incomparable to that of =TEs/'0. That is, problems likely e#ist that an =TE could efficiently solve but that a !uantum computer cannot. @ likely e#ample of problems solvable by =TEs but not by !uantum computers in polynomial time are =P,complete problems.
[edit] References
1. 3 2lements o the Theory o )omputation, by Qarry <. 3e%is and 2hristos Q. Papadimitriou, Prentice,Qall, >ngle%ood 2liffs, =e% Jersey, 1981, +F= :,1', .6'416,5, pp. .:5,.11 .. 3 The $rion ;uantum 2omputer @nti,Qype F@;, +cott @aronson. '. 3 Tusarova, Tere"a ).::4*. =uantum complexity classes. arOiv:cs7:4:9:&1..
Qarry <. 3e%is, 2hristos Papadimitriou )1981*. 2lements o the Theory o )omputation )1st ed.*. Prentice,Qall. +F= :,1',.6'416,5. +ection 4.5: =ondeterministic Turing machines, pp. .:4Y.11. John 2. Eartin )1996*. 'ntro.uction to "an#ua#es an. the Theory o )omputation ).nd ed.*. EcDra%,Qill. +F= :,:6,:4:84&,9. +ection 9.5: =ondeterministic Turing machines, pp. .66Y.81. 2hristos Papadimitriou )199'*. )omputational )omplexity )1st ed.*. @ddison, Wesley. +F= :,.:1,&':8.,1. +ection ..6: =ondeterministic machines, pp. 4&Y &:.
$
)definition* 2efinition> The complexity class of languages that can be accepted by a deterministic Turin# machine in polynomial time.
N$
)definition* 2efinition> The complexity class of .ecision problems for %hich ans%ers can be checked by an algorithm %hose run time is polynomial in the si"e of the input. =ote that this doesnJt re!uire or imply that an ans%er can be found !uickly, only that any claimed solution can be verified !uickly. I=PI is the class that a Non.eterministic Turin# machine accepts in $olynomial time.
N$& ard
)definition* 2efinition> The complexity class of .ecision problems that are intrinsically harder than those that can be solved by a non.eterministic Turin# machine in polynomial time. When a decision version of a combinatorial optimi1ation problem is proved to belong to the class of -(4complete problems, then the optimi"ation version is =P,hard.
N$&complete
)definition* 2efinition> The complexity class of .ecision problems for %hich ans%ers can be checked for correctness, given a certi icate, by an algorithm %hose run time is polynomial in the si"e of the input )that is, it is -(* and no other =P problem is more than a polynomial factor harder. nformally, a problem is =P,complete if ans%ers can be verified !uickly, and a !uick algorithm to solve this problem can be used to solve all other =P problems !uickly.