MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionfifty_pence
(x: int)
project_euler/problem_031/sol1.py:36
↓ 1 callersFunctionfill_row
>>> fill_row([2, 2, 2], [1, 2, 3]) [3, 4, 5]
graphs/minimum_path_sum.py:47
↓ 1 callersFunctionfilter_common_word
Given a list of possible decoded messages, narrow down the possibilities for checking for the presence of a specified common word. Only decod
project_euler/problem_059/sol1.py:88
↓ 1 callersFunctionfilter_valid_chars
Given an encrypted message, test all 3-character strings to try and find the key. Return a list of the possible decrypted messages. >>> f
project_euler/problem_059/sol1.py:69
↓ 1 callersMethodfinal_hash
(self)
hashes/sha256.py:126
↓ 1 callersFunctionfind_components
Use depth first search to find strongly connected vertices. Now graph is reversed >>> find_components({0: [1], 1: [2], 2: [0]}, 0, 5 * [F
graphs/strongly_connected_components.py:37
↓ 1 callersFunctionfind_empty_location
This function finds an empty location so that we can assign a number for that particular row and column.
backtracking/sudoku.py:63
↓ 1 callersFunctionfind_freq_subgraph_given_support
find edges of multiple frequent subgraphs
graphs/frequent_pattern_graph_miner.py:184
↓ 1 callersFunctionfind_longest_chain
Finds the smallest element of longest chain >>> find_longest_chain(chain=[0, 0, 0, 0, 0, 0, 6], max_num=6) 6
project_euler/problem_095/sol1.py:107
↓ 1 callersFunctionfind_max_area
Finds the area of all islands and returns the maximum area. >>> find_max_area(matrix) 6
matrix/max_area_of_island.py:55
↓ 1 callersMethodfind_maximum_flow
(self)
graphs/edmonds_karp_multiple_source_and_sink.py:47
↓ 1 callersFunctionfind_minimum_change
Find the minimum change from the given denominations and value >>> find_minimum_change([1, 5, 10, 20, 50, 100, 200, 500, 1000,2000], 18745)
greedy_methods/minimum_coin_change.py:44
↓ 1 callersFunctionfind_minimum_partitions
Returns the minimum cuts needed for a palindrome partitioning of string >>> find_minimum_partitions("aab") 1 >>> find_minimum_partit
dynamic_programming/palindrome_partitioning.py:12
↓ 1 callersFunctionfind_narcissistic_numbers
Find all narcissistic numbers up to the given limit using dynamic programming. This function uses memoization to cache digit power calculati
dynamic_programming/narcissistic_number.py:27
↓ 1 callersFunctionfind_negative_index
Find the smallest negative index >>> find_negative_index([0,0,0,0]) 4 >>> find_negative_index([4,3,2,-1]) 3 >>> find_negativ
matrix/count_negative_numbers_in_sorted_matrix.py:37
↓ 1 callersFunctionfind_neighborhood
Pure implementation of generating the neighborhood (sorted by total distance of each solution from lowest to highest) of a solution with 1-1
searches/tabu_search.py:127
↓ 1 callersFunctionfind_optimal_binary_search_tree
This function calculates and prints the optimal binary search tree. The dynamic programming algorithm below runs in O(n^2) time. Implemen
dynamic_programming/optimal_binary_search_tree.py:68
↓ 1 callersMethodfind_pivot
Finds the pivot row and column. >>> tuple(int(x) for x in Tableau(np.array([[-2,1,0,0,0], [3,1,1,0,6], ... [1,2,0,1,7.]]), 2, 0).find_
linear_programming/simplex.py:108
↓ 1 callersFunctionfind_prefix_path
Find the conditional pattern base for a given base pattern. Args: base_pat: The base pattern for which to find the conditional patte
machine_learning/frequent_pattern_growth.py:243
↓ 1 callersFunctionfind_primitive
Find a primitive root modulo modulus, if one exists. Args: modulus : The modulus for which to find a primitive root. Retu
ciphers/diffie.py:4
↓ 1 callersFunctionfind_pure_symbols
| Return pure symbols and their values to satisfy clause. | Pure symbols are symbols in a formula that exist only in one form, | either c
other/davis_putnam_logemann_loveland.py:184
↓ 1 callersFunctionfind_repeat
Finds all connected elements of the same type from a given position. >>> find_repeat([['A', 'B', 'A'], ['A', 'B', 'A'], ['A', 'A', 'A']], 0,
matrix/matrix_based_game.py:128
↓ 1 callersFunctionfind_secret_passcode
Returns the shortest possible secret passcode of unknown length. >>> find_secret_passcode(["135", "259", "235", "189", "690", "168", "120",
project_euler/problem_079/sol1.py:21
↓ 1 callersFunctionfind_unit_clauses
Returns the unit symbols and their values to satisfy clause. Unit symbols are symbols in a formula that are: - Either the only symbol
other/davis_putnam_logemann_loveland.py:235
↓ 1 callersMethodfind_word
(self, prefix: str)
strings/autocomplete_using_trie.py:18
↓ 1 callersMethodfirst_come_first_served
FCFS(First Come, First Served) FCFS will be applied to MLFQ's last queue A first came process will be finished at first
scheduling/multi_level_feedback_queue.py:150
↓ 1 callersMethodfit
Computes the polynomial regression model parameters using ordinary least squares (OLS) estimation: β = (XᵀX)⁻¹Xᵀy = X⁺y
machine_learning/polynomial_regression.py:102
↓ 1 callersMethodfit
Fit the GradientBoostingClassifier to the training data. Parameters: - features (np.ndarray): The training features.
machine_learning/gradient_boosting_classifier.py:26
↓ 1 callersFunctionfive_pence
(x: int)
project_euler/problem_031/sol1.py:24
↓ 1 callersFunctionfixed_priority_queue
()
data_structures/queues/priority_queue_using_list.py:180
↓ 1 callersFunctionflatten
Flatten a binary tree into a linked list in-place, where the linked list is represented using the right pointers of the tree nodes. Args
data_structures/binary_tree/flatten_binarytree_to_linkedlist.py:60
↓ 1 callersFunctionfloyd
Print the upper half of a diamond pattern with '*' characters. Args: n (int): Size of the pattern. Examples: >>>
other/magicdiamondpattern.py:5
↓ 1 callersFunctionfloyd_warshall
:param graph: 2D array calculated from weight[edge[i, j]] :type graph: List[List[float]] :param v: number of vertices :type v: int
graphs/graphs_floyd_warshall.py:19
↓ 1 callersMethodfloyd_warshall
Computes the shortest paths between all pairs of nodes using the Floyd-Warshall algorithm. >>> g = Graph(3) >>>
dynamic_programming/floyd_warshall.py:26
↓ 1 callersFunctionford_fulkerson
This function returns the maximum flow from source to sink in the given graph. CAUTION: This function changes the given graph. Args:
networking_flow/ford_fulkerson.py:58
↓ 1 callersFunctionformat_ruleset
>>> format_ruleset(11100) [0, 0, 0, 1, 1, 1, 0, 0] >>> format_ruleset(0) [0, 0, 0, 0, 0, 0, 0, 0] >>> format_ruleset(11111111)
cellular_automata/one_dimensional.py:18
↓ 1 callersFunctionforward_propagation
Return the value found after the forward propagation training. >>> res = forward_propagation(32, 450_000) # Was 10_000_000 >>> res > 31 and
neural_network/simple_neural_network.py:28
↓ 1 callersMethodforward_propagation
(self, xdata)
neural_network/back_propagation_neural_network.py:69
↓ 1 callersFunctionfraction_list
>>> fraction_list(2) ['16/64', '19/95', '26/65', '49/98'] >>> fraction_list(3) ['16/64', '19/95', '26/65', '49/98'] >>> fraction_
project_euler/problem_033/sol1.py:29
↓ 1 callersFunctionfreq_subgraphs_edge_list
returns Edge list for frequent subgraphs
graphs/frequent_pattern_graph_miner.py:193
↓ 1 callersFunctionfunction_to_integrate
Represents semi-circle with radius 2 >>> [function_to_integrate(x) for x in [-2.0, 0.0, 2.0]] [0.0, 2.0, 0.0]
maths/monte_carlo.py:108
↓ 1 callersFunctionfx
(x: float, a: float)
maths/numerical_analysis/square_root.py:4
↓ 1 callersFunctionfx_derivative
(x: float)
maths/numerical_analysis/square_root.py:8
↓ 1 callersFunctiongabor_filter_kernel
:param ksize: The kernelsize of the convolutional filter (ksize x ksize) :param sigma: standard deviation of the gaussian bell curve
digital_image_processing/filters/gabor_filter.py:7
↓ 1 callersFunctiongamma_iterative
Calculates the value of Gamma function of num where num is either an integer (1, 2, 3..) or a half-integer (0.5, 1.5, 2.5 ...). >>> gamm
maths/gamma.py:18
↓ 1 callersFunctiongamma_recursive
Calculates the value of Gamma function of num where num is either an integer (1, 2, 3..) or a half-integer (0.5, 1.5, 2.5 ...). Implement
maths/gamma.py:54
↓ 1 callersFunctiongauss_easter
Calculation Gregorian easter date for given year >>> gauss_easter(2007) datetime.datetime(2007, 4, 8, 0, 0, tzinfo=datetime.timezone.utc
other/gauss_easter.py:9
↓ 1 callersFunctiongaussian_distribution
Generate gaussian distribution instances based-on given mean and standard deviation :param mean: mean value of class :param std_dev: valu
machine_learning/linear_discriminant_analysis.py:53
↓ 1 callersFunctiongen_gaussian_kernel
(k_size, sigma)
digital_image_processing/edge_detection/canny.py:10
↓ 1 callersFunctiongen_gaussian_kernel
(k_size, sigma)
digital_image_processing/filters/gaussian_filter.py:11
↓ 1 callersFunctiongenerate
(k: int, arr: list)
divide_and_conquer/heaps_algorithm.py:35
↓ 1 callersFunctiongenerate
(n: int, arr: list)
divide_and_conquer/heaps_algorithm_iterative.py:35
↓ 1 callersMethodgenerate_board
Generates a board with a random direction for each word. >>> wt = WordSearch(WORDS, WIDTH, HEIGHT) >>> wt.generate_board()
other/word_search.py:316
↓ 1 callersFunctiongenerate_clause
| Randomly generate a clause. | All literals have the name Ax, where x is an integer from ``1`` to ``5``.
other/davis_putnam_logemann_loveland.py:123
↓ 1 callersMethodgenerate_col_titles
Generate column titles for tableau of specific dimensions >>> Tableau(np.array([[-1,-1,0,0,1],[1,3,1,0,4],[3,1,0,1,4.]]), ... 2, 0).g
linear_programming/simplex.py:86
↓ 1 callersFunctiongenerate_final_scores
>>> generate_final_scores([[1.0, 0.0, 0.33333333333333337], ... [0.75, 0.0, 1.0], ... [0.25
other/scoring_algorithm.py:80
↓ 1 callersFunctiongenerate_first_solution
Pure implementation of generating the first solution for the Tabu search to start, with the redundant resolution strategy. That means that we
searches/tabu_search.py:74
↓ 1 callersFunctiongenerate_formula
Randomly generate a formula.
other/davis_putnam_logemann_loveland.py:146
↓ 1 callersFunctiongenerate_gon_ring
Generate a gon_side-gon ring from a permutation state The permutation state is the ring, but every duplicate is removed >>> generate_gon
project_euler/problem_068/sol1.py:80
↓ 1 callersFunctiongenerate_image
Convert the cells into a greyscale PIL.Image.Image and return it to the caller. >>> from random import random >>> cells = [[random() for
cellular_automata/one_dimensional.py:44
↓ 1 callersFunctiongenerate_images
Generates a list of images of subsequent Game of Life states.
cellular_automata/conways_game_of_life.py:72
↓ 1 callersFunctiongenerate_key
(key_size: int)
ciphers/elgamal_key_generator.py:27
↓ 1 callersFunctiongenerate_key
>>> generate_key("THE GERMAN ATTACK","SECRET") 'SECRETSECRETSECRE'
ciphers/beaufort_cipher.py:14
↓ 1 callersFunctiongenerate_key
>>> random.seed(0) # for repeatability >>> public_key, private_key = generate_key(8) >>> public_key (26569, 239) >>> private_key
ciphers/rsa_key_generator.py:16
↓ 1 callersFunctiongenerate_large_matrix
>>> generate_large_matrix() # doctest: +ELLIPSIS [[1000, ..., -999], [999, ..., -1001], ..., [2, ..., -1998]]
matrix/count_negative_numbers_in_sorted_matrix.py:9
↓ 1 callersFunctiongenerate_large_prime
(keysize: int = 1024)
ciphers/rabin_miller.py:213
↓ 1 callersFunctiongenerate_neighbours
Pure implementation of generating a dictionary of neighbors and the cost with each neighbor, given a path file that includes a graph. :p
searches/tabu_search.py:32
↓ 1 callersFunctiongenerate_parameters
| Return the clauses and symbols from a formula. | A symbol is the uncomplemented form of a literal. For example, * Symbol of A3 i
other/davis_putnam_logemann_loveland.py:157
↓ 1 callersFunctiongenerate_parentheses_iterative
Generate all valid combinations of parentheses (Iterative Approach). The algorithm works as follows: 1. Initialize an empty list to stor
backtracking/generate_parentheses_iterative.py:1
↓ 1 callersFunctiongenerate_pascal_triangle
Create Pascal's triangle for different number of rows >>> generate_pascal_triangle(0) [] >>> generate_pascal_triangle(1) [[1]]
matrix/pascal_triangle.py:35
↓ 1 callersFunctiongenerate_permutation_key
Generate a random permutation key of a specified block size. Args: block_size (int): The size of each permutation block. Return
ciphers/permutation_cipher.py:37
↓ 1 callersFunctiongenerate_primes
Calculates the list of primes up to and including `max_num`. >>> generate_primes(6) [2, 3, 5]
project_euler/problem_095/sol1.py:34
↓ 1 callersFunctiongenerate_random_hand
()
project_euler/problem_054/test_poker_hand.py:139
↓ 1 callersFunctiongenerate_roman_numerals
Generates a string of roman numerals for a given integer. e.g. >>> generate_roman_numerals(89) 'LXXXIX' >>> generate_roman_numera
project_euler/problem_089/sol1.py:62
↓ 1 callersFunctiongenerate_table
>>> generate_table('marvin') # doctest: +NORMALIZE_WHITESPACE [('ABCDEFGHIJKLM', 'UVWXYZNOPQRST'), ('ABCDEFGHIJKLM', 'NOPQRSTUVWXYZ'),
ciphers/porta_cipher.py:31
↓ 1 callersFunctiongenerate_valid_block_size
Generate a valid block size that is a factor of the message length. Args: message_length (int): The length of the message. Retu
ciphers/permutation_cipher.py:14
↓ 1 callersFunctiongeometric_series
Pure Python implementation of Geometric Series algorithm :param nth_term: The last term (nth term of Geometric Series) :param start_term
maths/series/geometric_series.py:15
↓ 1 callersMethodget
Get value at index in O(lg N) Parameters: index (int): index to get the value Returns: int: Value o
data_structures/binary_tree/fenwick_tree.py:178
↓ 1 callersMethodget
Returns the value for the input key and updates the Double Linked List. Returns Returns None if key is not present in cache
other/lfu_cache.py:232
↓ 1 callersFunctionget_3d_vectors_cross
Get the cross of the two vectors AB and AC. I used determinant of 2x2 to get the determinant of the 3x3 matrix in the process. Read Mor
maths/points_are_collinear_3d.py:52
↓ 1 callersFunctionget_amazon_product_data
Take a product name or category as input and return product information from Amazon including title, URL, price, ratings, and the discount av
web_programming/get_amazon_product_data.py:23
↓ 1 callersFunctionget_anime_episode
[summary] Get click url and download url from episode url >>> type(get_anime_episode("/watch/kimetsu-no-yaiba/1")) <class 'list'> A
web_programming/fetch_anime_and_play.py:125
↓ 1 callersFunctionget_apod_data
Get the APOD(Astronomical Picture of the day) data Get your API Key from: https://api.nasa.gov/
web_programming/nasa_data.py:11
↓ 1 callersFunctionget_archive_data
Get the data of a particular query from NASA archives
web_programming/nasa_data.py:32
↓ 1 callersFunctionget_avg
Return the mid-number(whole) of two integers a and b >>> get_avg(10, 15) 12 >>> get_avg(20, 300) 160 >>> get_avg("abcd", 3
other/guess_the_number_search.py:58
↓ 1 callersFunctionget_band_type_count
Function returns the number of bands of a given type in a resistor with n bands Function takes total_number_of_bands and type_of_band as inpu
electronics/resistor_color_code.py:221
↓ 1 callersFunctionget_barcode
Returns the barcode as an integer >>> get_barcode("8718452538119") 8718452538119 >>> get_barcode("dwefgiweuf") Traceback (most r
strings/barcode_validator.py:56
↓ 1 callersFunctionget_bitcode
Return bitcode of distinct_edge
graphs/frequent_pattern_graph_miner.py:40
↓ 1 callersFunctionget_black_and_white_rgb
Black&white color-coding that ignores the relative distance. The Mandelbrot set is black, everything else is white. >>> get_black_an
fractals/mandelbrot.py:50
↓ 1 callersMethodget_block_filenames
(self)
sorts/external_sort.py:23
↓ 1 callersFunctionget_block_words
Splits bit string into blocks of 512 chars and yields each block as a list of 32-bit words Example: Suppose the input is the following:
hashes/md5.py:134
↓ 1 callersFunctionget_blocks_from_text
( message: str, block_size: int = DEFAULT_BLOCK_SIZE )
ciphers/rsa_cipher.py:10
↓ 1 callersFunctionget_bounds
Get bounds for printing fft results >>> import numpy >>> array = numpy.linspace(-20.0, 20.0, 1000) >>> get_bounds(array, 1000) (
audio_filters/show_response.py:22
↓ 1 callersFunctionget_check_digit
Returns the last digit of barcode by excluding the last digit first and then computing to reach the actual last digit from the remaining
strings/barcode_validator.py:6
↓ 1 callersFunctionget_child_left_position
heap helper function get the position of the left child of the current node >>> get_child_left_position(0) 1
graphs/minimum_spanning_tree_prims2.py:30
↓ 1 callersFunctionget_child_right_position
heap helper function get the position of the right child of the current node >>> get_child_right_position(0) 2
graphs/minimum_spanning_tree_prims2.py:40
↓ 1 callersFunctionget_citation
Return the citation number.
web_programming/crawl_google_scholar_citation.py:18
↓ 1 callersFunctionget_cluster
Returns cluster format cluster:{WT(bitcode):nodes with same WT}
graphs/frequent_pattern_graph_miner.py:88
↓ 1 callersFunctionget_color_coded_rgb
Color-coding taking the relative distance into account. The Mandelbrot set is black. >>> get_color_coded_rgb(0) (255, 0, 0)
fractals/mandelbrot.py:68
↓ 1 callersFunctionget_cost_derivative
:param index: index of the parameter vector wrt to derivative is to be calculated :return: derivative wrt to that index Note: If index is
machine_learning/gradient_descent.py:94
← previousnext →1,201–1,300 of 3,909, ranked by callers