{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 2 - Family Name m Given Name(b For each of the following...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Family Name: m Given Name: (b) For each of the following program segments, give the worst-ewe running time in terms of the parameter In and using B-notation. Answer in the space provided. Do not add. comments or explanations. i. public static int f_1(int n) { int x = 0; I for(intli=0;i<n*n;i+=2) //25’ x++; return x; } Running time of fl is in 6( ii. public static int f2(int n) { int x = 0; for (inti=1; i<n¥n; it=2) x++; return I; } Running time 0H2 is in 6( iii. public static int f3(int n) {intx=0; for(inti=0;1<n¥n¥n;i++) for (intj=1;j<n;j*=2) x++; return 3: } Running time of B is in 9[ iv. public static int f4(int n) {intx=0: for(inti=0;i< ntntn; 1H) for (1ntj=o;j<i;j+=2) 1:“; return x; } Running time of f4 is in B( v. public static int f5(int n) { int 1-0; for (inti=n; i>1; 1/22) for(intj*1;j<n:1*‘2) x++; returnx; Running time of i5 is in 8( Page 3 of 10 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online