Data Structure - Chapter 1 Exercises
Data Structure - Chapter 1 Exercises
1. Show Big-O notation for the following: a. 6n2 + 3 b. n2 + 17n + 1 c. 5n3 + 100 n2 - n - 10 d. 3n2 + 2n e. 7n2 + 5 What is the Big-O of the following computation? a)
boolean IsStringHello(String string) { if(string.equals(Hello)) { return true; } return false; }
2.
b)
boolean checkString(String[] strings, String st) { for(int i = 0; i < strings.length; i++) { if(strings[i] == st) { return true; } } return false; }
3.
The following algorithm involves an array of n items. The previous code shows the only repetition in the algorithm, but it does not show the computations that occur within the loops. These computations, however, are independent of n. What is the order of the algorithm?
for (int pass = 1; pass <= n; pass++) { for (int index = 0; index < n; index++) { for (int count = 1; count < 10; count++) { . . . } // end for } // end for } // end for
4.
Consider four programs A, B, C, and Dthat have the following performances: A O(log n) B O(n) C O(n2) D O(2n) If each program requires 10 seconds to solve a problem of size 1000, estimate the time required by each program for a problem of size 2000.
SSK3117/saadah