Last active
          September 14, 2018 12:36 
        
      - 
      
 - 
        
Save fmasanori/333fde85f447c69dcb34b9b5d7782af7 to your computer and use it in GitHub Desktop.  
    BooyerMoore
  
        
  
    
      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
    
  
  
    
  | def boyermoore(p, t): | |
| m = len(p) | |
| n = len(t) | |
| if m > n: return -1 | |
| pulo = [m for k in range(256)] | |
| for k in range(m - 1): | |
| pulo[ord(p[k])] = m - k - 1 | |
| pulo = tuple(pulo) | |
| k = m - 1 | |
| while k < n: | |
| j = m - 1 | |
| i = k | |
| while j >= 0 and t[i] == p[j]: | |
| j -= 1 | |
| i -= 1 | |
| if j == -1: return i + 1 | |
| k += pulo[ord(t[k])] | |
| return -1 | |
| texto = 'os algoritmos de ordenação' | |
| palavra = 'algoritmo' | |
| print (boyermoore(palavra, texto)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment