67 views

Uploaded by JamesRuth

COSC 338 Answers

- Chapter3ProblemsSol.doc
- Time Complexity
- ParallelDesign
- iDENTIFIKASI MASALAH LEAN MANAGEMENT
- Daa Objective
- Intro
- DDI Reward
- CT3 Probability
- Algorithms chapter 1 2 and 3 solutions
- 1403.2777
- Rosenblum
- gw-102
- Gauss User Manual
- SRLG: To Finding the Packet Loss in Peer to Peer Network
- A Quantum Adiabatic Evolution Algorithm Applied to Random Instances of an NP-Complete Problem
- Ch1 System 2010
- Sample Ppr
- How UX Fits in Different Models of SDLC
- The Design of Approximation Algorithms David P. Williamson David B. Shmoys
- 2-Development_Processes.pdf

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

- Chapter3ProblemsSol.docUploaded byadiaz
- Time ComplexityUploaded byRaJu SinGh
- ParallelDesignUploaded byRohit Soren
- iDENTIFIKASI MASALAH LEAN MANAGEMENTUploaded bychelsia
- Daa ObjectiveUploaded bykarunakar
- IntroUploaded byRavi Chandran
- DDI RewardUploaded byBastian Ardi
- CT3 ProbabilityUploaded byNick Papas
- Algorithms chapter 1 2 and 3 solutionsUploaded byprestonchaps
- 1403.2777Uploaded byachmad fitrianto
- RosenblumUploaded byAsseel Fleihan
- gw-102Uploaded byPiyush Puskar
- Gauss User ManualUploaded byMys Genie
- SRLG: To Finding the Packet Loss in Peer to Peer NetworkUploaded byAnonymous lPvvgiQjR
- A Quantum Adiabatic Evolution Algorithm Applied to Random Instances of an NP-Complete ProblemUploaded byfrancisco20047129
- Ch1 System 2010Uploaded bysifusz
- Sample PprUploaded byzawadzahin
- How UX Fits in Different Models of SDLCUploaded byTanvi Sharma
- The Design of Approximation Algorithms David P. Williamson David B. ShmoysUploaded bymrprajesh
- 2-Development_Processes.pdfUploaded byGenie Meca
- Public Ac IonsUploaded byAndreea
- Efficient Multilevel Image ThresholdingUploaded byjebilee
- esortUploaded bycsrinivas.se7878
- Monte Carlo Process FDAUploaded bySai Krishnamurthy
- Np Completeness 2Uploaded bychandan bharti
- FMEA PresentationUploaded byParas Kumar
- Zhang_WRA_01Uploaded byEtzel Santos
- C P MUploaded byrakeshtribhuwan
- SIS.pdfUploaded byNguyễnQuíTrọng
- introfmeaUploaded byGiancarlo Ceron

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

- Adaptive control theory: Direct Self-tuning regulators and Internal ModelUploaded byThanh Nguyen
- entropy reseach paper diUploaded byapi-271566731
- SummaryUploaded byJoey Tan
- Quiz Software EngineeringUploaded bySachin Dev
- Filter Design Hdl CoderUploaded bydwivedi89
- CBSE Papers, Questions, Answers, MCQ ..Uploaded byShailendra Garg
- A Timeline of Management and LeadershipUploaded byshia_pena
- Modular UPS SystemsUploaded bysarang11
- Particle FiltersUploaded byGeorge Mathai
- icwac1407Uploaded byklasicek
- Quantitative ManagementUploaded byZaiEbido
- Mt Slides Logistics (14 NovUploaded byRyan Tw Chouming
- 33.pdfUploaded byKhaoulaMaatoug
- Kriechbaum ThesisUploaded byGabriela Jurcan
- Project Quality ManagementUploaded byMagdy Abd Allh
- Improvement in the Performance of Online Control Applications and OptimizeIT ABB Suite for APCUploaded byquinteroudina
- BPMN2.0Uploaded byRks
- Industrial Automation and Control (Video)Uploaded byRaman Kumar
- An Engineering ApproachUploaded byErnest Appiah
- MSF SFT Practitioner Resource Guide VOL 1 (1)Uploaded byNor Karno
- Michael Zur Muehlen - Workflow-based Process Controlling (Web-Small)Uploaded byAhmad Salah Abd El-Motagaly
- SignalsUploaded byManojSharma
- Vorlesung 8 2009 Class 2dec09Uploaded byNadya Hartasiwi
- NF E 01-010_draftUploaded byhtm64
- 10 Steps to Conduct a DFMEAUploaded byRakesh S India
- Signals %26 Systems EC403Uploaded byShashank M Chanmal
- Business System Analyst Job PurposeUploaded byvmkakumanu
- 2-1 Calculations PFD ang 1.pptxUploaded byhajafar
- Formal_Lab_E1_151012Uploaded byNishant Jalgaonkar
- Wp Electric Machine DesignUploaded byConstantin Dorinel