MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionmin_dist
(mdist, vset, v)
graphs/dijkstra_2.py:11
↓ 1 callersMethodmin_dist_bottom_up
>>> EditDistance().min_dist_bottom_up("intention", "execution") 5 >>> EditDistance().min_dist_bottom_up("intention", "")
dynamic_programming/edit_distance.py:59
↓ 1 callersMethodmin_dist_top_down
>>> EditDistance().min_dist_top_down("intention", "execution") 5 >>> EditDistance().min_dist_top_down("intention", "")
dynamic_programming/edit_distance.py:44
↓ 1 callersFunctionmin_distance
(index1: int, index2: int)
dynamic_programming/min_distance_up_bottom.py:29
↓ 1 callersMethodmin_heapify
Sorts the queue array so that the minimum element is root. Examples: >>> priority_queue_test = PriorityQueue() >>> p
graphs/dijkstra_algorithm.py:44
↓ 1 callersFunctionmincut
This array is filled by BFS and to store path >>> mincut(test_graph, source=0, sink=5) [(1, 3), (4, 3), (4, 5)]
networking_flow/minimum_cut.py:30
↓ 1 callersFunctionmine_tree
Mine the FP-Tree recursively to discover frequent itemsets. Args: in_tree: The FP-Tree to mine. header_table: The header tab
machine_learning/frequent_pattern_growth.py:279
↓ 1 callersFunctionminimax
This function implements the minimax algorithm, which helps achieve the optimal score for a player in a two-player game by checking all possi
backtracking/minimax.py:16
↓ 1 callersMethodminimum_distance
A utility function to find the vertex with minimum distance value, from the set of vertices not yet included in shortest path tree.
graphs/dijkstra_alternate.py:27
↓ 1 callersMethodmirror
Mirror the binary tree rooted at this node by swapping left and right children. >>> tree = Node(0) >>> list(tree) [0
data_structures/binary_tree/mirror_binary_tree.py:33
↓ 1 callersMethodmismatch_in_text
Find the index of mis-matched character in text when compared with pattern from last. Parameters : current_pos (
strings/boyer_moore_search.py:57
↓ 1 callersFunctionmixed_keyword
For keyword: hello H E L O A B C D F G I J K M N P Q R S T U V W X Y Z and map vertically >>> mixed_keyword
ciphers/mixed_keyword_cypher.py:4
↓ 1 callersFunctionmodular_exponential
>>> modular_exponential(5, 0, 10) 1 >>> modular_exponential(2, 8, 7) 4 >>> modular_exponential(3, -2, 9) -1
maths/modular_exponential.py:11
↓ 1 callersFunctionmodular_exponentiation
(a: Matrix, b: int)
maths/matrix_exponentiation.py:31
↓ 1 callersFunctionmove_disk
(fp, tp)
other/tower_of_hanoi.py:18
↓ 1 callersFunctionmove_tower
>>> move_tower(3, 'A', 'B', 'C') moving disk from A to B moving disk from A to C moving disk from B to C moving disk from A to B
other/tower_of_hanoi.py:1
↓ 1 callersFunctionmove_x
Simulates gravity in a specific column. >>> move_x([['-', 'A'], ['-', '-'], ['-', 'C']], 1, 2) [['-', '-'], ['-', 'A'], ['-', 'C']]
matrix/matrix_based_game.py:176
↓ 1 callersFunctionmove_y
Shifts all columns leftward when an entire column becomes empty. >>> move_y([['-', 'A'], ['-', '-'], ['-', 'C']], 2) [['A', '-'], ['-',
matrix/matrix_based_game.py:196
↓ 1 callersFunctionmulti_a_star
(start: TPos, goal: TPos, n_heuristic: int)
graphs/multi_heuristic_astar.py:236
↓ 1 callersMethodmulti_level_feedback_queue
MLFQ(Multi Level Feedback Queue) >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>> P3 = Process("P3", 0
scheduling/multi_level_feedback_queue.py:243
↓ 1 callersFunctionmultiplication_table
Prints the multiplication table of a given number till the given number of terms >>> print(multiplication_table(3, 5)) 3 * 1 = 3 3 *
maths/print_multiplication_table.py:1
↓ 1 callersFunctionmultiply
:param matrix_a: A square Matrix. :param matrix_b: Another square Matrix with the same dimensions as matrix_a. :param result:
matrix/matrix_multiplication_recursion.py:119
↓ 1 callersFunctionmultiply
Run over all prime combinations to generate non-prime numbers. >>> chain = [0] * 3 >>> primes_degrees = {} >>> multiply( ...
project_euler/problem_095/sol1.py:51
↓ 1 callersFunctionmultiply_matrix_vector
Performs multiplication of a graph's adjacency list representation with a vector. Args: graph: The adjacency list of the graph. v
graphs/lanczos_eigenvectors.py:133
↓ 1 callersFunctionmy_dfs
find different DFS walk from given node to Header node
graphs/frequent_pattern_graph_miner.py:172
↓ 1 callersFunctionmy_laplacian
:param src: the source image, which should be a grayscale or color image. :param ksize: the size of the kernel used to compute the Laplacian
digital_image_processing/filters/laplacian_filter.py:20
↓ 1 callersFunctionn_queens_solution
(n: int)
backtracking/n_queens_math.py:141
↓ 1 callersFunctionnaive_cut_rod_recursive
Solves the rod-cutting problem via naively without using the benefit of dynamic programming. The results is the same sub-problems are solved
dynamic_programming/rod_cutting.py:14
↓ 1 callersFunctionnarcissistic_number
Return True if n is a narcissistic number or False if it is not. >>> all(narcissistic_number(n) for n in PASSING) True >>> any(narcissist
maths/special_numbers/armstrong_numbers.py:70
↓ 1 callersFunctionnew_generation
(cells: list[list[int]], rule: list[int], time: int)
cellular_automata/one_dimensional.py:30
↓ 1 callersFunctionnew_generation
Generates the next generation for a given state of Conway's Game of Life. >>> new_generation(BLINKER) [[0, 0, 0], [1, 1, 1], [0, 0, 0]]
cellular_automata/conways_game_of_life.py:26
↓ 1 callersFunctionnewton_raphson
Find a root of the given function f using the Newton-Raphson method. :param f: A real-valued single-variable function :param x0: Initial
maths/numerical_analysis/newton_raphson.py:35
↓ 1 callersFunctionnewtons_second_law_of_motion
Calculates force from `mass` and `acceleration` >>> newtons_second_law_of_motion(10, 10) 100 >>> newtons_second_law_of_motion(2.0, 1
physics/newtons_second_law_of_motion.py:65
↓ 1 callersFunctionnext_greatest_element
Efficient solution to find the Next Greatest Element (NGE) for all elements using a stack. The time complexity is reduced to O(n), making it
data_structures/stacks/next_greater_element.py:71
↓ 1 callersFunctionnext_greatest_element_fast
Find the Next Greatest Element (NGE) for each element in the array using a more readable approach. This implementation utilizes enumerate
data_structures/stacks/next_greater_element.py:40
↓ 1 callersFunctionnext_greatest_element_slow
Get the Next Greatest Element (NGE) for each element in the array by checking all subsequent elements to find the next greater one. This
data_structures/stacks/next_greater_element.py:7
↓ 1 callersFunctionnext_number
Returns the next number of the chain by adding the square of each digit to form a new number. For example, if number = 12, next_number()
project_euler/problem_092/sol1.py:17
↓ 1 callersMethodnext_number
The smallest number that can be generated is zero. The largest number that can be generated is modulo-1. modulo is set in the
other/linear_congruential_generator.py:29
↓ 1 callersFunctionnext_point
Given that a laser beam hits the interior of the white cell at point (point_x, point_y) with gradient incoming_gradient, return a tuple (x,y,
project_euler/problem_144/sol1.py:35
↓ 1 callersFunctionnext_term
Calculates and updates a_i in-place to either the n-th term or the smallest term for which c > 10^k when the terms are written in the form:
project_euler/problem_551/sol1.py:20
↓ 1 callersFunctionnon_bouncy_exact
Calculate the number of non-bouncy numbers with at most n digits. >>> non_bouncy_exact(1) 9 >>> non_bouncy_exact(6) 7998 >>>
project_euler/problem_113/sol1.py:37
↓ 1 callersFunctionnon_bouncy_upto
Calculate the number of non-bouncy numbers with at most n digits. >>> non_bouncy_upto(1) 9 >>> non_bouncy_upto(6) 12951 >>> n
project_euler/problem_113/sol1.py:50
↓ 1 callersFunctionnorm_squared
Return the squared second norm of vector norm_squared(v) = sum(x * x for x in v) Args: vector (ndarray): input vector Retur
machine_learning/support_vector_machines.py:6
↓ 1 callersFunctionnormalize
Normalize an audio signal by scaling it to have values between -1 and 1. Args: audio: The input audio signal. Returns:
machine_learning/mfcc.py:152
↓ 1 callersFunctionnormalize_array
Normalizes a 1D array, between ranges 0-cap. Args: array: List containing values to be normalized between cap range. cap: Maximum
computer_vision/haralick_descriptors.py:52
↓ 1 callersFunctionnot_32
Perform bitwise NOT on given int. Arguments: i {[int]} -- [given int] Raises: ValueError -- [input is negative] Re
hashes/md5.py:190
↓ 1 callersFunctionnth_fibonacci_bruteforce
>>> nth_fibonacci_bruteforce(100) 354224848179261915075 >>> nth_fibonacci_bruteforce(-100) -100
matrix/nth_fibonacci_using_matrix_exponentiation.py:57
↓ 1 callersFunctionnth_fibonacci_matrix
>>> nth_fibonacci_matrix(100) 354224848179261915075 >>> nth_fibonacci_matrix(-100) -100
matrix/nth_fibonacci_using_matrix_exponentiation.py:37
↓ 1 callersMethodnumbers_to_letter
Return the letter corresponding to the position [index1, index2] in the polybius square >>> PolybiusCipher().numbers_to_lett
ciphers/polybius.py:38
↓ 1 callersFunctionoctal_to_hex
Convert an Octal number to Hexadecimal number. For more information: https://en.wikipedia.org/wiki/Octal >>> octal_to_hex("100") '0x
conversions/octal_to_hexadecimal.py:1
↓ 1 callersFunctionodd_even_sort
Sort input with odd even sort. This algorithm uses the same idea of bubblesort, but by first dividing in two phase (odd and even). O
sorts/odd_even_sort.py:8
↓ 1 callersFunctionodd_even_transposition
>>> odd_even_transposition([5, 4, 3, 2, 1]) [1, 2, 3, 4, 5] >>> odd_even_transposition([13, 11, 18, 0, -1]) [-1, 0, 11, 13, 18]
sorts/odd_even_transposition_single_threaded.py:11
↓ 1 callersFunctionodd_even_transposition
>>> odd_even_transposition(list(range(10)[::-1])) == sorted(list(range(10)[::-1])) True >>> odd_even_transposition(["a", "x", "c"]) == so
sorts/odd_even_transposition_parallel.py:81
↓ 1 callersFunctionone_pence
()
project_euler/problem_031/sol1.py:16
↓ 1 callersFunctionone_pound
(x: int)
project_euler/problem_031/sol1.py:40
↓ 1 callersFunctionopen_knight_tour_helper
Helper function to solve knight tour problem.
backtracking/knight_tour.py:49
↓ 1 callersFunctionopening_filter
Opening filter, defined as the sequence of erosion and then a dilation filter on the same image. Examples: >>> img = np.array([[
computer_vision/haralick_descriptors.py:160
↓ 1 callersFunctionorbital_transfer_work
Calculates the work required to move an object from one orbit to another in a gravitational field based on the change in total mechanical ene
physics/orbital_transfer_work.py:1
↓ 1 callersFunctionoriginal_text
>>> original_text("BDC PAYUWL JPAIYI","SECRETSECRETSECRE") 'THE GERMAN ATTACK'
ciphers/beaufort_cipher.py:52
↓ 1 callersFunctionp_series
Pure Python implementation of P-Series algorithm :return: The P-Series starting from 1 to last (nth) term Examples: >>> p_series(5, 2
maths/series/p_series.py:15
↓ 1 callersMethodpadding
Pads the input message with zeros so that padded_data has 64 bytes or 512 bits
hashes/sha1.py:61
↓ 1 callersFunctionpage_rank
(nodes, limit=3, d=0.85)
graphs/page_rank.py:34
↓ 1 callersFunctionpancake_sort
Sort Array with Pancake Sort. :param arr: Collection containing comparable items :return: Collection ordered in ascending order of items E
sorts/pancake_sort.py:12
↓ 1 callersFunctionparse_args
(args: list)
digital_image_processing/filters/bilateral_filter.py:64
↓ 1 callersFunctionparse_file
Read the file and build a dict of all letters and their frequencies, then convert the dict into a list of Letters.
data_compression/huffman.py:23
↓ 1 callersFunctionparse_memory
(string)
sorts/external_sort.py:128
↓ 1 callersFunctionparse_moves
>>> parse_moves("0 1, 1 1") [(0, 1), (1, 1)] >>> parse_moves("0 1, 1 1, 2") Traceback (most recent call last): ... ValueE
matrix/matrix_based_game.py:105
↓ 1 callersFunctionparse_roman_numerals
Converts a string of roman numerals to an integer. e.g. >>> parse_roman_numerals("LXXXIX") 89 >>> parse_roman_numerals("IIII")
project_euler/problem_089/sol1.py:36
↓ 1 callersFunctionparse_token
Converts the given data to the appropriate number if it is indeed a number, else returns the data as it is with a False flag. This function a
data_structures/stacks/postfix_evaluation.py:40
↓ 1 callersFunctionpartition
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> partition(array, 0, len(array), 12) 8 >>> array = [21, 15,
sorts/intro_sort.py:108
↓ 1 callersFunctionpartition
Partitions list based on the pivot element. This function rearranges the elements in the input list 'elements' such that all elements gr
data_structures/arrays/kth_largest_element.py:8
↓ 1 callersFunctionpartition
Return a set of integers corresponding to unique prime partitions of n. The unique prime partitions can be represented as unique prime decomp
project_euler/problem_077/sol1.py:34
↓ 1 callersFunctionpartition_graph
Partitions a graph using Karger's Algorithm. Implemented from pseudocode found here: https://en.wikipedia.org/wiki/Karger%27s_algorithm.
graphs/karger.py:25
↓ 1 callersFunctionpassword_generator
Password Generator allows you to generate a random password of length N. >>> len(password_generator()) 8 >>> len(password_generator(
other/password.py:6
↓ 1 callersFunctionpatience_sort
A pure implementation of patience sort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable i
sorts/patience_sort.py:31
↓ 1 callersMethodpeek
(self)
data_structures/stacks/stack_using_two_queues.py:46
↓ 1 callersFunctionperfect
Check if a number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding
maths/perfect_number.py:15
↓ 1 callersFunctionperfect
Check if a number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding
maths/special_numbers/perfect_number.py:15
↓ 1 callersMethodperform_predator_actions
Performs the actions for a predator entity :param occupied_by_prey_coords: Move to this location if there is prey there For
cellular_automata/wa_tor.py:373
↓ 1 callersMethodperform_prey_actions
Performs the actions for a prey entity For prey the rules are: 1. At each chronon, a prey moves randomly to one of the a
cellular_automata/wa_tor.py:347
↓ 1 callersFunctionpermute_backtrack
Return all permutations of the given list. >>> permute_backtrack([1, 2, 3]) [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3,
data_structures/arrays/permutations.py:21
↓ 1 callersFunctionpheromone_update
Update pheromones on the route and update the best route >>> >>> pheromone_update(pheromone=[[1.0, 1.0], [1.0, 1.0]], ...
graphs/ant_colony_optimization_algorithms.py:115
↓ 1 callersFunctionpi
The Chudnovsky algorithm is a fast method for calculating the digits of PI, based on Ramanujan's PI formulae. https://en.wikipedia.org/w
maths/chudnovsky_algorithm.py:5
↓ 1 callersFunctionpigeon_sort
Implementation of pigeon hole sort algorithm :param array: Collection of comparable items :return: Collection sorted in ascending order
sorts/pigeon_sort.py:16
↓ 1 callersFunctionpigeonhole_sort
>>> a = [8, 3, 2, 7, 4, 6, 8] >>> b = sorted(a) # a nondestructive sort >>> pigeonhole_sort(a) # a destructive sort >>> a == b
sorts/pigeonhole_sort.py:6
↓ 1 callersMethodpivot
Pivots on value on the intersection of pivot row and column. >>> Tableau(np.array([[-2,-3,0,0,0],[1,3,1,0,4],[3,1,0,1,4.]]), ... 2, 2
linear_programming/simplex.py:149
↓ 1 callersFunctionplace_word
Place a word at the given position. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''],
backtracking/crossword_puzzle_solver.py:36
↓ 1 callersFunctionplay
Processes a single move, updating the matrix and calculating the score. >>> play([['R', 'G'], ['R', 'G']], 0, 0, 2) ([['G', '-'], ['G',
matrix/matrix_based_game.py:220
↓ 1 callersFunctionplot
Utility function to plot the vectors using matplotlib.pyplot No doctest was implemented since this function does not have a return value
fractals/koch_snowflake.py:92
↓ 1 callersFunctionplot_heterogeneity
(heterogeneity, k)
machine_learning/k_means_clust.py:125
↓ 1 callersMethodplot_histogram
(self)
digital_image_processing/histogram_equalization/histogram_stretch.py:49
↓ 1 callersFunctionplot_kmeans
(data, centroids, cluster_assignment)
machine_learning/k_means_clust.py:135
↓ 1 callersMethodplot_loss
(self)
neural_network/back_propagation_neural_network.py:166
↓ 1 callersFunctionplot_preds
Plot predictions and display the graph >>> pass # No doctests, function is for demo purposes only
machine_learning/local_weighted_learning/local_weighted_learning.py:151
↓ 1 callersFunctionpluperfect_number
Return True if n is a pluperfect number or False if it is not >>> all(pluperfect_number(n) for n in PASSING) True >>> any(pluperfect_numb
maths/special_numbers/armstrong_numbers.py:43
↓ 1 callersFunctionpollard_rho
Use Pollard's Rho algorithm to return a nontrivial factor of ``num``. The returned factor may be composite and require further factorization.
maths/pollard_rho.py:6
↓ 1 callersMethodpop
Pop the smallest value from the heap and return it. >>> rh = RandomizedHeap([3, 1, 3, 7]) >>> rh.pop() 1 >>>
data_structures/heap/randomized_heap.py:125
↓ 1 callersMethodpop
(self)
data_structures/stacks/stack_using_two_queues.py:43
↓ 1 callersFunctionpopulate_current_row
>>> triangle = [[1]] >>> populate_current_row(triangle, 1) [1, 1]
matrix/pascal_triangle.py:77
↓ 1 callersMethodpost_init
>>> Rectangle(5, 10) # doctest: +NORMALIZE_WHITESPACE Rectangle(sides=[Side(length=5, angle=Angle(degrees=90), next_side=None),
geometry/geometry.py:247
← previousnext →1,701–1,800 of 3,909, ranked by callers