Notre Dame University-Louaize
Computer Science Department
CSC 414 Operating Systems
Exam 1, Fall 2012
1. What is the complexity of
1
2
3
4
5
6
7
f o r ( i =1; i<=n ; i ++){
j =1;
while ( j < i ){
j =2;
sum+=1;
}
}
2. What is the complexity of
1
2
3
4
5
6
7
8
i n t i , j , k , count =0;
f o r ( i =1; i<=n ; i ++){
f o r ( j =1; j<=n ; j ++){
f o r ( k=1;k<=n ; k =2)[
count++;
}
}
}
3. What is the complexity of
1
2
3
4
5
6
7
8
i n t i , j , k , count =0;
f o r ( i =1; i<=n ; i ++){
f o r ( j =1; j<=n ; j =2){
f o r ( k=1;k<=n ; k =2)[
count++;
}
}
}
4. Write a C++ implementation of the two solutions for the max subsequent sum problem
( brute force and the divide-and-conquer). Use your C++ implementation to compute
the max subsequent sum of the provided input (a column of numbers where the first one
denotes the total number of entries in the sequence and the remaining ones are the values
of the elements of the sequence). What is the running time of each implementation?