67 views

Original Title: Assignment 1 Solutions

Uploaded by JamesRuth

- Algorithm Analysis
- 10.1.1.79
- Algorithm Types and Classification
- Intro Algo
- CS163_Topic7
- A Survey of 3sum-Hard Problems
- Longest Increasing Subsequence
- tutorial-complexity
- Comb_Accel_Branch-and-Bound_Meth_for_Solv_the_MIP_Mod_of_Proc_Netw_Synth.pdf
- Lab 5 Report
- Introduction to Algorithmic Analysis
- John Preskill - Quantum Information and Computation
- A General Algorithm for Computing Distance Transforms in Linear Time
- bigohhandout
- Parallel Computing Notes
- simulation of stopped diffusions
- Artigo Do Periodico
- Computational Geometry Methods and Applications - Chen
- Quality Management
- My Abstract of the TOC and TP Tools

You are on page 1of 5

1

COSC 336 Data Structures and Algorithm Analysis, Fall 2014

Assignment 1

Release date: September 10, 2014

Due date: September 17, 2014, 12:00pm EST

Question 1

Define and explain mathematically the relevance of the three asymptotic notations for Best-

Case, Expected (Average) case, and Worst-case running time.

Question 2 Give the worst case running time of the following code?

a)

Input: A, n

curMax = A[0][0]

for i=0 i<n i++

for j=0 j<n j++

if curMax < A[i][j]

curMax = A[i][j]

return curMax

Best Case ( or Omega) i s a r unni ng t i me f or whi ch t he set of al l pos-

si bl e r unni ng t i mes ( whi ch we can cal l c) i s bound f r omt he bot t omby

t he f unct i on of ( g( n) ) . No f unct i ons of r un- t i me can exi st l ower t han

, def i ni ng i t as t he absol ut e f ast est r un- t i me.

Worst Case ( or O) i s a r unni ng t i me f or whi ch t he set of al l possi bl e

r unni ng t i mes ( whi ch we can cal l c) i s bound f r omt he t op by t he f unct i on

of O( g( n) ) . No f unct i on of r un- t i me can exi st hi gher t han O, def i ni ng i t

as t he absol ut e sl owest r un- t i me.

Average case ( or Thet a) i s a f unct i on t hat i s def i ned as t he case when t he

wor se case r unni ng t i me and t he best case r unni ng t i me ar e equi val ent .

Ther e ar e 2 nest ed f or l oops: O(n^2)

James Ruth

9/17/2014

Const ant

Const ant

N ( f or )

N ( f or )

Const ant

Const ant

Const ant

Dr. Subrata Acharya Towson University

2

b)

procedure Sort( A : list of sortable items ) defined as:

do

swapped := false

for each i in 0 to length(A) - 2 inclusive do:

if A[i] > A[i+1] then

swap( A[i], A[i+1] )

swapped := true

end if

end for

while swapped

end procedure

Question 3 - Determine the Big-Oh for the following:

1. 41n

4

+ 7n

2. 4nlogn + 12nlogn - 100

3. n

e

+ n

5

logn + c

n

One f or l oop, and one do- whi l e l oop: O(N^2)

n^4 is a higher polynomial

Assuming multi-core: O(n^4)

nlogn is the highest function present

Assuming multi-core: O(nlogn)

Exponential > Polynomial > Log

Assuming multi-cre: O(c^n)

James Ruth

9/17/2014

N ( do- whi l e)

Const ant

N ( f or )

Const ant

Const ant

Const ant

Const ant

Const ant

Dr. Subrata Acharya Towson University

3

Question 4

Write down the pseudo-code for Fibonacci sequence and give the Big-Oh bound for your

algorithm.

Question 5

What can you say about the input size and the algorithm type for the best-case (Omega) and

worst-case (Big-Oh) bounds?

Question 6

Give an example and explain where you can have different worst case bounds for the same

problem. Explain.

Maxi mumcont i guous subsequence sums can have di f f er ent bounds

because t her e ar e mul t i pl e sol ut i ons f or t he same pr obl em,

wi t h some sol ut i ons havi ng an O( n^3) and some havi ng an O( n) .

