MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 2 callersMethodadd_node
(self, node: T)
graphs/minimum_spanning_tree_prims2.py:206
↓ 2 callersMethodadd_node
(self, node: str)
graphs/markov_chain.py:15
↓ 2 callersMethodadd_side
>>> Polygon().add_side(Side(5)) Polygon(sides=[Side(length=5, angle=Angle(degrees=90), next_side=None)])
geometry/geometry.py:194
↓ 2 callersFunctionanagram
Return every anagram of the given word from the dictionary. >>> anagram('test') ['sett', 'stet', 'test'] >>> anagram('this is a test
strings/anagrams.py:25
↓ 2 callersFunctionanswer
Returns value by comparing with entered `to_guess` number
other/guess_the_number_search.py:121
↓ 2 callersFunctionapply_sbox
(s, data)
other/sdes.py:36
↓ 2 callersFunctionarea_under_curve_estimator
An implementation of the Monte Carlo method to find area under a single variable non-negative real-valued continuous function, say
maths/monte_carlo.py:42
↓ 2 callersFunctionassign_ranks
Assigns ranks to elements in the array. :param data: List of floats. :return: List of ints representing the ranks. Example: >>>
maths/spearman_rank_correlation_coefficient.py:4
↓ 2 callersMethodbalanced_factor
(self)
data_structures/hashing/hash_table.py:51
↓ 2 callersFunctionbalanced_parentheses
Use a stack to check if a string of parentheses is balanced. >>> balanced_parentheses("([]{})") True >>> balanced_parentheses("[()]{}{[()(
data_structures/stacks/balanced_parentheses.py:4
↓ 2 callersFunctionbead_sort
>>> bead_sort([6, 11, 12, 4, 1, 5]) [1, 4, 5, 6, 11, 12] >>> bead_sort([9, 8, 7, 6, 5, 4 ,3, 2, 1]) [1, 2, 3, 4, 5, 6, 7, 8, 9]
sorts/bead_sort.py:7
↓ 2 callersFunctionbenchmark_function
(name: str)
graphs/breadth_first_search_2.py:73
↓ 2 callersFunctionbenchmark_levenshtein_distance
Benchmark the Levenshtein distance function. :param str: The name of the function being benchmarked. :param func: The function to be benc
strings/levenshtein_distance.py:99
↓ 2 callersFunctionbisect_left
Locates the first element in a sorted array that is larger or equal to a given value. It has the same interface as https://docs.pyth
searches/binary_search.py:17
↓ 2 callersFunctionbisection
>>> bisection(-2, 5) 3.1611328125 >>> bisection(0, 6) 3.158203125 >>> bisection(2, 3) Traceback (most recent call last):
maths/numerical_analysis/bisection_2.py:27
↓ 2 callersFunctionbitonic_merge
It recursively sorts a bitonic sequence in ascending order, if direction = 1, and in descending if direction = 0. The sequence to be sort
sorts/bitonic_sort.py:41
↓ 2 callersFunctionbreadth_first_search
A breadth first search traversal with defaultdict ds to append the values of tree from top view
data_structures/binary_tree/diff_views_of_binary_tree.py:129
↓ 2 callersMethodbuild_max_heap
build max heap from an unsorted array >>> h = Heap() >>> h.build_max_heap([20,40,50,20,10]) >>> h [50, 40, 2
data_structures/heap/heap.py:134
↓ 2 callersFunctioncalculate_hypothesis_value
Calculates hypothesis value for a given example :param data_set: test data or train_data :param example_no: example whose hypothesis valu
machine_learning/gradient_descent.py:62
↓ 2 callersFunctioncalculate_prime_numbers
Returns prime numbers below max_number. See: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes >>> calculate_prime_numbers(10) [2,
project_euler/problem_187/sol1.py:41
↓ 2 callersFunctioncan_string_be_rearranged_as_palindrome_counter
A Palindrome is a String that reads the same forward as it does backwards. Examples of Palindromes mom, dad, malayalam >>> can_string_be_
strings/can_string_be_rearranged_as_palindrome.py:11
↓ 2 callersFunctioncatalan_number
We can find Catalan number many ways but here we use Binomial Coefficient because it does the job in O(n) return the Catalan number of n
data_structures/binary_tree/number_of_possible_binary_trees.py:42
↓ 2 callersFunctionchain
The function generates the chain of numbers until the next number is 1 or 89. For example, if starting number is 44, then the function genera
project_euler/problem_092/sol1.py:54
↓ 2 callersMethodcheck_can_perform_operation
(self)
data_structures/queues/circular_queue_linked_list.py:142
↓ 2 callersFunctioncheck_keys
(key_a: int, key_b: int, mode: str)
ciphers/affine_cipher.py:14
↓ 2 callersFunctionchoose
Calculate the binomial coefficient c(n,r) using the multiplicative formula. >>> choose(4,2) 6 >>> choose(5,3) 10 >>> choose(2
project_euler/problem_113/sol1.py:21
↓ 2 callersFunctionchunker
(seq: Iterable[str], size: int)
ciphers/playfair_cipher.py:27
↓ 2 callersFunctioncircle_bottom_arc_integral
Returns integral of circle bottom arc y = 1 / 2 - sqrt(1 / 4 - (x - 1 / 2) ^ 2) >>> circle_bottom_arc_integral(0) 0.39269908169872414
project_euler/problem_587/sol1.py:32
↓ 2 callersMethodcofactor
returns the cofactor (signed minor) along (x, y)
linear_algebra/src/lib.py:394
↓ 2 callersMethodcofactors
(self)
matrix/matrix_class.py:203
↓ 2 callersFunctioncolumn_based_sort
>>> column_based_sort([(5, 1), (4, 2), (3, 0)], 1) [(3, 0), (5, 1), (4, 2)]
divide_and_conquer/closest_pair_of_points.py:31
↓ 2 callersFunctioncombinations
(n, r)
project_euler/problem_053/sol1.py:23
↓ 2 callersFunctioncompress
Reads source file, compresses it and writes the compressed result in destination file
data_compression/lempel_ziv.py:113
↓ 2 callersMethodcompress
Compress the given string text using LZ77 compression algorithm. Args: text: string to be compressed Returns:
data_compression/lz77.py:69
↓ 2 callersFunctioncompute_truncated_primes
Returns the list of truncated primes >>> compute_truncated_primes(11) [23, 37, 53, 73, 313, 317, 373, 797, 3137, 3797, 739397]
project_euler/problem_037/sol1.py:94
↓ 2 callersFunctionconstruct_path
(current: int | None, parents: dict[int, int | None])
graphs/bidirectional_search.py:41
↓ 2 callersFunctionconvert_small_number
Converts small, non-negative integers with irregular constructions in English (i.e., numbers under 100) into words. >>> convert_small_nu
conversions/convert_number_to_words.py:95
↓ 2 callersFunctioncounting_sort
Pure implementation of counting sort algorithm in Python :param collection: some mutable ordered collection with heterogeneous comparable item
sorts/counting_sort.py:12
↓ 2 callersFunctioncreate_canvas
(size: int)
cellular_automata/game_of_life.py:44
↓ 2 callersFunctioncreate_tree
Create Frequent Pattern tree Args: data_set: A list of transactions, where each transaction is a list of items. min_sup: The
machine_learning/frequent_pattern_growth.py:55
↓ 2 callersFunctioncreate_vector
Pass two points to get the vector from them in the form (x, y, z). >>> create_vector((0, 0, 0), (1, 1, 1)) (1, 1, 1) >>> create_vect
maths/points_are_collinear_3d.py:35
↓ 2 callersFunctioncycle_sort
>>> cycle_sort([4, 3, 2, 1]) [1, 2, 3, 4] >>> cycle_sort([-4, 20, 0, -50, 100, -1]) [-50, -4, -1, 0, 20, 100] >>> cycle_sort([-
sorts/cycle_sort.py:7
↓ 2 callersMethoddecrease_key
Decrease the key value for a given tuple, assuming the new_d is at most old_d. Examples: >>> priority_queue_test = PriorityQ
graphs/dijkstra_algorithm.py:192
↓ 2 callersFunctiondecrypt
decrypt ======= Decodes a given string of cipher-text and returns the decoded plain-text Parameters: ----------- * `inpu
ciphers/caesar_cipher.py:91
↓ 2 callersFunctiondecrypt
Decrypt a given `ciphertext` (string) and `key` (string), returning the decrypted ciphertext. >>> decrypt("jsqqs avvwo", "coffee") '
ciphers/autokey.py:77
↓ 2 callersMethoddelete
Deletes a word from the tree if it exists Args: word (str): word to be deleted Returns: bool: True if the wo
data_structures/trie/radix_tree.py:131
↓ 2 callersMethoddelete_front
Delete and return the data of the node at the front of the Circular Linked List. Raises: IndexError: If the list is empty
data_structures/linked_list/circular_linked_list.py:89
↓ 2 callersMethoddelete_tail
Delete and return the data of the node at the end of the Circular Linked List. Returns: Any: The data of the deleted node
data_structures/linked_list/circular_linked_list.py:97
↓ 2 callersFunctiondencrypt
https://en.wikipedia.org/wiki/ROT13 >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!" >>> s = dencrypt(msg)
ciphers/rot13.py:1
↓ 2 callersMethoddepth
>>> root = Node(1) >>> root.depth() 1 >>> root.left = Node(2) >>> root.depth() 2 >>> root.lef
data_structures/binary_tree/diameter_of_binary_tree.py:17
↓ 2 callersFunctiondepth_first_search
A depth first search preorder traversal to append the values at right side of tree.
data_structures/binary_tree/diff_views_of_binary_tree.py:46
↓ 2 callersMethoddepth_first_search
(self, vertex, sink, flow)
graphs/dinic.py:22
↓ 2 callersMethoddeterminant
returns the determinant of an nxn matrix using Laplace expansion
linear_algebra/src/lib.py:405
↓ 2 callersFunctiondistance
Calculate the distance between two coordinate points >>> distance([0, 0], [3, 4] ) 5.0 >>> distance([0, 0], [-3, 4] ) 5.0 >>>
graphs/ant_colony_optimization_algorithms.py:102
↓ 2 callersFunctiondo_something
(back_pointer, goal, start)
graphs/multi_heuristic_astar.py:81
↓ 2 callersFunctionencrypt
>>> encrypt('marvin', 'jessica') 'QRACRWU'
ciphers/porta_cipher.py:41
↓ 2 callersFunctionencrypt
encrypt ======= Encodes a given string with the caesar cipher and returns the encoded message Parameters: -----------
ciphers/caesar_cipher.py:6
↓ 2 callersFunctionenigma
The only difference with real-world enigma is that ``I`` allowed string input. All characters are converted to uppercase. (non-letter symbol
ciphers/enigma_machine2.py:167
↓ 2 callersFunctioneuclidean
Calculates euclidean distance between two data. :param input_a: ndarray of first vector. :param input_b: ndarray of second vector. :r
machine_learning/similarity_search.py:19
↓ 2 callersFunctioneuclidean_distance_sqr
>>> euclidean_distance_sqr([1,2],[2,4]) 5
divide_and_conquer/closest_pair_of_points.py:23
↓ 2 callersFunctionevaluate
Evaluate a given expression in prefix notation. Asserts that the given expression is valid. >>> evaluate("+ 9 * 2 6") 21 >>> eva
data_structures/stacks/prefix_evaluation.py:26
↓ 2 callersMethodevaluate
Evaluates the clause with the assignments in model. This has the following steps: 1. Return ``True`` if both a literal and
other/davis_putnam_logemann_loveland.py:76
↓ 2 callersFunctionexpand_search
( graph: dict[int, list[int]], queue: deque[int], parents: dict[int, int | None], opposite_dir
graphs/bidirectional_search.py:17
↓ 2 callersFunctionexpand_state
( s, j, visited, g_function, close_list_anchor, close_list_inad, open_list, ba
graphs/multi_heuristic_astar.py:129
↓ 2 callersFunctionextended_euclid
>>> extended_euclid(10, 6) (-1, 2) >>> extended_euclid(7, 5) (-2, 3)
maths/chinese_remainder_theorem.py:19
↓ 2 callersMethodextract_max
get and remove max from heap >>> h = Heap() >>> h.build_max_heap([20,40,50,20,10]) >>> h.extract_max() 50
data_structures/heap/heap.py:165
↓ 2 callersMethodextract_min
(self)
graphs/minimum_spanning_tree_prims2.py:108
↓ 2 callersFunctionextract_user_profile
May raise json.decoder.JSONDecodeError
web_programming/instagram_crawler.py:23
↓ 2 callersFunctionf_derivative
(x: float)
maths/numerical_analysis/newton_raphson.py:82
↓ 2 callersFunctionfactors
>>> factors(12) [1, 2, 3, 4, 6] >>> factors(1) [1] >>> factors(100) [1, 2, 4, 5, 10, 20, 25, 50] # >>> factors(-12)
maths/special_numbers/weird_number.py:10
↓ 2 callersMethodfeedforward
The information moves in only one direction i.e. forward from the input nodes, through the two hidden nodes and to the output nodes.
neural_network/two_hidden_layers_neural_network.py:53
↓ 2 callersFunctionfetch_github_info
Fetch GitHub info of a user using the httpx module
web_programming/fetch_github_info.py:44
↓ 2 callersFunctionfib_recursive_term
Calculates the i-th (0-indexed) Fibonacci number using recursion >>> fib_recursive_term(0) 0 >>> fib_recursive_term(1
maths/fibonacci.py:108
↓ 2 callersMethodfinal_hash
Calls all the other methods to process the input. Pads the data, then splits into blocks and then does a series of operations for eac
hashes/sha1.py:88
↓ 2 callersFunctionfind_circular_primes
Return circular primes below limit. >>> len(find_circular_primes(100)) 13 >>> len(find_circular_primes(1000000)) 55
project_euler/problem_035/sol1.py:56
↓ 2 callersMethodfind_component
Propagates a new component throughout a given component.
graphs/boruvka.py:54
↓ 2 callersFunctionfind_median
This is the implementation of the median. :param nums: The list of numeric nums :return: Median of the list >>> find_median(nums=([1,
maths/interquartile_range.py:14
↓ 2 callersFunctionfind_parent
(i)
graphs/minimum_spanning_tree_kruskal.py:19
↓ 2 callersFunctionfind_python_set
Return a Python Standard Library set that contains i.
data_structures/disjoint_set/disjoint_set.py:51
↓ 2 callersFunctionfisher_yates_shuffle
(data: list)
other/fischer_yates_shuffle.py:13
↓ 2 callersMethodformat_bin
(self, bitarray: int)
data_structures/hashing/bloom_filter.py:83
↓ 2 callersFunctionfreq_to_mel
Convert a frequency in Hertz to the mel scale. Args: freq: The frequency in Hertz. Returns: The frequency in mel scale.
machine_learning/mfcc.py:274
↓ 2 callersFunctiongenerate_all_combinations
Generates all possible combinations of k numbers out of 1 ... n using backtracking. >>> generate_all_combinations(n=4, k=2) [[1, 2], [1,
backtracking/all_combinations.py:23
↓ 2 callersFunctiongenerate_all_permutations
(sequence: list[int | str])
backtracking/all_permutations.py:12
↓ 2 callersFunctiongenerate_all_subsequences
(sequence: list[Any])
backtracking/all_subsequences.py:14
↓ 2 callersFunctiongenerate_table
(key: str)
ciphers/playfair_cipher.py:62
↓ 2 callersMethodget_edges
Returna all edges in the graph
graphs/minimum_spanning_tree_boruvka.py:68
↓ 2 callersFunctionget_failure_array
Calculates the new index we should go to if we fail a comparison :param pattern: :return:
strings/knuth_morris_pratt.py:45
↓ 2 callersMethodget_greyscale
>>> Burkes.get_greyscale(3, 4, 5) 4.185 >>> Burkes.get_greyscale(0, 0, 0) 0.0 >>> Burkes.get_greyscale(255, 2
digital_image_processing/dithering/burkes.py:40
↓ 2 callersFunctionget_matched_characters
(_str1: str, _str2: str)
strings/jaro_winkler.py:28
↓ 2 callersMethodget_max
Returns the largest element in this tree. This method is guaranteed to run in O(log(n)) time.
data_structures/binary_tree/red_black_tree.py:402
↓ 2 callersMethodget_neighbors
Returns a list of coordinates of neighbors adjacent to the current coordinates. Neighbors: | 0 | 1 | 2 | | 3 | _ | 4
searches/hill_climbing.py:37
↓ 2 callersFunctionget_nodes_from_left_to_right
Returns a list of nodes value from a particular level: Left to right direction of the binary tree. >>> list(get_nodes_from_left_to_rig
data_structures/binary_tree/binary_tree_traversals.py:119
↓ 2 callersFunctionget_openlibrary_data
Given an 'isbn/0140328726', return book data from Open Library as a Python dict. Given an '/authors/OL34184A', return authors data as a Pytho
web_programming/search_books_by_isbn.py:19
↓ 2 callersMethodget_parent
Find the Parent of a given set >>> A = DisjointSet([1, 1, 1]) >>> A.merge(1, 2) True >>> A.get_parent(0)
data_structures/disjoint_set/alternate_disjoint_set.py:54
↓ 2 callersFunctionget_parent_position
heap helper function get the position of the parent of the current node >>> get_parent_position(1) 0 >>> get_parent_position(2)
graphs/minimum_spanning_tree_prims2.py:18
↓ 2 callersFunctionget_point_key
Returns the hash key of matrix indexes. >>> get_point_key(10, 20, 1, 0) 200
backtracking/word_search.py:36
↓ 2 callersMethodget_prev
Get previous index in O(1)
data_structures/binary_tree/maximum_fenwick_tree.py:61
↓ 2 callersMethodget_weight
(self)
other/greedy.py:16
↓ 2 callersMethodget_winner
Compute the winning vector by Euclidean distance >>> SelfOrganizingMap().get_winner([[1, 2, 3], [4, 5, 6]], [1, 2, 3]) 1
machine_learning/self_organizing_map.py:9
← previousnext →401–500 of 3,909, ranked by callers