Skip to content

Instantly share code, notes, and snippets.

@tmosest
Created January 27, 2017 01:29
Show Gist options
  • Save tmosest/2dc1d7fd3062b5626e7877973d911641 to your computer and use it in GitHub Desktop.
Save tmosest/2dc1d7fd3062b5626e7877973d911641 to your computer and use it in GitHub Desktop.
Example 1 Big O vs Big Theta
// 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