Thi s i s because of t he di f f er ent sol ut i ons i nvol vi ng di f f er i ng

amount s of nest ed f or l oops. Each compl et es t he t ask, but wi t h

t he mor e l oops i nvol ved, t he mor e cycl es needed t o get t hr ough

each t ask.

Input: n = sequence l i mi t

Variables:

num1 = 0

num2 = 1

temp = 0

r ead n

i f n = 1 pr i nt 0

i f n = 2 pr i nt 1

el se

pr i nt num1

pr i nt num2

f or ( i = 3, i <=n, i ++)

t emp = num1+num2

pr i nt num3

num1 = num2

num2 = num3

end f or

Onl y 1 f or - l oop: O(n)

Bi g- Oh bounds al ways i nt er pr et t he i nput si ze as t he absol ut e maxi mum. For

i nst ance, i f a f unct i on exi t s af t er f i ndi ng a number , Bi g- Oh

assumes t he number i s i n t he ver y l ast pl ace. Most al gor i t hmt ypes ar e

j udged on t hei r Bi g- Oh val ue, and not t hei r Omega.

Occasi onal l y, an Omega bound i s eval uat ed, i n whi ch case t he i nput si ze

woul d be t heor et i cal l y t he absol ut e mi ni mumneeded f or t he al gor i t hmt o

wor k. Thi s i s done t o check i f t he Omega i s i n f act equal t o t he Bi g- Oh.

James Ruth

9/17/2014

Dr. Subrata Acharya Towson University

4

Question 7

Arrange the following in decreasing order of running time.

a. N

b. log N

c. 10

d. log c

e. N

2

f. c

N

g. N

N

h. N!

i. e

5

Question 8

Write a pseudo code for an O (n

5

log

2

n) algorithm.

log c, 10, e^5, log N, N, N^2, C^N, N!, N^N

for(i=1,i<=n, 2i)

for(j=1, j<n, j++)

for(k=1, k<n, k++)

for(l=1, l<n, l++)

for(m=1, m<n, m++)

for(o=1, o<n, o++)

//code goes here

end for

end for

end for

end for

end for

end for

James Ruth

9/17/2014

Dr. Subrata Acharya Towson University

5

Question 9

Let T

1

(N) = N

5

, T

2

(N) = e, T

3

(N) = N

7/2

,T

4

(N) = N

c

logN, T

5

(N) = N

a. What would be Big-Oh of T1+T2+T3+T4+T5 and explain why?

b. What would be Big-Oh of T1*T2*T3*T4*T5 and explain why?

Assumi ng mul t i - cor e: O(N^c*logN)

Assumi ng si ngl e- cor e: O(T1+T3+T4+T5)

Thi s i s because i n a mul t i - cor e pr ocessor , t asks can be spl i t up among

t he cor es, and so i t wi l l onl y t ake as l ong as i t t akes a cor e t o f i ni sh

t he hi ghest degr ee of O. Compar ed t o si ngl e, wher e i t must sequence each

f or mul a i n a sor t of queue.

N*N^5*N^( 7/ 2) *( N^c*l ogN) = N^( 2c+( 19/ 2) )

Bi g- Oh di sr egar ds const ant s l i ke 2c or e.

Thi s l eaves O(N^(19/2)*logN).

James Ruth

9/17/2014

- Algorithm AnalysisUploaded byJay Ng
- 10.1.1.79Uploaded bysamir_khan11
- Algorithm Types and ClassificationUploaded bySheraz Ali
- Intro AlgoUploaded byRavi Stephen
- CS163_Topic7Uploaded bySumant Luhar
- A Survey of 3sum-Hard ProblemsUploaded byshabunc
- Longest Increasing SubsequenceUploaded byModernZen
- tutorial-complexityUploaded byAzim Khan
- Comb_Accel_Branch-and-Bound_Meth_for_Solv_the_MIP_Mod_of_Proc_Netw_Synth.pdfUploaded byBahman Homayun
- Lab 5 ReportUploaded byJorge Berumen
- Introduction to Algorithmic AnalysisUploaded byKristin Dikiciyan
- John Preskill - Quantum Information and ComputationUploaded bywgfaldo
- A General Algorithm for Computing Distance Transforms in Linear TimeUploaded byNoisyperson
- bigohhandoutUploaded bybarber bob
- Parallel Computing NotesUploaded byluvlastcall
- simulation of stopped diffusionsUploaded bysupermanvix
- Artigo Do PeriodicoUploaded byadrianazeredo
- Computational Geometry Methods and Applications - ChenUploaded byAlejandro Jimenez
- Quality ManagementUploaded byarjunmurti
- My Abstract of the TOC and TP ToolsUploaded byNabil Khibit
- Data Leakage DetectionUploaded bykrishnaone
- Data Structures With c++Uploaded byRachna Bhatnagar
- Analisis design algoritmaUploaded byJesy Amelia
- S.M.E.D.Uploaded byanujkumartyagi9275
- RecurrenceUploaded byJagrut Kosti
- entropy-16-05020Uploaded byZeeshan Shamsi
- Perventive MaintenanceUploaded byPeracha Engineering
- 1349Uploaded byArtem A. Lenskiy
- spire00Uploaded byDevi Dian Pramana Putra
- Daa Unit Viii Notes 1Uploaded bySunil Choudhary

- Army Men GuideUploaded byJamesRuth
- Stone Fast MapUploaded byJamesRuth
- Stone Fast MapUploaded byJamesRuth
- 5e Rogue Assassin Lvl 10Uploaded byJamesRuth
- Guild RecruitmentUploaded byJamesRuth
- STEPHEN SONDHEIM AND HIS FILMIC INFLUENCESUploaded byJamesRuth
- CTF Rules carver 2010Uploaded byJamesRuth
- Edited Map of Waterdeep Up CloseUploaded byJamesRuth
- Old HeadshotsUploaded byJamesRuth
- CURSO DE INGLES COMPLETO - Eric GonzálezUploaded byFrat Quintero
- Guild RecruitmentUploaded byJamesRuth
- Curso de Ingles Completo 2 - Eric GonzálezUploaded byJamesRuth
- Gimme Book PleaseUploaded byJamesRuth
- Tower in the IceUploaded byJamesRuth

- UMLUploaded byNurfauza Jali
- 9 Nonseasonal ARIMAUploaded byilkom12
- Lec 2 the Entity-Relationship ModelUploaded bySandeep Wagh
- TIF_06Uploaded byboblong1911
- 1.1 - Relational database concepts.pdfUploaded byTheDragon OfDestruction
- tif_ch16Uploaded byHaouas Hanen
- Enterprise IT StandarsUploaded byPedro Lara
- oosd ITUploaded byAbdul Kareem
- Math t AssignmentUploaded byDeryneTee
- Extreme Value Distribution PDFUploaded byVernon
- Modelos ArmUploaded bysanpornu
- De_cuong_PP_Tke_PT_dulieu.pdfUploaded bynguyenhuynhvuong93
- A Deductive View on Process-Data Diagrams XXXXXXX 2011Uploaded byAdelaide Bianchini
- 2 - UML.pdfUploaded bySyed Akram Hussain
- Chapter 7 Relational Database DesignUploaded bygretchen_lim_1
- UML Workshop SlidesUploaded bygeodeco
- 3D AR-Based Modeling for Discrete-event Simulation of Transport Operations in ConstructionUploaded byIndonesianRiviera
- UML DiagramsUploaded bycoolguy0007
- ch07Uploaded byAndreas Rousalis
- AIS AssignmentUploaded byDownload
- cse315Uploaded bysigma_amit
- Samsung SP43R1HL1X XEC Shassis J60BUploaded bykorodiferenc9258
- FORTRAN Simulation Environment (FSE)Uploaded byManuel P. Marcaida III
- TPC 5.1.0 UML&SysML WithPapyrus Features TutorialUploaded bybvernay
- UML for DesignersUploaded bylaxmankurnool
- UMLUploaded byIffat Khan
- NotesUploaded bydaselknam
- Formula Sheet Final Exam Fall2011Uploaded byMiki Obmosc
- Flowchart - Wikipedia, The Free EncyclopediaUploaded byjoe smoe
- Sad 1Uploaded byJamal Samatar