0% found this document useful (0 votes)
0 views

Week 12 Ex

Exercises Programming

Uploaded by

info.bptrades
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Week 12 Ex

Exercises Programming

Uploaded by

info.bptrades
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CMPT130 J.

Ye

Week 12 Practice
1. For the following function/algorithm, all the operations that we are counting for the worst case time complexity are
circled as follows, what is the worst case scenario in terms of time complexity? What is the exact worst case time
complexity expressed as a function of N given the length of the array is N (= size)? What about the best case scenario?

bool hasOdd (int arr[], int size)


{

bool foundOdd = false;

int i = 0;

while (i < size)


{

if (arr[i] % 2 != 0)

foundOdd = true;

++ i;
}

return foundOdd;
}

2. Modify the binary_search function provided in Week 12 Handout 2 such that it uses only one return statement
and without using break.

3. Implement Bubble sort algorithm. (To trace how the array is changed, you can insert cout statement in the loop.)

You might also like