MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 636 callersMethodappend
Adds val to the end of the deque. Time complexity: O(1) >>> our_deque_1 = Deque([1, 2, 3]) >>> our_deque_1.append(4)
data_structures/queues/double_ended_queue.py:99
↓ 158 callersMethodsplit
(self, block_size, sort_key=None)
sorts/external_sort.py:26
↓ 126 callersMethodpop
Pop an element off of the top of the stack. >>> S = Stack() >>> S.push(-5) >>> S.push(10) >>> S.pop()
data_structures/stacks/stack.py:57
↓ 110 callersMethodappend
Adds Operation object to the related Variable objects for creating computational graph for calculating gradients. Args:
machine_learning/automatic_differentiation.py:221
↓ 97 callersMethodadd
Adds the given node to the end of the list (before rear)
other/lru_cache.py:112
↓ 89 callersMethodget
Returns the value for the input key and updates the Double Linked List. Returns None if key is not present in cache
other/lru_cache.py:246
↓ 59 callersMethodcount
(self)
data_structures/binary_tree/avl_tree.py:34
↓ 46 callersMethodinsert
Inserts label into the subtree rooted at self, performs any rotations necessary to maintain balance, and then returns the new root t
data_structures/binary_tree/red_black_tree.py:87
↓ 45 callersMethodfind
Tries to find word in a Trie :param word: word to look for :return: Returns True if word is found, False otherwise
data_structures/trie/trie.py:36
↓ 40 callersMethodsort
(self, filename, sort_key=None)
sorts/external_sort.py:113
↓ 37 callersMethodcopy
copies this vector and returns it.
linear_algebra/src/lib.py:129
↓ 37 callersMethodinsert
:param key: Key to insert. :param value: Value associated with given key. >>> skip_list = SkipList() >>> skip_list.i
data_structures/linked_list/skip_list.py:189
↓ 35 callersMethodremove
Removes and returns the given node from the list Returns None if node.prev or node.next is None
other/lru_cache.py:127
↓ 29 callersMethodshow
(self)
machine_learning/astar.py:58
↓ 27 callersFunctionfunction
(expansion, s0, s1, key, message)
other/sdes.py:42
↓ 26 callersMethodput
Put a new node in the tree >>> t = BinarySearchTree() >>> t.put(8) >>> assert t.root.parent is None >>> asse
data_structures/binary_tree/binary_search_tree_recursive.py:55
↓ 25 callersFunctionget_height
(node: MyNode | None)
data_structures/binary_tree/avl_tree.py:75
↓ 24 callersMethodfind
:param key: Search key. :return: Value associated with given key or None if given key is not present. >>> skip_list = SkipLi
data_structures/linked_list/skip_list.py:226
↓ 24 callersFunctionis_prime
Checks to see if a number is a prime in O(sqrt(n)). A number is prime if it has exactly two factors: 1 and itself. >>> is_prime(0) False
maths/prime_check.py:9
↓ 23 callersFunctioncolor
Returns the color of a node, allowing for None leaves.
data_structures/binary_tree/red_black_tree.py:512
↓ 23 callersMethodextend
Appends every value of iterable to the end of the deque. Time complexity: O(n) >>> our_deque_1 = Deque([1, 2, 3]) >>>
data_structures/queues/double_ended_queue.py:183
↓ 23 callersFunctionsin
Implement sin function. >>> sin(0.0) 0.0 >>> sin(90.0) 1.0 >>> sin(180.0) 0.0 >>> sin(270.0) -1.0 >>> sin(0.
maths/sin.py:17
↓ 22 callersFunctionfunc
(x: float)
maths/numerical_analysis/newton_raphson.py:107
↓ 21 callersFunctionfactorial
input: positive integer 'n' returns the factorial of 'n' (n!) >>> factorial(0) 1 >>> factorial(20) 2432902008176640000 >
maths/primelib.py:767
↓ 20 callersMethodjson
(self)
web_programming/test_fetch_github_info.py:14
↓ 20 callersFunctionmiller_rabin
Deterministic Miller-Rabin algorithm for primes ~< 3.32e24. Uses numerical analysis results to return whether or not the passed number is pri
ciphers/deterministic_miller_rabin.py:6
↓ 19 callersMethodget_left
(self)
data_structures/binary_tree/avl_tree.py:53
↓ 19 callersMethodget_right
(self)
data_structures/binary_tree/avl_tree.py:56
↓ 19 callersMethodplot
Plot the membership function of the fuzzy set.
fuzzy_logic/fuzzy_operations.py:159
↓ 19 callersMethodput
(self, item: Any)
data_structures/queues/queue_on_pseudo_stack.py:19
↓ 18 callersMethodreverse
This reverses the linked list order. >>> linked_list = LinkedList() >>> linked_list.insert_tail("first") >>> linked_l
data_structures/linked_list/singly_linked_list.py:337
↓ 17 callersMethodinsert
(self, val: int)
sorts/tree_sort.py:29
↓ 17 callersMethodpopleft
Removes the first element of the deque and returns it. Time complexity: O(1) @returns topop.val: the value of the node to pop
data_structures/queues/double_ended_queue.py:290
↓ 17 callersMethodtranspose
<method Matrix.transpose> Return self^T. Example: >>> a = Matrix(2, 3) >>> for r in range(2): ...
matrix/sherman_morrison.py:180
↓ 16 callersMethodcomponent
input: index (0-indexed) output: the i-th component of the vector.
linear_algebra/src/lib.py:135
↓ 16 callersFunctiongraham_scan
Find the convex hull of a set of points using the Graham scan algorithm. The algorithm works as follows: 1. Find the bottom-most point (
geometry/graham_scan.py:113
↓ 16 callersFunctionprompt
(s: str = "", width=50, char="*")
searches/binary_tree_traversal.py:261
↓ 15 callersMethodappend
Appends a new node with the given data to the end of the LinkedList. >>> linked_list = LinkedList() >>> str(linked_list) ''
data_structures/linked_list/print_reverse.py:54
↓ 15 callersMethodempty
(self)
graphs/multi_heuristic_astar.py:20
↓ 14 callersMethodadd_edge
Add edge going from node u to v and v to u with weight w: u (w)-> v, v (w) -> u Examples: >>> graph_test = Graph(1)
graphs/dijkstra_algorithm.py:235
↓ 14 callersMethodcontains_vertex
Returns True if the graph contains the vertex, False otherwise.
graphs/graph_adjacency_matrix.py:165
↓ 14 callersMethodcontains_vertex
Returns True if the graph contains the vertex, False otherwise.
graphs/graph_adjacency_list.py:159
↓ 14 callersMethodfloor
Returns the largest element in this tree which is at most label. This method is guaranteed to run in O(log(n)) time.
data_structures/binary_tree/red_black_tree.py:367
↓ 14 callersMethodget
(self)
graphs/multi_heuristic_astar.py:53
↓ 13 callersMethodkeys
The keys function returns a dictionary containing the key value pairs. key being the index number in hash table and value being the d
data_structures/hashing/hash_table.py:25
↓ 13 callersFunctionrandom
(chars_incl: str, i: int)
other/password.py:50
↓ 12 callersMethodcontains_edge
Returns True if the graph contains the edge from the source_vertex to the destination_vertex, False otherwise. If any given vertex do
graphs/graph_adjacency_matrix.py:171
↓ 12 callersMethodcontains_edge
Returns True if the graph contains the edge from the source_vertex to the destination_vertex, False otherwise. If any given vertex do
graphs/graph_adjacency_list.py:165
↓ 12 callersMethoddelete
:param key: Key to remove from list. >>> skip_list = SkipList() >>> skip_list.insert(2, "Two") >>> skip_list.insert(
data_structures/linked_list/skip_list.py:163
↓ 12 callersMethodremove
Removes a node in the tree >>> t = BinarySearchTree() >>> t.put(8) >>> t.put(10) >>> t.remove(8) >>>
data_structures/binary_tree/binary_search_tree_recursive.py:115
↓ 12 callersMethodscore
Returns the output of the function called with current x and y coordinates. >>> def test_function(x, y): ... return x + y
searches/hill_climbing.py:25
↓ 12 callersFunctionsignum
Applies signum function on the number Custom test cases: >>> signum(-10) -1 >>> signum(10) 1 >>> signum(0) 0 >>>
maths/signum.py:6
↓ 12 callersMethodto_ndarray
(self)
machine_learning/automatic_differentiation.py:62
↓ 11 callersFunction_set
(k, v)
data_structures/hashing/tests/test_hash_map.py:12
↓ 11 callersMethodadd_edge
Adds a directed edge from node u to node v with weight w. >>> g = Graph(3) >>> g.add_edge(0, 1, 5) >>>
dynamic_programming/floyd_warshall.py:14
↓ 11 callersFunctionis_prime
input: positive integer 'number' returns true if 'number' is prime otherwise false. >>> is_prime(3) True >>> is_prime(10) Fa
maths/primelib.py:45
↓ 11 callersFunctionjarvis_march
Find the convex hull of a set of points using the Jarvis March algorithm. The algorithm starts with the leftmost point and wraps around the
geometry/jarvis_march.py:120
↓ 11 callersMethodleft
>>> segment_tree = SegmentTree(15) >>> segment_tree.left(1) 2 >>> segment_tree.left(2) 4 >>> segment_
data_structures/binary_tree/lazy_segment_tree.py:15
↓ 11 callersMethodmain
Utilize various methods in this class to simulate the Banker's algorithm :Return: None >>> BankersAlgorithm(test_claim_v
other/bankers_algorithm.py:103
↓ 11 callersFunctionmatrix_addition
(matrix_a: list, matrix_b: list)
divide_and_conquer/strassen_matrix_multiplication.py:19
↓ 11 callersMethodpush
Push an element to the top of the stack. >>> S = Stack(2) # stack size = 2 >>> S.push(10) >>> S.push(20) >>>
data_structures/stacks/stack.py:35
↓ 11 callersMethodright
>>> segment_tree = SegmentTree(15) >>> segment_tree.right(1) 3 >>> segment_tree.right(2) 5 >>> segmen
data_structures/binary_tree/lazy_segment_tree.py:27
↓ 11 callersMethodrun
Emulate time passing by looping `iteration_count` times >>> wt = WaTor(WIDTH, HEIGHT) >>> wt.run(iteration_count=PREDATOR_IN
cellular_automata/wa_tor.py:431
↓ 10 callersMethod_get_binary_search_tree
r""" 8 / \ 3 10 / \ \ 1 6 14 / \ / 4 7 13
data_structures/binary_tree/binary_search_tree_recursive.py:281
↓ 10 callersMethoddequeue
Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised.
data_structures/queues/priority_queue_using_list.py:89
↓ 10 callersMethoddequeue
Return the highest priority element in FIFO order. If the queue is empty then an under flow exception is raised.
data_structures/queues/priority_queue_using_list.py:161
↓ 10 callersMethodencode
Return the encoded version of message according to the polybius cipher >>> BifidCipher().encode('testmessage') == 'qtltbdxrxlk'
ciphers/bifid.py:54
↓ 10 callersMethodexists
(self, value: str)
data_structures/hashing/bloom_filter.py:76
↓ 10 callersMethodget_data
(self)
data_structures/binary_tree/avl_tree.py:50
↓ 10 callersFunctionpoints_to_polynomial
coordinates is a two dimensional matrix: [[x, y], [x, y], ...] number of points you want to use >>> points_to_polynomial([]) Traceba
linear_algebra/src/polynom_for_points.py:1
↓ 10 callersMethodror
Right rotate a given unsigned number by a certain amount of rotations
hashes/sha256.py:190
↓ 9 callersMethod__generate_graphs
( self, vertex_count: int, min_val: int, max_val: int, edge_pick_count: int )
graphs/graph_adjacency_matrix.py:262
↓ 9 callersMethod__generate_graphs
( self, vertex_count: int, min_val: int, max_val: int, edge_pick_count: int )
graphs/graph_adjacency_list.py:251
↓ 9 callersFunctionapply_table
>>> apply_table("0123456789", list(range(10))) '9012345678' >>> apply_table("0123456789", list(range(9, -1, -1))) '8765432109'
other/sdes.py:1
↓ 9 callersFunctioncolumn_reshape
Function to reshape a row Numpy array into a column Numpy array >>> input_array = np.array([1, 2, 3]) >>> column_reshape(input_array) arra
machine_learning/dimensionality_reduction.py:20
↓ 9 callersFunctiondecimal_isolate
Isolates the decimal part of a number. If digitAmount > 0 round to that decimal place, else print the entire decimal. >>> decimal_isolate
maths/decimal_isolate.py:7
↓ 9 callersMethoddecode
Return the decoded version of message according to the polybius cipher >>> BifidCipher().decode('qtltbdxrxlk') == 'testmessage'
ciphers/bifid.py:88
↓ 9 callersMethodenqueue
Add an element to a queue based on its priority. If the priority is invalid ValueError is raised. If the queue is full an Ove
data_structures/queues/priority_queue_using_list.py:76
↓ 9 callersMethodenqueue
This function enters the element into the queue If the queue is full an Exception is raised saying Over Flow!
data_structures/queues/priority_queue_using_list.py:152
↓ 9 callersFunctionfloor
Return the floor of x as an Integral. :param x: the number :return: the largest integer <= x. >>> import math >>> all(floor(n) ==
maths/floor.py:6
↓ 9 callersFunctionmean
Find mean of a list of numbers. Wiki: https://en.wikipedia.org/wiki/Mean >>> mean([3, 6, 9, 12, 15, 18, 21]) 12.0 >>> mean([5, 1
maths/average_mean.py:4
↓ 9 callersFunctionradians
Converts the given angle from degrees to radians https://en.wikipedia.org/wiki/Radian >>> radians(180) 3.141592653589793 >>> rad
maths/radians.py:4
↓ 8 callersFunction_det
Computes the sign perpendicular distance of a 2d point c from a line segment ab. The sign indicates the direction of c relative to ab. A
divide_and_conquer/convex_hull.py:188
↓ 8 callersFunctionceil
Return the ceiling of x as an Integral. :param x: the number :return: the smallest integer >= x. >>> import math >>> all(ceil(n
maths/ceil.py:6
↓ 8 callersMethodceil
Returns the smallest element in this tree which is at least label. This method is guaranteed to run in O(log(n)) time.
data_structures/binary_tree/red_black_tree.py:384
↓ 8 callersFunctionf
(x: float)
maths/numerical_analysis/bisection.py:46
↓ 8 callersMethodget
(self)
data_structures/queues/queue_on_pseudo_stack.py:28
↓ 8 callersFunctionget_neighbors_pixel
Comparing local neighborhood pixel value with threshold value of centre pixel. Exception is required when neighborhood value of a center pixe
digital_image_processing/filters/local_binary_pattern.py:5
↓ 8 callersMethodis_empty
Check if a stack is empty. >>> S = Stack() >>> S.is_empty() True >>> S = Stack() >>> S.push(10)
data_structures/stacks/stack.py:95
↓ 8 callersMethodis_left
Returns true iff this node is the left child of its parent.
data_structures/binary_tree/red_black_tree.py:440
↓ 8 callersMethodpeek
Peek at the top-most element of the stack. >>> S = Stack() >>> S.push(-5) >>> S.push(10) >>> S.peek()
data_structures/stacks/stack.py:76
↓ 8 callersMethodremove_vertex
Removes the given vertex from the graph and deletes all incoming and outgoing edges from the given vertex as well. If the given verte
graphs/graph_adjacency_matrix.py:135
↓ 8 callersMethodremove_vertex
Removes the given vertex from the graph and deletes all incoming and outgoing edges from the given vertex as well. If the given verte
graphs/graph_adjacency_list.py:107
↓ 7 callersFunction_del
(k)
data_structures/hashing/tests/test_hash_map.py:16
↓ 7 callersMethod_is_unbound
(self, index)
machine_learning/sequential_minimum_optimization.py:385
↓ 7 callersMethodadd_edge
Creates an edge from source vertex to destination vertex. If any given vertex doesn't exist or the edge already exists, a ValueError
graphs/graph_adjacency_matrix.py:61
↓ 7 callersMethodadd_edge
Creates an edge from source vertex to destination vertex. If any given vertex doesn't exist or the edge already exists, a ValueError
graphs/graph_adjacency_list.py:79
↓ 7 callersMethodadd_vertex
Adds a vertex to the graph. If the given vertex already exists, a ValueError will be thrown.
graphs/graph_adjacency_matrix.py:118
↓ 7 callersMethodadd_vertex
Adds a vertex to the graph. If the given vertex already exists, a ValueError will be thrown. >>> g = GraphAdjacencyList(vert
graphs/graph_adjacency_list.py:60
↓ 7 callersFunctioncombinations
Returns the number of different combinations of k length which can be made from n values, where n >= k. Examples: >>> combinations(1
maths/combinations.py:6
next →1–100 of 3,909, ranked by callers