MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 4 callersMethoddelete_tail
Delete the tail end node and return the node's data. >>> linked_list = LinkedList() >>> linked_list.insert_tail("firs
data_structures/linked_list/singly_linked_list.py:262
↓ 4 callersFunctiondirection
Return the cross product of vectors (pivot->query) and (pivot->target). The sign of the result encodes the orientation of the ordered triple
geometry/segment_intersection.py:30
↓ 4 callersFunctionelapsed_time
(msg: str)
dynamic_programming/matrix_chain_multiplication.py:131
↓ 4 callersMethodempty
Empties the tree >>> t = BinarySearchTree() >>> assert t.root is None >>> t.put(8) >>> assert t.root is not
data_structures/binary_tree/binary_search_tree_recursive.py:31
↓ 4 callersMethodeuclidean_distance
Calculate Euclidean distance between two points. >>> Point(0, 0).euclidean_distance(Point(3, 4)) 5.0 >>> Point(1, 1)
geometry/graham_scan.py:80
↓ 4 callersMethodfind_set
(self, data: T)
graphs/minimum_spanning_tree_kruskal2.py:26
↓ 4 callersFunctiongamma
Calculate the Lorentz factor y = 1 / √(1 - v²/c²) for a given velocity >>> gamma(4) 1.0000000000000002 >>> gamma(1e5) 1.000000055
physics/lorentz_transformation_four_vector.py:64
↓ 4 callersMethodget_entities
Returns a list of all the entities within the planet. >>> wt = WaTor(WIDTH, HEIGHT) >>> len(wt.get_entities()) == PREDATOR_I
cellular_automata/wa_tor.py:173
↓ 4 callersMethodget_max_label
Gets the max label inserted in the tree >>> t = BinarySearchTree() >>> t.get_max_label() Traceback (most recent call
data_structures/binary_tree/binary_search_tree_recursive.py:186
↓ 4 callersMethodget_min_label
Gets the min label inserted in the tree >>> t = BinarySearchTree() >>> t.get_min_label() Traceback (most recent call
data_structures/binary_tree/binary_search_tree_recursive.py:210
↓ 4 callersMethodheapify
(self, heap, positions)
graphs/minimum_spanning_tree_prims.py:63
↓ 4 callersMethodheight
getter for the height
linear_algebra/src/lib.py:353
↓ 4 callersFunctionimg_convolve
(image, filter_kernel)
digital_image_processing/filters/convolve.py:23
↓ 4 callersMethodinsert
Insert new element
data_structures/heap/max_heap.py:32
↓ 4 callersMethodinsert_head
Insert data to the beginning of linked list. >>> linked_list = LinkedList() >>> linked_list.insert_head("head") >>> l
data_structures/linked_list/singly_linked_list.py:176
↓ 4 callersMethodinsert_nth
Insert the data of the node at the nth pos in the Circular Linked List. Args: index: The index at which the data should b
data_structures/linked_list/circular_linked_list.py:58
↓ 4 callersFunctionint_to_base
Convert a given positive decimal integer to base 'base'. Where 'base' ranges from 2 to 36. Examples: >>> int_to_base(0, 21) '0'
maths/special_numbers/harshad_numbers.py:8
↓ 4 callersMethodis_empty
(self)
data_structures/linked_list/deque_doubly.py:37
↓ 4 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. Returns boolean representin
project_euler/problem_003/sol1.py:17
↓ 4 callersMethodis_right
Returns true iff this node is the right child of its parent.
data_structures/binary_tree/red_black_tree.py:446
↓ 4 callersFunctionis_sq
Check if number is a perfect square. >>> is_sq(1) True >>> is_sq(1000001) False >>> is_sq(1000000) True
project_euler/problem_180/sol1.py:54
↓ 4 callersFunctioniterate_function
Iterate the function "eval_function" exactly nb_iterations times. The first argument of the function is a parameter which is contained in
fractals/julia_sets.py:85
↓ 4 callersFunctionleft_rotation
a mirror symmetry rotation of the left_rotation
data_structures/binary_tree/avl_tree.py:110
↓ 4 callersFunctionmaclaurin_cos
Finds the maclaurin approximation of cos :param theta: the angle to which cos is found :param accuracy: the degree of accuracy wante
maths/maclaurin_series.py:60
↓ 4 callersFunctionmaclaurin_sin
Finds the maclaurin approximation of sin :param theta: the angle to which sin is found :param accuracy: the degree of accuracy wante
maths/maclaurin_series.py:8
↓ 4 callersMethodmax_heapify
correct a single violation of the heap property in a subtree's root. It is the function that is responsible for restoring the proper
data_structures/heap/heap.py:111
↓ 4 callersFunctionmedian_of_five
Return the median of the input list :param arr: Array to find median of :return: median of arr >>> median_of_five([2, 4, 5, 7, 899])
searches/median_of_medians.py:12
↓ 4 callersMethodminors
(self)
matrix/matrix_class.py:195
↓ 4 callersFunctionon_segment
Check whether *point*, known to be collinear with the segment, lies on it. >>> on_segment(Point(0, 0), Point(4, 4), Point(2, 2)) True >>>
geometry/segment_intersection.py:51
↓ 4 callersMethodpop
Removes the last 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:241
↓ 4 callersMethodpop
Pop the smallest value from the heap and return it. >>> sh = SkewHeap([3, 1, 3, 7]) >>> sh.pop() 1 >>> sh.po
data_structures/heap/skew_heap.py:173
↓ 4 callersMethodpop
(self)
data_structures/binary_tree/avl_tree.py:29
↓ 4 callersFunctionprime_factorization
input: positive integer 'number' returns a list of the prime number factors of 'number' >>> prime_factorization(0) [0] >>> prime
maths/primelib.py:179
↓ 4 callersMethodprint_list
This method prints every node data. >>> linked_list = LinkedList() >>> linked_list.insert_tail("first") >>> linked_li
data_structures/linked_list/singly_linked_list.py:223
↓ 4 callersMethodpush
add a Node to the stack
data_structures/stacks/stack_with_doubly_linked_list.py:47
↓ 4 callersFunctionreformat_hex
Converts the given non-negative integer to hex string. Example: Suppose the input is the following: i = 1234 The input is 0
hashes/md5.py:46
↓ 4 callersFunctionright_rotation
r""" A B / \ / \ B C Bl A / \ -->
data_structures/binary_tree/avl_tree.py:87
↓ 4 callersMethodrotate
Static method to be used inside other methods. Left rotates n by b. >>> SHA1Hash('').rotate(12,2) 48
hashes/sha1.py:53
↓ 4 callersFunctionshow_results
Plots of whether the absolute value of z_final is greater than the value of escape_radius. Adds the function_label and function_params to
fractals/julia_sets.py:127
↓ 4 callersFunctionsimulated_annealing
Implementation of the simulated annealing algorithm. We start with a given state, find all its neighbors. Pick a random neighbor, if that nei
searches/simulated_annealing.py:9
↓ 4 callersMethodsize
Return the size of the stack. >>> S = Stack(3) >>> S.size() 0 >>> S = Stack(3) >>> S.push(10)
data_structures/stacks/stack.py:123
↓ 4 callersFunctiontransform
Simple image transformation using one of two available filter functions: Erosion and Dilation. Args: image: binarized input imag
computer_vision/haralick_descriptors.py:104
↓ 4 callersFunctionunion_set
Union of two sets. set with bigger rank should be parent, so that the disjoint set tree will be more flat.
data_structures/disjoint_set/disjoint_set.py:24
↓ 4 callersFunctionvalid_input
Ask for user value and validate that it fulfill a condition. :input_type: user input expected type of value :input_msg: message to show
machine_learning/linear_discriminant_analysis.py:251
↓ 4 callersFunctionvariance
>>> from math import isclose >>> isclose(variance([1,2],[0.7,0.3]), 0.21) True
maths/joint_probability_distribution.py:41
↓ 4 callersFunctionvector_product
Return the 2-d vector product of two vectors. >>> vector_product((1, 2), (-5, 0)) 10 >>> vector_product((3, 1), (6, 10)) 24
project_euler/problem_102/sol1.py:27
↓ 4 callersMethodwidth
getter for the width
linear_algebra/src/lib.py:359
↓ 3 callersMethod__assert_graph_edge_does_not_exist_check
( self, undirected_graph: GraphAdjacencyMatrix, directed_graph: GraphAdjacencyMatrix,
graphs/graph_adjacency_matrix.py:215
↓ 3 callersMethod__assert_graph_edge_does_not_exist_check
( self, undirected_graph: GraphAdjacencyList, directed_graph: GraphAdjacencyList,
graphs/graph_adjacency_list.py:204
↓ 3 callersMethod__assert_graph_vertex_does_not_exist_check
( self, undirected_graph: GraphAdjacencyMatrix, directed_graph: GraphAdjacencyMatrix,
graphs/graph_adjacency_matrix.py:234
↓ 3 callersMethod__assert_graph_vertex_does_not_exist_check
( self, undirected_graph: GraphAdjacencyList, directed_graph: GraphAdjacencyList,
graphs/graph_adjacency_list.py:223
↓ 3 callersMethod__need
Implement safety checker that calculates the needs by ensuring that ``max_claim[i][j] - alloc_table[i][j] <= avail[j]``
other/bankers_algorithm.py:76
↓ 3 callersMethod__reassign_nodes
(self, node: Node, new_children: Node | None)
data_structures/binary_tree/binary_search_tree.py:145
↓ 3 callersMethod_bubble_down
(self, elem: T)
graphs/minimum_spanning_tree_prims2.py:148
↓ 3 callersMethod_cmp
Compares the two items using default comparison
data_structures/heap/heap_generic.py:45
↓ 3 callersFunction_enforce_args
Basic checks on the arguments to the rod-cutting algorithms * `n`: int, the length of the rod * `prices`: list, the price list for each
dynamic_programming/rod_cutting.py:177
↓ 3 callersMethod_heapify_up
Fixes the heap in upward direction of given index
data_structures/heap/heap_generic.py:65
↓ 3 callersMethod_is_straight
(self)
project_euler/problem_054/sol1.py:273
↓ 3 callersMethod_iterate_buckets
(self, key: KEY)
data_structures/hashing/hash_map.py:128
↓ 3 callersMethod_locate_node
:param key: Searched key, :return: Tuple with searched node (or None if given key is not present) and list of nodes
data_structures/linked_list/skip_list.py:128
↓ 3 callersFunction_validate_dict
>>> _validate_dict({"b": 0.5}, "mock_name", float) >>> _validate_dict("invalid", "mock_name", float) Traceback (most recent call last):
dynamic_programming/viterbi.py:340
↓ 3 callersFunction_validate_input
validates an input instance before a convex-hull algorithms uses it Parameters --------- points: array-like, the 2d points to valida
divide_and_conquer/convex_hull.py:135
↓ 3 callersFunction_verify_matrix_sizes
( matrix_a: list[list[int]], matrix_b: list[list[int]] )
matrix/matrix_operation.py:173
↓ 3 callersMethodadd
Adds the given node at the tail of the list and shifting it to proper position
other/lfu_cache.py:114
↓ 3 callersMethodadd_edge
(self, a, b, c, rcap=0)
graphs/dinic.py:17
↓ 3 callersMethodadd_vertex
Adds a vertex to the graph
graphs/minimum_spanning_tree_boruvka.py:11
↓ 3 callersFunctionall_construct
returns the list containing all the possible combinations a string(`target`) can be constructed from the given list of substrings(`word_b
dynamic_programming/all_construct.py:9
↓ 3 callersFunctionarea_reg_polygon
Calculate the area of a regular polygon. Wikipedia reference: https://en.wikipedia.org/wiki/Polygon#Regular_polygons Formula: (n*s^2*c
maths/area.py:513
↓ 3 callersFunctionbeta
Calculates β = v/c, the given velocity as a fraction of c >>> beta(c) 1.0 >>> beta(199792458) 0.666435904801848 >>> beta(1e5)
physics/lorentz_transformation_four_vector.py:41
↓ 3 callersFunctionbidirectional_search
Perform bidirectional search on a graph to find the shortest path. Args: graph: A dictionary where keys are nodes and values are lis
graphs/bidirectional_search.py:49
↓ 3 callersFunctionbinary_search_insertion
>>> binary_search_insertion([1, 2, 7, 9, 10], 4) [1, 2, 4, 7, 9, 10]
sorts/merge_insertion_sort.py:17
↓ 3 callersFunctioncalculate_spearman_rank_correlation
Calculates Spearman's rank correlation coefficient. :param variable_1: List of floats representing the first variable. :param variable_2
maths/spearman_rank_correlation_coefficient.py:27
↓ 3 callersMethodchange_component
input: an index (pos) and a value changes the specified component (pos) with the 'value'
linear_algebra/src/lib.py:145
↓ 3 callersFunctioncheck_args
Check that the arguments are valid
physics/horizontal_projectile_motion.py:27
↓ 3 callersMethodconvolute
(self, data, convs, w_convs, thre_convs, conv_step)
neural_network/convolution_neural_network.py:109
↓ 3 callersFunctioncount_inversions_bf
Counts the number of inversions using a naive brute-force algorithm Parameters ---------- arr: arr: array-like, the list containing t
divide_and_conquer/inversions.py:12
↓ 3 callersFunctioncount_inversions_recursive
Counts the number of inversions using a divide-and-conquer algorithm Parameters ----------- arr: array-like, the list containing the
divide_and_conquer/inversions.py:43
↓ 3 callersFunctiondecimal_to_any
Convert a positive integer to another base as str. >>> decimal_to_any(0, 2) '0' >>> decimal_to_any(5, 4) '11' >>> decimal_to_
conversions/decimal_to_any.py:8
↓ 3 callersMethoddelete_at_nth
>>> linked_list = DoublyLinkedList() >>> linked_list.delete_at_nth(0) Traceback (most recent call last): ....
data_structures/linked_list/doubly_linked_list.py:114
↓ 3 callersMethoddelete_head
(self)
data_structures/linked_list/doubly_linked_list.py:108
↓ 3 callersMethoddelete_tail
(self)
data_structures/linked_list/doubly_linked_list.py:111
↓ 3 callersFunctiondeterminant
>>> determinant([[1, 2], [3, 4]]) -2 >>> determinant([[1.5, 2.5], [3, 4]]) -1.5
matrix/matrix_operation.py:125
↓ 3 callersMethoddeterminant
(self)
matrix/matrix_class.py:157
↓ 3 callersMethoddiameter
>>> root = Node(1) >>> root.diameter() 1 >>> root.left = Node(2) >>> root.diameter() 2 >>> ro
data_structures/binary_tree/diameter_of_binary_tree.py:35
↓ 3 callersFunctiondijkstra
Return the cost of the shortest path between vertices start and end. >>> dijkstra(G, "E", "C") 6 >>> dijkstra(G2, "E", "F") 3 >>>
graphs/dijkstra.py:37
↓ 3 callersFunctiondisplay
Display these values as a 2-D grid.
data_structures/arrays/sudoku_solver.py:124
↓ 3 callersFunctionf
This is the function to integrate, f(x) = (x - 0)^2 = x^2. :param x: The input value :return: The value of f(x) >>> f(0) 0
maths/trapezoidal_rule.py:65
↓ 3 callersFunctionf
>>> f(5) 39.98652410600183
maths/numerical_analysis/secant_method.py:9
↓ 3 callersFunctionf
(x)
maths/numerical_analysis/simpson_rule.py:68
↓ 3 callersFunctionfake
()
neural_network/input_data.py:282
↓ 3 callersFunctionfibonacci
Finds fibonacci number in index k. Parameters ---------- k : Index of fibonacci. Returns ------- int Fibonac
searches/fibonacci_search.py:18
↓ 3 callersMethodfit
(self)
machine_learning/sequential_minimum_optimization.py:78
↓ 3 callersFunctiongaussian_filter
(image, k_size, sigma)
digital_image_processing/filters/gaussian_filter.py:18
↓ 3 callersMethodget
Get the Fibonacci number of `index`. If the number does not exist, calculate all missing numbers leading up to the number of `index`.
dynamic_programming/fibonacci.py:11
↓ 3 callersMethodget_minor
(self, row: int, column: int)
matrix/matrix_class.py:178
↓ 3 callersMethodget_parent_idx
(self, idx)
data_structures/heap/min_heap.py:42
↓ 3 callersFunctionget_rotation
Get image rotation :param img: np.ndarray :param pt1: 3x2 list :param pt2: 3x2 list :param rows: columns image shape :param c
digital_image_processing/rotation/rotation.py:8
↓ 3 callersMethodget_successors
Returns a list of successors (both in the grid and free spaces)
graphs/bidirectional_breadth_first_search.py:79
↓ 3 callersMethodget_successors
Returns a list of successors (both in the grid and free spaces)
graphs/bidirectional_a_star.py:132
↓ 3 callersMethodhash_
(self, value: str)
data_structures/hashing/bloom_filter.py:91
← previousnext →201–300 of 3,909, ranked by callers