0% found this document useful (0 votes)
35 views1 page

Data Structure - Chapter 1 Exercises

1. The Big-O of the examples provided are: a) O(n^2) b) O(n^2) c) O(n^3) d) O(n^2) e) O(n^2). The algorithms in questions 1a and 1b are both O(1). The nested for loops in question 3 make the algorithm O(n^3). Question 4 estimates that programs A, B, C, and D would take approximately 20, 40, 400, and 10240 seconds respectively to solve a problem of size 2000 based on their known complexities and the given time of 10 seconds for a problem size of 1000.

Uploaded by

rockers91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Data Structure - Chapter 1 Exercises

1. The Big-O of the examples provided are: a) O(n^2) b) O(n^2) c) O(n^3) d) O(n^2) e) O(n^2). The algorithms in questions 1a and 1b are both O(1). The nested for loops in question 3 make the algorithm O(n^3). Question 4 estimates that programs A, B, C, and D would take approximately 20, 40, 400, and 10240 seconds respectively to solve a problem of size 2000 based on their known complexities and the given time of 10 seconds for a problem size of 1000.

Uploaded by

rockers91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like