This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: d) Let s.length() = n The first line is an array declaration that only takes place once. The first for loop iterates s.length() times, and inside it, the array attribution only takes place once. O(n) c.length = s.length() = n the second for loop iterates n times. the third for loop which is nested into the second, occurs k times inside the third loop, there is a condition that can occur once or not at all, and inside it, an addition O(1). worst case: O(n + n*n) = O(n^2 + n) = O(n^2) Best case: if the string is only one character O(1) e) let big.length()-small.length() = n the first for loop iterates n times inside the loop there is a method call and a condition if there is a specific string inside a bigger string, the program returns the place where it begins worst case = O(n) if there is no "small" that equals "partOfBig" string. Sheet1 Page 2 best case = O(1) if the small string is the first part of the big string, and everything iterates only once....
View Full Document
This note was uploaded on 11/03/2009 for the course CS 01-111 taught by Professor Pradiphari during the Fall '09 term at Rutgers.
- Fall '09
- Computer Science