This file contains 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
### | |
# Python 3 - MinHeap | |
# H = [] | |
### | |
def size(H): | |
return len(H) | |
def is_empty(H): | |
return len(H) == 0 | |
def peek(H): | |
return H[0] if len(H) > 0 else None |
This file contains 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
### | |
# Python 3 - MinHeap | |
# H = [] | |
### | |
def size(H): | |
return len(H) | |
def is_empty(H): | |
return len(H) == 0 | |
def peek(H): | |
return H[0] if len(H) > 0 else None |
This file contains 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
### | |
# Python 3 | |
# Q = [ [], [] ] | |
### | |
def size(Q): | |
return len(Q[0]) + len(Q[1]) | |
def is_empty(Q): | |
return (len(Q[0]) + len(Q[1])) == 0 | |
def peek(Q): | |
if len(Q[1]) == 0: |
This file contains 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
### | |
# Python 3 | |
# S = [] | |
### | |
def size(S): | |
return len(S) | |
def is_empty(S): | |
return len(S) == 0 | |
def peek(S): | |
return S[-1] if len(S) > 0 else None |
This file contains 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
### | |
# Python 3 | |
# T = [int, BinarySearchTree, BinarySearchTree, int] or None | |
### | |
def size(T): | |
return T[3] if not T is None else 0 | |
def is_empty(T): | |
return T is None | |
def v(T): | |
return T[0] |
This file contains 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
// Overwrite settings by placing them into your settings file. | |
// See http://go.microsoft.com/fwlink/?LinkId=808995 for the most commonly used settings. | |
{ | |
// Editor | |
// Controls the font family. | |
"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace", | |
// Controls the font weight. |
This file contains 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
# python 3.6.5 | |
# from typing import List | |
def Primes( N: int ) -> List[int]: | |
""" Generates a complete list of primes P s.t. for all p in P, p < N. """ | |
P: List[int] = [] | |
A: List[int] = [ n+1 for n in range( N ) ] | |
for n in range( 1, N+1 ): | |
if A[n-1] == 1: | |
continue | |
P.append( A[n-1] ) |
This file contains 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
# python 3.6.5 | |
# from typing import List | |
def PrimesGen( N: int ) -> List[int]: | |
""" Generates the first N primes starting with 2. """ | |
P: List[int] = [] | |
i: int = 2 | |
while len(P) < N: | |
is_prime: boolean = True | |
for p in P: | |
if i % p == 0: |
This file contains 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
# python 3.6.5 | |
# from typing import List | |
def prod( A: List[int] ) -> int: | |
""" Computes the product of the elements of A. """ | |
if A == None or len(A) == 0: | |
return 0 | |
z: int = 1 | |
for a in A: | |
z *= a | |
return z |
This file contains 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
class Array | |
def prod | |
if self.length == 0 | |
return 0 | |
end | |
z = 1 | |
self.each do |a_i| | |
z *= a_i | |
end | |
return z |
OlderNewer