MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunction_create_spd_matrix
Returns a symmetric positive definite matrix given a dimension. Input: dimension gives the square matrix dimension. Output: spd
linear_algebra/src/conjugate_gradient.py:48
↓ 1 callersFunction_dense_to_one_hot
Convert class labels from scalars to one-hot vectors.
neural_network/input_data.py:76
↓ 1 callersMethod_depth
(self, node: Node | None)
data_structures/binary_tree/basic_binary_tree.py:88
↓ 1 callersFunction_dijkstra
Dijkstra over reweighted graph, using potentials h to make weights non-negative. Returns distances from start in the reweighted space.
graphs/johnson.py:43
↓ 1 callersMethod_elements
(self, d: dict)
strings/autocomplete_using_trie.py:27
↓ 1 callersFunction_euclidean_distance
Return the Euclidean distance between two 2-D points. >>> _euclidean_distance((0.0, 0.0), (3.0, 4.0)) 5.0 >>> _euclidean_distance((1.0, 1
geometry/ramer_douglas_peucker.py:19
↓ 1 callersMethod_euclidean_distance
Calculate the Euclidean distance between two points >>> KNN._euclidean_distance(np.array([0, 0]), np.array([3, 4])) 5.0
machine_learning/k_nearest_neighbours.py:37
↓ 1 callersMethod_expand_mat
(self, data_mat)
neural_network/convolution_neural_network.py:180
↓ 1 callersFunction_fib
(n: int)
dynamic_programming/fast_fibonacci.py:25
↓ 1 callersMethod_find_encoding_token
Finds the encoding token for the first character in the text. Tests: >>> lz77_compressor = LZ77Compressor() >>> lz77_
data_compression/lz77.py:144
↓ 1 callersFunction_find_leftmost_point
Find index of leftmost point (and bottom-most in case of tie).
geometry/jarvis_march.py:72
↓ 1 callersFunction_find_next_hull_point
Find the next point on the convex hull.
geometry/jarvis_march.py:83
↓ 1 callersMethod_get_bucket_index
(self, key: KEY)
data_structures/hashing/hash_map.py:50
↓ 1 callersMethod_get_hand_type
(self)
project_euler/problem_054/sol1.py:233
↓ 1 callersMethod_get_kernel
(self, kernel_name)
machine_learning/sequential_minimum_optimization.py:426
↓ 1 callersMethod_get_lowest_node
(self, node: Node)
data_structures/binary_tree/binary_search_tree_recursive.py:158
↓ 1 callersMethod_get_new_alpha
(self, i1, i2, a1, a2, e1, e2, y1, y2)
machine_learning/sequential_minimum_optimization.py:302
↓ 1 callersMethod_get_next_ind
Get next index. Implements linear open addressing. >>> HashMap(5)._get_next_ind(3) 4 >>> HashMap(5)._get_nex
data_structures/hashing/hash_map.py:53
↓ 1 callersMethod_inorder_traversal
(self, node: Node | None)
data_structures/binary_tree/binary_search_tree_recursive.py:250
↓ 1 callersMethod_internal_state
(self)
project_euler/problem_054/sol1.py:318
↓ 1 callersMethod_is_full
Return true if we have reached safe capacity. So we need to increase the number of buckets to avoid collisions. >>> hm = Ha
data_structures/hashing/hash_map.py:90
↓ 1 callersMethod_is_sparse
Return true if we need twice fewer buckets when we have now.
data_structures/hashing/hash_map.py:107
↓ 1 callersMethod_is_support
(self, index)
machine_learning/sequential_minimum_optimization.py:388
↓ 1 callersFunction_is_valid_polygon
Check if hull forms a valid polygon (has at least one non-collinear turn).
geometry/jarvis_march.py:100
↓ 1 callersMethod_left
Returns left-child-index of given index if exists else None
data_structures/heap/heap_generic.py:25
↓ 1 callersMethod_match_length_from_index
Calculate the longest possible match of text and window characters from text_index in text and window_index in window. Args:
data_compression/lz77.py:183
↓ 1 callersFunction_modexpt
Returns the modular exponentiation, that is the value of `base ** exponent % modulo_value`, without calculating the actual number. >>
project_euler/problem_188/sol1.py:23
↓ 1 callersFunction_msd_radix_sort
Sort the given list based on the bit at bit_position. Numbers with a 0 at that position will be at the start of the list, numbers with a
sorts/msd_radix_sort.py:40
↓ 1 callersFunction_msd_radix_sort_inplace
Sort the given list based on the bit at bit_position. Numbers with a 0 at that position will be at the start of the list, numbers with a
sorts/msd_radix_sort.py:112
↓ 1 callersMethod_normalize_graph
(self, sources, sinks)
graphs/edmonds_karp_multiple_source_and_sink.py:12
↓ 1 callersFunction_partition
Three way partition the data into smaller, equal and greater lists, in relationship to the pivot :param data: The data to be sorted (a li
searches/quick_select.py:11
↓ 1 callersFunction_perpendicular_distance
Return the distance from *point* to the line **segment** between *line_start* and *line_end*. When the perpendicular projection of *point* on
geometry/ramer_douglas_peucker.py:33
↓ 1 callersFunction_plugboard
https://en.wikipedia.org/wiki/Enigma_machine#Plugboard >>> _plugboard('PICTURES') {'P': 'I', 'I': 'P', 'C': 'T', 'T': 'C', 'U': 'R', 'R'
ciphers/enigma_machine2.py:114
↓ 1 callersMethod_position_node
Moves node forward to maintain invariant of sort by freq value
other/lfu_cache.py:131
↓ 1 callersMethod_predict
(self, sample)
machine_learning/sequential_minimum_optimization.py:206
↓ 1 callersMethod_preorder_traversal
(self, node: Node | None)
data_structures/binary_tree/binary_search_tree_recursive.py:272
↓ 1 callersFunction_print_dist
(dist, v)
graphs/graphs_floyd_warshall.py:8
↓ 1 callersMethod_put
(self, node: Node | None, label: int, parent: Node | None = None)
data_structures/binary_tree/binary_search_tree_recursive.py:74
↓ 1 callersMethod_query_range
(self, node, i, j)
data_structures/binary_tree/segment_tree_other.py:186
↓ 1 callersMethod_remove_repair
Repair the coloring of the tree that may have been messed up.
data_structures/binary_tree/red_black_tree.py:205
↓ 1 callersMethod_right
Returns right-child-index of given index if exists else None
data_structures/heap/heap_generic.py:30
↓ 1 callersMethod_search
(self, node: Node | None, label: int)
data_structures/binary_tree/binary_search_tree_recursive.py:104
↓ 1 callersMethod_size_down
(self)
data_structures/hashing/hash_map.py:125
↓ 1 callersMethod_size_up
(self)
data_structures/hashing/hash_map.py:122
↓ 1 callersMethod_step_by_step
(self, step_ord)
data_structures/hashing/hash_table.py:83
↓ 1 callersFunction_test
()
data_structures/binary_tree/avl_tree.py:332
↓ 1 callersFunction_top_down_cut_rod_recursive
Constructs a top-down dynamic programming solution for the rod-cutting problem via memoization. Runtime: O(n^2) Arguments -----
dynamic_programming/rod_cutting.py:94
↓ 1 callersMethod_try_set
Try to add value to the bucket. If bucket is empty or key is the same, does insert and return True. If bucket has another k
data_structures/hashing/hash_map.py:69
↓ 1 callersMethod_update_tree
(self, node, i, val)
data_structures/binary_tree/segment_tree_other.py:176
↓ 1 callersFunction_validate_dicts
>>> _validate_dicts({"c":0.5}, {"d": {"e": 0.6}}, {"f": {"g": 0.7}}) >>> _validate_dicts("invalid", {"d": {"e": 0.6}}, {"f": {"g": 0.7}})
dynamic_programming/viterbi.py:286
↓ 1 callersFunction_validate_lists
>>> _validate_lists(["a"], ["b"]) >>> _validate_lists(1234, ["b"]) Traceback (most recent call last): ... ValueError: obs
dynamic_programming/viterbi.py:248
↓ 1 callersFunction_validate_not_empty
>>> _validate_not_empty(["a"], ["b"], {"c":0.5}, ... {"d": {"e": 0.6}}, {"f": {"g": 0.7}}) >>> _validate_not_empty(["a"], ["b"], {"c":0.5
dynamic_programming/viterbi.py:217
↓ 1 callersFunction_validation
>>> observations = ["normal", "cold", "dizzy"] >>> states = ["Healthy", "Fever"] >>> start_p = {"Healthy": 0.6, "Fever": 0.4} >>> tra
dynamic_programming/viterbi.py:179
↓ 1 callersFunction_validator
Checks if the values can be used for the ``enigma`` function >>> _validator((1,1,1), (rotor1, rotor2, rotor3), 'POLAND') ((1, 1, 1), ('E
ciphers/enigma_machine2.py:74
↓ 1 callersFunctiona
(i: int, j: int)
dynamic_programming/matrix_chain_multiplication.py:121
↓ 1 callersFunctionabs_max
>>> abs_max([0,5,1,11]) 11 >>> abs_max([3,-10,-2]) -10 >>> abs_max([]) Traceback (most recent call last): ... Val
maths/abs.py:38
↓ 1 callersFunctionabs_max_sort
>>> abs_max_sort([0,5,1,11]) 11 >>> abs_max_sort([3,-10,-2]) -10 >>> abs_max_sort([]) Traceback (most recent call last):
maths/abs.py:58
↓ 1 callersFunctionabs_min
>>> abs_min([0,5,1,11]) 0 >>> abs_min([3,-10,-2]) -2 >>> abs_min([]) Traceback (most recent call last): ... Value
maths/abs.py:18
↓ 1 callersFunctionabundant
>>> abundant(0) True >>> abundant(1) False >>> abundant(12) True >>> abundant(13) False >>> abundant(20) True
maths/special_numbers/weird_number.py:32
↓ 1 callersFunctionaccuracy
Calculate the value of accuracy based-on predictions :param actual_y:a list containing initial Y values generated by 'y_generator' fu
machine_learning/linear_discriminant_analysis.py:220
↓ 1 callersFunctionactual_strassen
Recursive function to calculate the product of two matrices, using the Strassen Algorithm. It only supports square matrices of any size that
divide_and_conquer/strassen_matrix_multiplication.py:74
↓ 1 callersFunctionadd
Implementation of addition of integer Examples: >>> add(3, 5) 8 >>> add(13, 5) 18 >>> add(-7, 2) -5 >>> add(0, -
maths/addition_without_arithmetic.py:9
↓ 1 callersFunctionadd
>>> add([[1,2],[3,4]],[[2,3],[4,5]]) [[3, 5], [7, 9]] >>> add([[1.2,2.4],[3,4]],[[2,3],[4,5]]) [[3.2, 5.4], [7, 9]] >>> add([[1,
matrix/matrix_operation.py:10
↓ 1 callersMethodadd
Add an item to the LinkedList at the specified position. Default position is 0 (the head). Args: item (Any): The
data_structures/linked_list/__init__.py:25
↓ 1 callersMethodadd
Add a value to index in O(lg N) Parameters: index (int): index to add value to value (int): value to add to
data_structures/binary_tree/fenwick_tree.py:80
↓ 1 callersMethodadd_column
(self, column: list[int], position: int | None = None)
matrix/matrix_class.py:265
↓ 1 callersMethodadd_edge
(self, node1: T, node2: T, weight: int)
graphs/minimum_spanning_tree_kruskal2.py:59
↓ 1 callersMethodadd_edge
Adds an edge to the graph
graphs/minimum_spanning_tree_boruvka.py:20
↓ 1 callersMethodadd_edge
Add a new edge to the graph. >>> graph = Graph({1, 2}, {(2, 1): 4}) >>> graph.add_edge((3, 1), 5) >>> sorted(graph.ve
project_euler/problem_107/sol1.py:50
↓ 1 callersFunctionadd_file_length
Adds given file's length in front (using Elias gamma coding) of the compressed string
data_compression/lempel_ziv.py:74
↓ 1 callersMethodadd_inbound
(self, node)
graphs/page_rank.py:24
↓ 1 callersFunctionadd_key_to_lexicon
Adds new strings (curr_string + "0", curr_string + "1") to the lexicon
data_compression/lempel_ziv.py:28
↓ 1 callersMethodadd_keyword
(self, keyword: str)
strings/aho_corasick.py:23
↓ 1 callersMethodadd_layer
(self, layer)
neural_network/back_propagation_neural_network.py:110
↓ 1 callersMethodadd_outbound
(self, node)
graphs/page_rank.py:27
↓ 1 callersMethodadd_output
(self, output: Variable)
machine_learning/automatic_differentiation.py:149
↓ 1 callersMethodadd_pair
(self, u, v, w=1)
graphs/directed_and_undirected_weighted_graph.py:16
↓ 1 callersMethodadd_pair
(self, u, v, w=1)
graphs/directed_and_undirected_weighted_graph.py:271
↓ 1 callersMethodadd_param_to
(self, param_to: Operation)
machine_learning/automatic_differentiation.py:124
↓ 1 callersMethodadd_params
(self, params: list[Variable])
machine_learning/automatic_differentiation.py:146
↓ 1 callersMethodadd_result_of
(self, result_of: Operation)
machine_learning/automatic_differentiation.py:127
↓ 1 callersMethodadd_row
(self, row: list[int], position: int | None = None)
matrix/matrix_class.py:249
↓ 1 callersMethodadd_transition_probability
( self, node1: str, node2: str, probability: float )
graphs/markov_chain.py:18
↓ 1 callersFunctionadded_solution_file_path
Collects only the solution file path which got added in the current pull request. This will only be triggered if the script is ran from GitHu
scripts/validate_solutions.py:58
↓ 1 callersMethodadjugate
(self)
matrix/matrix_class.py:216
↓ 1 callersFunctionall_rotations
:param s: The string that will be rotated len(s) times. :return: A list with the rotations. :raises TypeError: If s is not an instance of
data_compression/burrows_wheeler.py:24
↓ 1 callersFunctionall_solution_file_paths
Collects all the solution file path in the Project Euler directory
scripts/validate_solutions.py:38
↓ 1 callersFunctionalternative_list_arrange
The method arranges two lists as one list in alternative forms of the list elements. :param first_input_list: :param second_input_list:
other/alternative_list_arrange.py:1
↓ 1 callersFunctionalternative_password_generator
(chars_incl: str, i: int)
other/password.py:28
↓ 1 callersFunctionalternative_string_arrange
Return the alternative arrangements of the two strings. :param first_str: :param second_str: :return: String >>> alternative_stri
strings/alternative_string_arrange.py:1
↓ 1 callersFunctionanalyze_text
Convert text input into two dicts of counts. The first dictionary stores the frequency of single character strings. The second dictionary
maths/entropy.py:93
↓ 1 callersMethodangle
find angle between two Vector (self, Vector) >>> Vector([3, 4, -1]).angle(Vector([2, -1, 1])) 1.4906464636572374 >>>
linear_algebra/src/lib.py:175
↓ 1 callersFunctionangle_comparer
Return the angle toward to point from (minx, miny) :param point: The target point minx: The starting point's x miny: The st
other/graham_scan.py:28
↓ 1 callersMethodappend
>>> ll = LinkedList([1, 2]) >>> tuple(ll) (1, 2) >>> ll.append(3) >>> tuple(ll) (1, 2, 3) >>>
data_structures/linked_list/reverse_k_group.py:54
↓ 1 callersFunctionapply_pca
Applies Principal Component Analysis (PCA) to reduce dimensionality. :param data_x: Original dataset (features) :param n_components: Num
machine_learning/principle_component_analysis.py:37
↓ 1 callersFunctionapply_tsne
Apply t-SNE for dimensionality reduction. Args: data_matrix: Original dataset (features). n_components: Target dimension (2D
machine_learning/t_stochastic_neighbour_embedding.py:90
↓ 1 callersFunctionapriori
Returns a list of frequent itemsets and their support counts. >>> data = [['A', 'B', 'C'], ['A', 'B'], ['A', 'C'], ['A', 'D'], ['B', 'C']]
machine_learning/apriori_algorithm.py:65
↓ 1 callersFunctionarc_length
>>> arc_length(45, 5) 3.9269908169872414 >>> arc_length(120, 15) 31.415926535897928 >>> arc_length(90, 10) 15.707963267948966
maths/arc_length.py:4
↓ 1 callersFunctionarea_circle
Calculate the area of a circle. >>> area_circle(20) 1256.6370614359173 >>> area_circle(1.6) 8.042477193189871 >>> are
maths/area.py:435
↓ 1 callersFunctionarea_ellipse
Calculate the area of a ellipse. >>> area_ellipse(10, 10) 314.1592653589793 >>> area_ellipse(10, 20) 628.3185307179587
maths/area.py:455
← previousnext →701–800 of 3,909, ranked by callers