MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionpost_order
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:86
↓ 1 callersFunctionpost_order_iter
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:230
↓ 1 callersFunctionpostorder
Post-order traversal visits left subtree, right subtree, root node. >>> list(postorder(make_tree())) [4, 5, 2, 3, 1]
data_structures/binary_tree/binary_tree_traversals.py:46
↓ 1 callersFunctionpower
Calculate the power of a base raised to an exponent. >>> power(3, 4) 81 >>> power(2, 0) 1 >>> all(power(base, exponent) == p
maths/power_using_recursion.py:16
↓ 1 callersFunctionpower
Examples: >>> power(2, 15, 3) 2 >>> power(5, 1, 30) 5
maths/special_numbers/carmichael_number.py:17
↓ 1 callersFunctionpower
:param a: The base (integer). :param b: The exponent (integer). :return: The result of a^b, as a float for negative exponents. >>> p
divide_and_conquer/power.py:30
↓ 1 callersFunctionpower_iteration
Power Iteration. Find the largest eigenvalue and corresponding eigenvector of matrix input_matrix given a random vector in the same space
linear_algebra/src/power_iteration.py:4
↓ 1 callersFunctionpre_order
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:42
↓ 1 callersMethodpre_order
Returns the Pre-order representation of the heap including values of nodes plus their level distance from the root; Empty
data_structures/heap/binomial_heap.py:359
↓ 1 callersFunctionpre_order_iter
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:172
↓ 1 callersMethodpredict
Computes the predicted response values y for the given input data by constructing the design matrix X and evaluating y = Xβ.
machine_learning/polynomial_regression.py:152
↓ 1 callersMethodpredict
Predict's the output for the given input values using the trained neural network. The output value given by the model ranges
neural_network/two_hidden_layers_neural_network.py:184
↓ 1 callersFunctionpredict_prob
(x)
machine_learning/logistic_regression.py:143
↓ 1 callersFunctionpredict_y_values
This function predicts new indexes(groups for our data) :param x_items: a list containing all items(gaussian distribution of all classes) :par
machine_learning/linear_discriminant_analysis.py:156
↓ 1 callersFunctionprefix_function
For the given string this function computes value for each index(i), which represents the longest coincidence of prefix and suffix for gi
strings/prefix_function.py:14
↓ 1 callersFunctionpreorder
Pre-order traversal visits root node, left subtree, right subtree. >>> list(preorder(make_tree())) [1, 2, 4, 5, 3]
data_structures/binary_tree/binary_tree_traversals.py:33
↓ 1 callersMethodpreorder_traverse
(self, node: Node | None)
data_structures/binary_tree/binary_search_tree.py:302
↓ 1 callersFunctionprepare_grid
Create a grid of complex values of size nb_pixels*nb_pixels with real and imaginary parts ranging from -window_size to window_size (inclusiv
fractals/julia_sets.py:67
↓ 1 callersFunctionprepare_input
Prepare the plaintext by up-casing it and separating repeated letters with X's
ciphers/playfair_cipher.py:36
↓ 1 callersFunctionpreprocess
Preprocesses the message string: - Convert message to bit string - Pad bit string to a multiple of 512 chars: - Append a 1
hashes/md5.py:90
↓ 1 callersFunctionpreprocess
Preprocess the edge array >>> preprocess([['ab-e1', 'ac-e3', 'ad-e5', 'bc-e4', 'bd-e2', 'be-e6', 'bh-e12', ... 'cd-e2', '
graphs/frequent_pattern_graph_miner.py:209
↓ 1 callersMethodpreprocessing
(data: bytes)
hashes/sha256.py:121
↓ 1 callersMethodprev
(index: int)
data_structures/binary_tree/fenwick_tree.py:77
↓ 1 callersFunctionprime_factors
Find Prime Factors. >>> prime_factors(100) [2, 2, 5, 5] >>> prime_factors(0) Traceback (most recent call last): ...
maths/basic_maths.py:6
↓ 1 callersFunctionprime_generator
Generate a list sequence of prime numbers
project_euler/problem_010/sol2.py:53
↓ 1 callersFunctionprime_generator
Generate a sequence of prime numbers
project_euler/problem_007/sol3.py:53
↓ 1 callersFunctionprime_implicant_chart
>>> prime_implicant_chart(['0.00.01.5'],['0.00.01.5']) [[1]]
boolean_algebra/quine_mc_cluskey.py:122
↓ 1 callersFunctionprime_sieve
Returns a list with all prime numbers up to n. >>> prime_sieve(50) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] >>>
maths/sieve_of_eratosthenes.py:19
↓ 1 callersFunctionprime_sieve
Sieve of Erotosthenes Function to return all the prime numbers up to a certain number https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
project_euler/problem_051/sol1.py:24
↓ 1 callersFunctionprime_sieve
Sieve of Erotosthenes Function to return all the prime numbers up to a certain number https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
project_euler/problem_234/sol1.py:23
↓ 1 callersFunctionprime_sieve
Sieve of Erotosthenes Function to return all the prime numbers up to a number 'limit' https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
project_euler/problem_050/sol1.py:22
↓ 1 callersFunctionprime_sieve_eratosthenes
Print the prime numbers up to n >>> prime_sieve_eratosthenes(10) [2, 3, 5, 7] >>> prime_sieve_eratosthenes(20) [2, 3, 5, 7, 11,
maths/prime_sieve_eratosthenes.py:15
↓ 1 callersFunctionprimes
Return a list of all primes numbers up to max. >>> list(primes(0)) [] >>> list(primes(-1)) [] >>> list(primes(-10)) []
maths/prime_numbers.py:32
↓ 1 callersFunctionprimitive_root
(p_val: int)
ciphers/elgamal_key_generator.py:16
↓ 1 callersMethodprims_algorithm
Run Prim's algorithm to find the minimum spanning tree. Reference: https://en.wikipedia.org/wiki/Prim%27s_algorithm >>> graph
project_euler/problem_107/sol1.py:64
↓ 1 callersFunctionprincipal_component_analysis
Principal Component Analysis. For more details, see: https://en.wikipedia.org/wiki/Principal_component_analysis. Parameters: * f
machine_learning/dimensionality_reduction.py:94
↓ 1 callersFunctionprint_all
()
graphs/frequent_pattern_graph_miner.py:113
↓ 1 callersFunctionprint_array
(arr, n)
data_structures/stacks/stock_span_problem.py:61
↓ 1 callersFunctionprint_binary_search_tree
Recursive function to print a BST from a root table. >>> key = [3, 8, 9, 10, 17, 21] >>> root = [[0, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 3],
dynamic_programming/optimal_binary_search_tree.py:38
↓ 1 callersFunctionprint_directory_md
(top_dir: str = ".")
scripts/build_directory_md.py:45
↓ 1 callersFunctionprint_dist
(dist, v)
graphs/dijkstra_2.py:1
↓ 1 callersFunctionprint_distance
(distance: list[float], src)
graphs/bellman_ford.py:4
↓ 1 callersMethodprint_graph
Print the graph vertices. Example: >>> g = Graph() >>> g.add_edge(0, 1) >>> g.add_edge(0, 2) >>> g.a
graphs/depth_first_search_2.py:11
↓ 1 callersMethodprint_graph
prints adjacency list representation of graaph >>> g = Graph() >>> g.print_graph() >>> g.add_edge(0, 1) >>> g
graphs/breadth_first_search.py:14
↓ 1 callersFunctionprint_max_activities
>>> start = [1, 3, 0, 5, 8, 5] >>> finish = [2, 4, 6, 7, 9, 9] >>> print_max_activities(start, finish) The following activities are s
other/activity_selection.py:11
↓ 1 callersFunctionprint_optimal_solution
Print order of matrix with Ai as Matrix.
dynamic_programming/matrix_chain_order.py:37
↓ 1 callersFunctionprint_path
(old_path: str, new_path: str)
scripts/build_directory_md.py:37
↓ 1 callersFunctionprint_results
(msg: str, passes: bool)
data_structures/trie/trie.py:111
↓ 1 callersMethodprint_solution
>>> Graph(0).print_solution([]) # doctest: +NORMALIZE_WHITESPACE Vertex Distance from Source
graphs/dijkstra_alternate.py:18
↓ 1 callersFunctionprint_stack
(stack, clothes)
graphs/g_topological_sort.py:21
↓ 1 callersMethodprint_tree
Print the tree Args: height (int, optional): Height of the printed node
data_structures/trie/radix_tree.py:181
↓ 1 callersFunctionprintboard
Prints the boards that have a successful combination.
backtracking/n_queens.py:92
↓ 1 callersFunctionprisms_algorithm
>>> adjacency_list = {0: [[1, 1], [3, 3]], ... 1: [[0, 1], [2, 6], [3, 5], [4, 1]], ... 2: [[1, 6], [
graphs/minimum_spanning_tree_prims.py:75
↓ 1 callersFunctionprocess_game
Processes the game logic for the given matrix and moves. Args: size (int): Size of the game board. matrix (List[str]): Initial ga
matrix/matrix_based_game.py:243
↓ 1 callersMethodprocess_vertex
(self, vertex_index)
graphs/edmonds_karp_multiple_source_and_sink.py:135
↓ 1 callersFunctionproduct_sum
Recursively calculates the product sum of an array. The product sum of an array is defined as the sum of its elements multiplied by thei
data_structures/arrays/product_sum.py:23
↓ 1 callersFunctionprojection
>>> projection(45) # doctest: +NORMALIZE_WHITESPACE [[0.27596319193541496, 0.446998331800279], [0.446998331800279, 0.7240368080645851]]
linear_algebra/src/transformations_2d.py:39
↓ 1 callersFunctionproth
:param number: nth number to calculate in the sequence :return: the nth number in Proth number Note: indexing starts at 1 i.e. proth(1) g
maths/special_numbers/proth_number.py:10
↓ 1 callersFunctionprune
Prune candidate itemsets that are not frequent. The goal of pruning is to filter out candidate itemsets that are not frequent. This is d
machine_learning/apriori_algorithm.py:28
↓ 1 callersFunctionpull
()
hashes/chaos_machine.py:42
↓ 1 callersFunctionpush
(seed)
hashes/chaos_machine.py:16
↓ 1 callersMethodpush
(self, elem: T, weight: int)
graphs/minimum_spanning_tree_prims2.py:101
↓ 1 callersMethodpush
(self, from_index, to_index)
graphs/edmonds_karp_multiple_source_and_sink.py:149
↓ 1 callersMethodpush
Add a new node with the given data to the beginning of the Linked List. Args: new_data (Any): The data to be added t
data_structures/linked_list/swap_nodes.py:43
↓ 1 callersMethodpush
(self, new_data: int)
data_structures/linked_list/middle_element_of_linked_list.py:14
↓ 1 callersMethodpush
(self, item: int)
data_structures/stacks/stack_using_two_queues.py:37
↓ 1 callersMethodput
Sets the value for the input key and updates the Double Linked List
other/lru_cache.py:266
↓ 1 callersMethodput
Sets the value for the input key and updates the Double Linked List
other/lfu_cache.py:251
↓ 1 callersFunctionpythagorean_triple
Returns a dictionary with keys as the perimeter of a right angled triangle and value as the number of corresponding triplets. >>> pyth
project_euler/problem_039/sol1.py:17
↓ 1 callersFunctionquadratic_roots
Given the numerical coefficients a, b and c, calculates the roots for any quadratic equation of the form ax^2 + bx + c >>> quadratic_roo
maths/quadratic_equations_complex_numbers.py:6
↓ 1 callersFunctionquantum_fourier_transform
# >>> quantum_fourier_transform(2) # {'00': 2500, '01': 2500, '11': 2500, '10': 2500} # quantum circuit for number_of_qubits = 3:
quantum/q_fourier_transform.py:21
↓ 1 callersFunctionquery
>>> query(build_sparse_table([8, 1, 0, 3, 4, 9, 3]), 0, 4) 0 >>> query(build_sparse_table([8, 1, 0, 3, 4, 9, 3]), 4, 6) 3 >>> que
data_structures/arrays/sparse_table.py:61
↓ 1 callersMethodquery
Query the sum of all elements in [left, right) in O(lg N) Parameters: left (int): left bound of the query (inclusive)
data_structures/binary_tree/fenwick_tree.py:156
↓ 1 callersMethodquery_recursive
query(1, 1, N, a, b) for query max of [a,b]
data_structures/binary_tree/segment_tree.py:86
↓ 1 callersFunctionquick_sort
A pure Python implementation of quicksort algorithm. :param collection: a mutable collection of comparable items :return: the same collection
sorts/quick_sort.py:16
↓ 1 callersFunctionquick_sort_3partition
" Python implementation of quick sort algorithm with 3-way partition. The idea of 3-way quick sort is based on "Dutch National Flag algorithm
sorts/quick_sort_3_partition.py:1
↓ 1 callersFunctionrabin_miller
(num: int)
ciphers/rabin_miller.py:6
↓ 1 callersFunctionrandom_anime_character
Returns the Title, Description, and Image Title of a random anime character .
web_programming/random_anime_character.py:29
↓ 1 callersFunctionrandom_chars
Automatic generate random 32 characters. Get random string code: '7b7ad245cdff75241935e4dd860f3bad' >>> len(random_chars(32)) 32
computer_vision/mosaic_augmentation.py:172
↓ 1 callersFunctionrandom_chars
Automatic generate random 32 characters. Get random string code: '7b7ad245cdff75241935e4dd860f3bad' >>> len(random_chars(32)) 32
computer_vision/flip_augmentation.py:114
↓ 1 callersMethodrandom_level
:return: Random level from [1, self.max_level] interval. Higher values are less likely.
data_structures/linked_list/skip_list.py:116
↓ 1 callersFunctionrandom_pivot
Choose a random pivot for the list. We can use a more sophisticated algorithm here, such as the median-of-medians algorithm.
divide_and_conquer/kth_order_statistic.py:17
↓ 1 callersFunctionrandom_puzzle
Make a random puzzle with N or more assignments. Restart on contradictions. Note the resulting puzzle is not guaranteed to be solvable, but e
data_structures/arrays/sudoku_solver.py:213
↓ 1 callersFunctionrandom_quotes
()
web_programming/fetch_quotes.py:27
↓ 1 callersMethodrandom_unit_square
Generates a point randomly drawn from the unit square [0, 1) x [0, 1).
maths/pi_monte_carlo_estimation.py:17
↓ 1 callersFunctionread_file_binary
Reads given file as bytes and returns them as a long string
data_compression/lempel_ziv.py:11
↓ 1 callersFunctionread_file_binary
Reads given file as bytes and returns them as a long string
data_compression/lempel_ziv_decompress.py:10
↓ 1 callersFunctionread_from_file_and_decrypt
(message_filename: str, key_filename: str)
ciphers/rsa_cipher.py:93
↓ 1 callersFunctionrec_fn_memoized
(num: int)
maths/fibonacci.py:190
↓ 1 callersFunctionrec_insertion_sort
Given a collection of numbers and its length, sorts the collections in ascending order :param collection: A mutable collection of compar
sorts/recursive_insertion_sort.py:8
↓ 1 callersFunctionrec_ternary_search
Recursive method of the ternary search algorithm. >>> test_list = [0, 1, 2, 8, 13, 17, 19, 32, 42] >>> rec_ternary_search(0, len(test_list),
searches/ternary_search.py:112
↓ 1 callersFunctionrecursive_lucas_number
Returns the nth lucas number >>> recursive_lucas_number(1) 1 >>> recursive_lucas_number(20) 15127 >>> recursive_lucas_number(
maths/lucas_series.py:6
↓ 1 callersFunctionreflection
>>> reflection(45) # doctest: +NORMALIZE_WHITESPACE [[0.05064397763545947, 0.893996663600558], [0.893996663600558, 0.7018070490682369]]
linear_algebra/src/transformations_2d.py:50
↓ 1 callersMethodrefresh
(self)
sorts/external_sort.py:71
↓ 1 callersMethodrehashing
(self)
data_structures/hashing/hash_table.py:239
↓ 1 callersMethodrelabel
(self, vertex_index)
graphs/edmonds_karp_multiple_source_and_sink.py:159
↓ 1 callersFunctionrelu
Implements the relu function Parameters: vector (np.array,list,tuple): A numpy array of shape (1,n) consisting of real valu
neural_network/activation_functions/rectified_linear_unit.py:18
↓ 1 callersMethodremove
(self)
data_structures/heap/min_heap.py:105
↓ 1 callersFunctionremove_duplicates
Removes duplicate alphabetic characters in a keyword (letter is ignored after its first appearance). :param key: Keyword to use :ret
ciphers/simple_keyword_cypher.py:1
↓ 1 callersMethodremove_element
(self, item)
graphs/multi_heuristic_astar.py:39
← previousnext →1,801–1,900 of 3,909, ranked by callers