Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

3/28/13

14 numbers every developer should know

14numberseverydevelopershouldknow
DespreBlog

CosminNegruseri 26martie2013

123
Like

62

97
Tweet

Ultimeleinsemnari
14numberseverydeveloper shouldknow Interactiveproblemsshortlist CodePandas Combinatoricsshortlist Algoritmiada2013 Infoarenaiaalesnoua conducere HaidetisaimbunatatimInfoarena impreuna! Rollinghash,RabinKarp, palindromes,rsyncandothers Count(distinct)problem Infoarenalovetedinnou!

JeffDean ,afamousGoogleengineer,popularizedalistoflatencynumberseveryoneshould know .Thelistisagreatresourcefordesigninglargescaleinfrastructuresystems. Algorithmsandtheircomplexityoftenoccurincriticalpartsofcomputersystems,butIfindthat fewengineershaveagoodunderstandingofhowaO(n!)algorithmcomparestoaO(n5 )one. Inthecodingcontestworld,competitorsthinkaboutthesetradeoffsallthetime.Nowonder, there'sasetofnumberseveryalgorithmdesignershouldknow. Thetablebelowshowsthelimitsthatcanbereachedinafewsecondsbyalgorithmsofdifferent complexities,nbeingtheinputsize.I'veaddedsomealgorithmsanddatastructureexamplesfor eachcomplexityclass.

Categorii
algoritmiada(7) algoritmica(1) concursuri(11) doilasuta(1) Evenimente(7) facebook(1) Features(2) girlcamp(2) Girls(2) Girlscamp(2) girlsprogrammingcamp(3) google(1) infoarena(6) internships(1) interviu(12) lifetheuniverseandeverything (7) organizare(3) potw(31) preoni2008(3) probleme(9) SelectieGirlsProgramming Camp(1) stiri(76) video(6)

Blogroll
Vivi'sblog WebDiariosdeMotocicleta CatalinFrancu FlorinManea Stevey'sBlogRants JoelonSoftware Developingfordevelopers

maximumn 1,000,000,000 andhigher

complexity algorithms logn,sqrtn binarysearch,ternarysearch,fast exponentiation,euclidalgorithm

datastructures

www.infoarena.ro/blog/numbers-everyone-should-know

1/3

3/28/13

14 numbers every developer should know

10,000,000

n,nloglog n,nlog*n

setintersection,Eratosthenessieve,radix sort,KMP,topologicalsort,Eulertour, stronglyconnectedcomponents,2sat

disjointsets,tries, hash_map,rollinghash deque segmenttrees,range

1,000,000

nlogn

sorting,divideandconquer,sweepline, Kruskal,Dijkstra

trees,heaps,treaps, binaryindexedtrees, suffixarrays

100,000 50,000

nlog2 n n1.585 ,n sqrtn

divideandconquer Karatsuba,squareroottrick largestemptyrectangle,Dijkstra,Prim(on densegraphs) allpairsshortestpaths,largestsum

2drangetrees twoleveltree

100010,000 n2

300500

n3

submatrix,naivematrixmultiplication, matrixchainmultiplication,gaussian elimination,networkflow

3050 2540

n4 ,n5 ,n6 3n/2 ,2n/2

meetinthemiddle subsetenumeration,bruteforce,dynamic programmingwithexponentialstates dynamicprogrammingwithexponential states dynamicprogrammingwithexponential states bruteforce,backtracking, next_permutation bruteforce,cartesianproduct

hashtables(forset intersection)

1524

2n

1520

n2 2n

bitsets,hash_map hash_map(tostorethe states)

1317

3n

11 8

n! nn

Thesenumbersaren'tveryprecise,theyassumeinmemoryoperationsandsomevaryingconstant factors,buttheydogiveagoodstartingpointinyoursearchforasolutionthatfitsyourproblemand yourdatasize. Let'sgothroughanexample. SupposeyouworkforaGPScompanyandyourprojectistoimprovetheirdirectionsfeature.In schoolyou'velearnedaboutusingDijkstra'salgorithmtofindtheshortestpathbetweentwonodes inagraph.Knowingthesenumbersyouwillunderstandthatitwilltakesecondstoprocessagraph withmillionsofedgesgiventhatDijkstraimplementationshavemlogntimecomplexity(wheremis thenumberofedgesandnthenumberofnodes). Nowyoufaceafewquestions: Howfastdoyouwantyourcodetobe?seconds?hundredsofmilliseconds?

www.infoarena.ro/blog/numbers-everyone-should-know

2/3

3/28/13

14 numbers every developer should know

Aresponseonthewebfeelsfastifittakeslessthen500milliseconds.Solet'spickhalfasecond. Howbigisthegraph?Doyouwanttosolvetheproblemforacity,acoutryorevenacontinent? Eachisaboutamagnitudelargerthantheotherandwillbesolvedbydifferentapproaches.Let's saywewanttosolvetheproblemforthewholeofEurope. Herearesizesforafewinputsets: input #nodes #directededges #roadcategories Europe 18029721 42199587 13 USA/CAN 18741705 47244849 13 USA(Tiger) 24278285 58213192 4

Sincewechosehalfasecondtobeourexecutiontimeandthesizeofourproblemtobeabout40 millionedgesit'sclearfromourtablethatmlognistooslow.SopureDijkstrawon'tdo.Weneedto lookathowotheralgorithmslikeAstarsearchoronebasedonHighwayhierarchies behavefor thisproblem.


Categorii:

20042013Asociatiainfoarena
Cuexceptiacazurilorincaresespecificaaltfel,continutulsiteuluiinfoarena estepublicatsublicentaCreativeCommonsAttributionNonCommercial2.5.

www.infoarena.ro/blog/numbers-everyone-should-know

3/3

You might also like