MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 7 callersFunctiondecimal_to_fraction
Return a decimal number in its simplest fraction form >>> decimal_to_fraction(2) (2, 1) >>> decimal_to_fraction(89.) (89, 1)
maths/decimal_to_fraction.py:1
↓ 7 callersMethodfind
(self, item)
graphs/minimum_spanning_tree_boruvka.py:121
↓ 7 callersFunctiongreatest_common_divisor
Calculate Greatest Common Divisor (GCD). >>> greatest_common_divisor(24, 40) 8 >>> greatest_common_divisor(1, 1) 1 >>> greate
maths/greatest_common_divisor.py:10
↓ 7 callersFunctioninsert
If the binary search tree is empty, make a new node and declare it as root. >>> node_a = BinaryTreeNode(12345) >>> node_b = insert(node_a
data_structures/binary_tree/inorder_tree_traversal_2022.py:17
↓ 7 callersFunctionmatrix_subtraction
(matrix_a: list, matrix_b: list)
divide_and_conquer/strassen_matrix_multiplication.py:26
↓ 7 callersMethodpredict
predict: @param x: a floating point value to predict the label of the prediction function works by recursively calling the pr
machine_learning/decision_tree.py:140
↓ 7 callersFunctionprint_results
(msg: str, passes: bool)
data_structures/binary_tree/red_black_tree.py:684
↓ 7 callersFunctionrabin_karp
The Rabin-Karp Algorithm for finding a pattern within a piece of text with complexity O(nm), most efficient when it is used with multiple pat
strings/rabin_karp.py:7
↓ 7 callersMethodrotate_right
Rotate the subtree rooted at this node to the right and returns the new root to this subtree. Performing one rotation can be done in
data_structures/binary_tree/red_black_tree.py:65
↓ 7 callersMethodset_coefficients
Set the coefficients for the IIR filter. These should both be of size `order` + 1. :math:`a_0` may be left out, and it will u
audio_filters/iir_filter.py:39
↓ 7 callersFunctiontime_func
Times the execution of a function with parameters
maths/fibonacci.py:26
↓ 6 callersMethod__assert_graph_edge_exists_check
( self, undirected_graph: GraphAdjacencyMatrix, directed_graph: GraphAdjacencyMatrix,
graphs/graph_adjacency_matrix.py:205
↓ 6 callersMethod__assert_graph_edge_exists_check
( self, undirected_graph: GraphAdjacencyList, directed_graph: GraphAdjacencyList,
graphs/graph_adjacency_list.py:194
↓ 6 callersFunction_check_not_integer
(matrix: list[list[int]])
matrix/matrix_operation.py:165
↓ 6 callersFunction_read32
(bytestream)
neural_network/input_data.py:41
↓ 6 callersFunctionabs_val
Find the absolute value of a number. >>> abs_val(-5.1) 5.1 >>> abs_val(-5) == abs_val(5) True >>> abs_val(0) 0
maths/abs.py:4
↓ 6 callersMethodadd_edge
Add an edge between two vertices. :param from_vertex: The source vertex. :param to_vertex: The destination vertex.
graphs/depth_first_search_2.py:35
↓ 6 callersMethodadd_edge
adding the edge between two vertices >>> g = Graph() >>> g.print_graph() >>> g.add_edge(0, 1) >>> g.print_gra
graphs/breadth_first_search.py:26
↓ 6 callersMethodcompare_with
Determines the outcome of comparing self hand with other hand. Returns the output as 'Win', 'Loss', 'Tie' according to the rules of
project_euler/problem_054/sol1.py:141
↓ 6 callersMethodconsecutive_orientation
Calculate the cross product of vectors (self -> point_a) and (point_a -> point_b). Returns: - Positive value: counte
geometry/graham_scan.py:91
↓ 6 callersMethodeuclidean_length
returns the euclidean length of the vector >>> Vector([2, 3, 4]).euclidean_length() 5.385164807134504 >>> Vector([1]
linear_algebra/src/lib.py:155
↓ 6 callersMethodexists
Checks if a node exists in the tree >>> t = BinarySearchTree() >>> t.put(8) >>> t.put(10) >>> t.exists(8)
data_structures/binary_tree/binary_search_tree_recursive.py:167
↓ 6 callersFunctionexpectation
>>> from math import isclose >>> isclose(expectation([1, 2], [0.7, 0.3]), 1.3) True
maths/joint_probability_distribution.py:31
↓ 6 callersMethodfind
Returns if the word is on the tree Args: word (str): word to check Returns: bool: True if the word appears o
data_structures/trie/radix_tree.py:102
↓ 6 callersFunctionfind_set
Return the parent of x
data_structures/disjoint_set/disjoint_set.py:42
↓ 6 callersMethodfit
Fits the SVC with a set of observations. Args: observations (list[ndarray]): list of observations classes (n
machine_learning/support_vector_machines.py:101
↓ 6 callersFunctiongcd_by_iterative
Below method is more memory efficient because it does not create additional stack frames for recursive functions calls (as done in the above
maths/greatest_common_divisor.py:39
↓ 6 callersFunctionget_mid
Find the midpoint of two points >>> get_mid((0, 0), (2, 2)) (1.0, 1.0) >>> get_mid((-3, -3), (3, 3)) (0.0, 0.0) >>> get_mid(
fractals/sierpinski_triangle.py:30
↓ 6 callersMethodhash_function
Generates hash for the given key value Examples: Creating HashTable with size 5 >>> ht = HashTable(5) >>> h
data_structures/hashing/hash_table.py:56
↓ 6 callersMethodis_empty
Checks if the deque is empty. Time complexity: O(1) >>> our_deque = Deque([1, 2, 3]) >>> our_deque.is_empty()
data_structures/queues/double_ended_queue.py:336
↓ 6 callersFunctionknuth_morris_pratt
The Knuth-Morris-Pratt Algorithm for finding a pattern within a piece of text with complexity O(n + m) 1) Preprocess pattern to identify
strings/knuth_morris_pratt.py:4
↓ 6 callersFunctionleft_shift
>>> left_shift("0123456789") '1234567890'
other/sdes.py:14
↓ 6 callersFunctionlowest_common_ancestor
Return the lowest common ancestor between u and v >>> level = [-1, 0, 1, 1, 2, 2, 2] >>> parent = [[0, 0, 1, 1, 2, 2, 3],[0, 0, 0, 0, 1,
data_structures/binary_tree/lowest_common_ancestor.py:57
↓ 6 callersFunctionmy_max
(a: int, b: int)
data_structures/binary_tree/avl_tree.py:81
↓ 6 callersFunctionpolar_force
Resolves force along rectangular components. (force, angle) => (force_x, force_y) >>> import math >>> force = polar_force(10, 45)
physics/in_static_equilibrium.py:11
↓ 6 callersFunctionprint_matrix
(matrix: list[list[int]])
matrix/rotate_matrix.py:79
↓ 6 callersMethodput
(self, item, priority)
graphs/multi_heuristic_astar.py:23
↓ 6 callersMethodrefer
Looks for a page in the cache store and adds reference to the set. Remove the least recently used key if the store is full. U
other/least_recently_used.py:50
↓ 6 callersMethodremove_edge
Removes the edge between the two vertices. If any given vertex doesn't exist or the edge does not exist, a ValueError will be thrown.
graphs/graph_adjacency_matrix.py:90
↓ 6 callersMethodremove_edge
Removes the edge between the two vertices. If any given vertex doesn't exist or the edge does not exist, a ValueError will be thrown.
graphs/graph_adjacency_list.py:132
↓ 6 callersMethodrotate_left
Rotate the subtree rooted at this node to the left and returns the new root to this subtree. Performing one rotation can be done in
data_structures/binary_tree/red_black_tree.py:43
↓ 6 callersMethodsearch
Searches for a pattern in the suffix tree. Args: pattern (str): The pattern to search for. Returns:
data_structures/suffix_tree/suffix_tree.py:51
↓ 6 callersMethodset_height
(self, height: int)
data_structures/binary_tree/avl_tree.py:71
↓ 6 callersMethodset_right
(self, node: MyNode | None)
data_structures/binary_tree/avl_tree.py:68
↓ 6 callersFunctionsigmoid
Applies sigmoid activation function. return normalized values >>> sigmoid(np.array(([1, 0, 2], [1, 0, 0]), dtype=np.float64)) array
neural_network/two_hidden_layers_neural_network.py:226
↓ 6 callersFunctionsigmoid_derivative
Provides the derivative value of the sigmoid function. returns derivative of the sigmoid value >>> sigmoid_derivative(np.array(([1, 0,
neural_network/two_hidden_layers_neural_network.py:239
↓ 5 callersFunction_input
(message)
graphs/basic_graphs.py:4
↓ 5 callersMethod_reassign_nodes
(self, node: Node, new_children: Node | None)
data_structures/binary_tree/binary_search_tree_recursive.py:146
↓ 5 callersMethod_swap_nodes
(self, node1_pos: int, node2_pos: int)
graphs/minimum_spanning_tree_prims2.py:175
↓ 5 callersFunctionbucket_sort
>>> data = [-1, 2, -5, 0] >>> bucket_sort(data) == sorted(data) True >>> data = [9, 8, 7, 6, -12] >>> bucket_sort(data) == sorted
sorts/bucket_sort.py:34
↓ 5 callersFunctioncheck_euler
(graph, max_node)
graphs/eulerian_path_and_circuit_for_undirected_graph.py:35
↓ 5 callersFunctioncross
Cross product of elements in A and elements in B. >>> cross('AB', '12') ['A1', 'A2', 'B1', 'B2'] >>> cross('ABC', '123') ['A1',
data_structures/arrays/sudoku_solver.py:11
↓ 5 callersFunctiondecimal_to_octal
Convert a Decimal Number to an Octal Number. >>> all(decimal_to_octal(i) == oct(i) for i ... in (0, 2, 8, 64, 65, 216, 255, 256, 512))
conversions/decimal_to_octal.py:9
↓ 5 callersMethoddelete_nth
Delete and return the data of the node at the nth pos in Circular Linked List. Args: index (int): The index of the node t
data_structures/linked_list/circular_linked_list.py:107
↓ 5 callersMethodempty
Returns True if the tree does not have any element(s). False if the tree has element(s). >>> BinarySearchTree().empty()
data_structures/binary_tree/binary_search_tree.py:156
↓ 5 callersFunctionequation
>>> equation(5) -15 >>> equation(0) 10 >>> equation(-5) -15 >>> equation(0.1) 9.99 >>> equation(-0.1) 9.99
maths/numerical_analysis/bisection_2.py:11
↓ 5 callersMethodfind_next_state
(self, current_state: int, char: str)
strings/aho_corasick.py:17
↓ 5 callersMethodget
>>> queue = LinkedQueue() >>> queue.get() Traceback (most recent call last): ... IndexError: dequeue from
data_structures/queues/linked_queue.py:115
↓ 5 callersMethodget_position
(self, vertex)
graphs/minimum_spanning_tree_prims.py:9
↓ 5 callersMethodinsert
Inserts a node into the Priority Queue. Examples: >>> priority_queue_test = PriorityQueue() >>> priority_queue_test.
graphs/dijkstra_algorithm.py:87
↓ 5 callersFunctioninsert_node
Insert a new node at the end of a linked list and return the new head. Parameters: head (Node | None): The head of the linked list.
data_structures/linked_list/rotate_to_the_right.py:40
↓ 5 callersMethodinsert_tail
Insert data to the end of linked list. >>> linked_list = LinkedList() >>> linked_list.insert_tail("tail") >>> linked_
data_structures/linked_list/singly_linked_list.py:160
↓ 5 callersFunctionkey
(start: TPos, i: int, goal: TPos, g_function: dict[TPos, float])
graphs/multi_heuristic_astar.py:76
↓ 5 callersMethodleft
Returns the left child index for a given index in a binary tree. >>> s = SegmentTree([1, 2, 3]) >>> s.left(1) 2
data_structures/binary_tree/segment_tree.py:14
↓ 5 callersFunctionmatrix_dimensions
(matrix: list)
divide_and_conquer/strassen_matrix_multiplication.py:66
↓ 5 callersMethodminkey
(self)
graphs/multi_heuristic_astar.py:14
↓ 5 callersMethodpush
(self, data: Any)
data_structures/binary_tree/avl_tree.py:25
↓ 5 callersMethodquery
Query the maximum value in the range [a,b]. >>> s = SegmentTree([1, 2, 3, 4, 5]) >>> s.query(1, 3) 3 >>> s.q
data_structures/binary_tree/segment_tree.py:74
↓ 5 callersMethodquery
query(1, 1, size, a, b) for query max of [a,b] >>> A = [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8] >>> segment_tree
data_structures/binary_tree/lazy_segment_tree.py:89
↓ 5 callersMethodright
Returns the right child index for a given index in a binary tree. >>> s = SegmentTree([1, 2, 3]) >>> s.right(1) 3
data_structures/binary_tree/segment_tree.py:26
↓ 5 callersMethodsearch
Searches a node in the tree >>> t = BinarySearchTree() >>> t.put(8) >>> t.put(10) >>> node = t.search(8)
data_structures/binary_tree/binary_search_tree_recursive.py:87
↓ 5 callersMethodset_left
(self, node: MyNode | None)
data_structures/binary_tree/avl_tree.py:65
↓ 5 callersMethodset_position
(self, vertex, pos)
graphs/minimum_spanning_tree_prims.py:12
↓ 5 callersMethodsig
(self, x)
neural_network/convolution_neural_network.py:103
↓ 5 callersFunctionsum_32
Add two numbers as 32-bit ints. Arguments: a {[int]} -- [first given int] b {[int]} -- [second given int] Returns:
hashes/md5.py:228
↓ 5 callersMethodupdate
Set the value of index in O(lg N) Parameters: index (int): index to set value to value (int): value to set i
data_structures/binary_tree/fenwick_tree.py:107
↓ 5 callersFunctionvalidate
Input Parameters: ----------------- effusion_rate_1: Effustion rate of first gas (m^2/s, mm^2/s, etc.) effusion_rate_2: Effustion rat
physics/grahams_law.py:20
↓ 5 callersFunctionvol_sphere
r""" | Calculate the Volume of a Sphere. | Wikipedia reference: https://en.wikipedia.org/wiki/Sphere :return: :math:`\frac{4}{3} \cdot \p
maths/volume.py:319
↓ 4 callersMethod__assert_graph_vertex_exists_check
( self, undirected_graph: GraphAdjacencyMatrix, directed_graph: GraphAdjacencyMatrix,
graphs/graph_adjacency_matrix.py:225
↓ 4 callersMethod__assert_graph_vertex_exists_check
( self, undirected_graph: GraphAdjacencyList, directed_graph: GraphAdjacencyList,
graphs/graph_adjacency_list.py:214
↓ 4 callersMethod__generate_random_edges
( self, vertices: list[int], edge_pick_count: int )
graphs/graph_adjacency_matrix.py:243
↓ 4 callersMethod__generate_random_edges
( self, vertices: list[int], edge_pick_count: int )
graphs/graph_adjacency_list.py:232
↓ 4 callersMethod_e
Two cases: 1: Sample[index] is non-bound, fetch error from list: _error 2: sample[index] is bound, use predicted valu
machine_learning/sequential_minimum_optimization.py:180
↓ 4 callersMethod_is_five_high_straight
(self)
project_euler/problem_054/sol1.py:256
↓ 4 callersFunction_maybe_download
Download the data from source url, unless it's already here. Args: filename: string, name of the file in the directory. work_dire
neural_network/input_data.py:247
↓ 4 callersFunction_subsum
Private helper function to implement the summation functionality. @param digit_pos_to_extract: digit position to extract @param denom
maths/bailey_borwein_plouffe.py:58
↓ 4 callersFunction_validate_point
>>> _validate_point(None) Traceback (most recent call last): ... ValueError: Missing an input >>> _validate_point([1,"one"])
maths/manhattan_distance.py:46
↓ 4 callersMethodadd
(self, value: str)
data_structures/hashing/bloom_filter.py:72
↓ 4 callersMethodadd_node
Adds a new node to the end of the linked list. Args: data (Any): The data to be stored in the new node. Example
data_structures/linked_list/floyds_cycle_detection.py:61
↓ 4 callersFunctionadd_three
Given the numerators and denominators of three fractions, return the numerator and denominator of their sum in lowest form. >>> add_three
project_euler/problem_180/sol1.py:69
↓ 4 callersMethodappendleft
Adds val to the beginning of the deque. Time complexity: O(1) >>> our_deque_1 = Deque([2, 3]) >>> our_deque_1.appendl
data_structures/queues/double_ended_queue.py:141
↓ 4 callersFunctionassign
Eliminate all the other values (except d) from values[s] and propagate. Return values, except return False if a contradiction is detected.
data_structures/arrays/sudoku_solver.py:86
↓ 4 callersMethodassign
Assign values to literals of the clause as given by model.
other/davis_putnam_logemann_loveland.py:61
↓ 4 callersFunctionbenchmark_function
(name: str)
strings/palindrome.py:84
↓ 4 callersFunctionbuild_kdtree
Builds a KD-Tree from a list of points. Args: points: The list of points to build the KD-Tree from. depth: The current depth
data_structures/kd_tree/build_kdtree.py:12
↓ 4 callersMethodclear
Clear the heap. >>> sh = SkewHeap([3, 1, 3, 7]) >>> sh.clear() >>> sh.pop() Traceback (most recent call last
data_structures/heap/skew_heap.py:220
↓ 4 callersFunctionconvert_time
Convert time from one unit to another using the time_chart above. >>> convert_time(3600, "seconds", "hours") 1.0 >>> convert_time(35
conversions/time_conversions.py:25
↓ 4 callersMethoddelete
Deletes a word in a Trie :param word: word to delete :return: None
data_structures/trie/trie.py:49
↓ 4 callersMethoddelete_head
Delete the first node and return the node's data. >>> linked_list = LinkedList() >>> linked_list.insert_tail("first")
data_structures/linked_list/singly_linked_list.py:235
↓ 4 callersMethoddelete_nth
Delete node at given index and return the node's data. >>> linked_list = LinkedList() >>> linked_list.insert_tail("fi
data_structures/linked_list/singly_linked_list.py:289
← previousnext →101–200 of 3,909, ranked by callers