Week 12 Ex
Week 12 Ex
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?
int i = 0;
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.)