Created
January 27, 2017 01:29
-
-
Save tmosest/2dc1d7fd3062b5626e7877973d911641 to your computer and use it in GitHub Desktop.
Example 1 Big O vs Big Theta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Same worst case and best case | |
public static boolean detectCharacter(String s, char c) | |
{ | |
boolean hasCharacter = false; | |
for(int i = 0; i < s.length(); i++) { | |
if(s.charAt(i) == c) hasCharacter = true; | |
} | |
return hasCharacter; | |
} | |
// Different best case and worse case | |
public static boolean detectCharacter(String s, char c) | |
{ | |
for(int i = 0; i < s.length(); i++) { | |
if(s.charAt(i) == c) return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment