Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 592 Bytes

Problem2.md

File metadata and controls

35 lines (29 loc) · 592 Bytes

How do the following behave for large values of n? Give answers in big-O notation: eg. O(n2)

a.

for (int x=0; x<n; x++) {
  for (int y=n; y>0; y--) {
    data[x]  =  data[y]; 
  }
}

| |

b.

for (int x=0; x<n; x++) {
  for (int y=1; y<n; y *= 2) {
    data[x]  =  data[y]; 
  }
}

| |

c.

for (int x=0; x<n; x++) {
  data[x]  =  data[n-x];
}
for (int y=n; y>0; y /= 2) {
  data[y]  =  data[n-y];
}

| |