MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionconcave_triangle_area
Returns area of concave triangle >>> concave_triangle_area(1) 0.026825229575318944 >>> concave_triangle_area(2) 0.0195623614008
project_euler/problem_587/sol1.py:51
↓ 1 callersFunctionconjugate_gradient
Returns solution to the linear system np.dot(spd_matrix, x) = b. Input: spd_matrix is an NxN Symmetric Positive Definite (SPD) matrix.
linear_algebra/src/conjugate_gradient.py:71
↓ 1 callersFunctionconsistent_heuristic
(p: TPos, goal: TPos)
graphs/multi_heuristic_astar.py:59
↓ 1 callersFunctionconstruct_graph
(cluster, nodes)
graphs/frequent_pattern_graph_miner.py:154
↓ 1 callersFunctioncontains_an_even_digit
Return True if n contains an even digit. >>> contains_an_even_digit(0) True >>> contains_an_even_digit(975317933) False
project_euler/problem_035/sol1.py:43
↓ 1 callersFunctioncontains_origin
Check if the triangle given by the points A(x1, y1), B(x2, y2), C(x3, y3) contains the origin. >>> contains_origin(-340, 495, -153, -910,
project_euler/problem_102/sol1.py:38
↓ 1 callersFunctioncontinued_fraction
:param num: Fraction of the number whose continued fractions to be found. Use Fraction(str(number)) for more accurate results due to
maths/continued_fraction.py:11
↓ 1 callersFunctioncontinuous_fraction_period
Returns the continued fraction period of a number n. >>> continuous_fraction_period(2) 1 >>> continuous_fraction_period(5) 1
project_euler/problem_064/sol1.py:19
↓ 1 callersFunctionconvert_currency
https://www.amdoren.com/currency-api/
web_programming/currency_converter.py:178
↓ 1 callersFunctionconvert_number
Converts an integer to English words. :param num: The integer to be converted :param system: The numbering system (short, long, or India
conversions/convert_number_to_words.py:137
↓ 1 callersFunctionconvert_path_to_module
Converts a file path to a Python module
scripts/validate_solutions.py:30
↓ 1 callersFunctionconvert_to_2d
Converts 3d point to a 2d drawable point >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) (7.6923076923076925, 15.384615384615385) >>>
graphics/vector3_for_2d_rendering.py:13
↓ 1 callersFunctionconvert_to_negative
(img)
digital_image_processing/convert_to_negative.py:8
↓ 1 callersFunctionconvex_hull_bf
Constructs the convex hull of a set of 2D points using a brute force algorithm. The algorithm basically considers all combinations of points
divide_and_conquer/convex_hull.py:223
↓ 1 callersFunctionconvex_hull_melkman
Constructs the convex hull of a set of 2D points using the melkman algorithm. The algorithm works by iteratively inserting points of a simple
divide_and_conquer/convex_hull.py:409
↓ 1 callersFunctionconvex_hull_recursive
Constructs the convex hull of a set of 2D points using a divide-and-conquer strategy The algorithm exploits the geometric properties of the p
divide_and_conquer/convex_hull.py:295
↓ 1 callersFunctioncost_function
Cost function quantifies the error between predicted and expected values. The cost function used in Logistic Regression is called Log Loss
machine_learning/logistic_regression.py:66
↓ 1 callersFunctioncount_coins
>>> count_coins(None) 0
data_structures/binary_tree/distribute_coins.py:92
↓ 1 callersFunctioncount_divisors
(n)
project_euler/problem_012/sol1.py:26
↓ 1 callersFunctioncount_divisors
(n)
project_euler/problem_012/sol2.py:31
↓ 1 callersMethodcount_no_of_ways
(self, task_performed)
dynamic_programming/bitmask.py:64
↓ 1 callersFunctioncount_nodes
>>> count_nodes(None) 0
data_structures/binary_tree/distribute_coins.py:82
↓ 1 callersFunctioncount_of_possible_combinations
(target: int)
dynamic_programming/combination_sum_iv.py:35
↓ 1 callersFunctioncount_of_possible_combinations_with_dp_array
( target: int, dp_array: list[int] )
dynamic_programming/combination_sum_iv.py:55
↓ 1 callersMethodcount_ways_until
(self, mask, task_no)
dynamic_programming/bitmask.py:31
↓ 1 callersFunctioncounting_sort_string
>>> counting_sort_string("thisisthestring") 'eghhiiinrsssttt'
sorts/counting_sort.py:59
↓ 1 callersFunctioncovariance
>>> covariance([1, 2], [-2, 5, 8], [0.7, 0.3], [0.3, 0.5, 0.2]) -2.7755575615628914e-17
maths/joint_probability_distribution.py:52
↓ 1 callersFunctioncovariance_between_classes
Function to compute the covariance matrix between multiple classes >>> features = np.array([[9, 2, 3], [4, 3, 6], [1, 8, 9]]) >>> labels = np.
machine_learning/dimensionality_reduction.py:60
↓ 1 callersFunctioncovariance_within_classes
Function to compute the covariance matrix inside each class. >>> features = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> labels = np.array(
machine_learning/dimensionality_reduction.py:32
↓ 1 callersFunctioncovid_stats
( url: str = ( "https://web.archive.org/web/20250825095350/" "https://www.worldometers.inf
web_programming/covid_stats_via_xpath.py:28
↓ 1 callersFunctioncreate_all_state
Helper function to recursively build all combinations. >>> create_all_state(1, 4, 2, [], result := []) >>> result [[1, 2], [1, 3], [
backtracking/all_combinations.py:64
↓ 1 callersFunctioncreate_cipher_map
Returns a cipher map given a keyword. :param key: keyword to use :return: dictionary cipher map
ciphers/simple_keyword_cypher.py:20
↓ 1 callersFunctioncreate_edge
create edge between the nodes
graphs/frequent_pattern_graph_miner.py:130
↓ 1 callersFunctioncreate_graph
>>> n = 7 >>> source = [0, 0, 1, 2, 3, 3, 4, 4, 6] >>> target = [1, 3, 2, 0, 1, 4, 5, 6, 5] >>> edges = list(zip(source, target))
graphs/tarjans_scc.py:83
↓ 1 callersMethodcreate_linked_list
(self, initial_capacity: int)
data_structures/queues/circular_queue_linked_list.py:27
↓ 1 callersFunctioncreate_sparse
creating sparse table which saves each nodes 2^i-th parent >>> max_node = 6 >>> parent = [[0, 0, 1, 1, 2, 2, 3]] + [[0] * 7 for _ in rang
data_structures/binary_tree/lowest_common_ancestor.py:27
↓ 1 callersFunctioncreate_state_space_tree
Creates a state space tree to iterate through each branch using DFS. It terminates the branching of a node when any of the two conditions
backtracking/sum_of_subsets.py:32
↓ 1 callersFunctioncreate_state_space_tree
Creates a state space tree to iterate through each branch using DFS. We know that each state has exactly len(sequence) - index children.
backtracking/all_permutations.py:16
↓ 1 callersFunctioncreate_state_space_tree
Creates a state space tree to iterate through each branch using DFS. We know that each state has exactly two children. It terminates when
backtracking/all_subsequences.py:18
↓ 1 callersFunctioncrossover
Slice and combine two strings at a random point. >>> random.seed(42) >>> crossover("123456", "abcdef") ('12345f', 'abcde6')
genetic_algorithm/basic_string.py:35
↓ 1 callersFunctioncurrent_weather
>>> current_weather("location") Traceback (most recent call last): ... ValueError: No API keys provided or no valid data returned
web_programming/current_weather.py:19
↓ 1 callersFunctioncyclic_sort
Sorts the input list of n integers from 1 to n in-place using the Cyclic Sort algorithm. :param nums: List of n integers from 1 to n to
sorts/cyclic_sort.py:15
↓ 1 callersFunctiondata_handling
>>> data_handling(( ... {'data':'[ 8.3252 41. 6.9841269 1.02380952 322. 2.55555556 37.88 -122.23 ]' ... ,'target':([4.526])})) (
machine_learning/xgboost_regressor.py:9
↓ 1 callersFunctiondata_handling
>>> data_handling(({'data':'[5.1, 3.5, 1.4, 0.2]','target':([0])})) ('[5.1, 3.5, 1.4, 0.2]', [0]) >>> data_handling( ... {'data':
machine_learning/xgboost_classifier.py:10
↓ 1 callersFunctiondata_safety_checker
Used to review all the votes (list result prediction) and compare it to the actual result. input : list of predictions output : print
machine_learning/forecasting/run.py:98
↓ 1 callersFunctiondecimal_to_binary
>>> decimal_to_binary(3,[1.5]) ['0.00.01.5']
boolean_algebra/quine_mc_cluskey.py:52
↓ 1 callersFunctiondecimal_to_binary_recursive
Take an integer value and raise ValueError for wrong inputs, call the function above and return the output with prefix "0b" & "-0b" for p
conversions/decimal_to_binary.py:74
↓ 1 callersFunctiondecimal_to_binary_recursive_helper
Take a positive integer value and return its binary equivalent. >>> decimal_to_binary_recursive_helper(1000) '1111101000' >>> decimal
conversions/decimal_to_binary.py:55
↓ 1 callersFunctiondecode
Decode the input string using the provided key. >>> decode("BMZFAZRZDH", "HAZARD") 'FIREHAZARD' >>> decode("HNBWBPQT", "AUTOMOBILE")
ciphers/playfair_cipher.py:121
↓ 1 callersFunctiondecode
>>> decode([13, 25, 14, 1, 13, 5]) 'myname'
ciphers/a1z26.py:20
↓ 1 callersMethoddecompress
Convert the list of tokens into an output string. Args: tokens: list containing triplets (offset, length, char)
data_compression/lz77.py:111
↓ 1 callersMethoddecompress
Decompress a single integer. Args: num: The compressed integer to decompress. Returns: The original value.
data_compression/coordinate_compression.py:101
↓ 1 callersFunctiondecompress_data
Decompresses given data_bits using Lempel-Ziv-Welch compression algorithm and returns the result as a string
data_compression/lempel_ziv_decompress.py:27
↓ 1 callersMethoddecrease_key
(self, node, new_value)
data_structures/heap/min_heap.py:126
↓ 1 callersFunctiondecrypt
>>> decrypt('marvin', 'QRACRWU') 'JESSICA'
ciphers/porta_cipher.py:55
↓ 1 callersFunctiondecrypt
Decrypt an encrypted message using a permutation cipher with block rearrangement. Args: encrypted_message (str): The encrypted messa
ciphers/permutation_cipher.py:94
↓ 1 callersFunctiondecrypt
>>> decrypt('... --- ... -.-.--') 'SOS!'
ciphers/morse_code.py:35
↓ 1 callersFunctiondecrypt
Generates a template based on the key and fills it in with the characters of the input string and then reading it in a zigzag formatio
ciphers/rail_fence_cipher.py:41
↓ 1 callersFunctiondecrypt
>>> decrypt('TMDETUX PMDVU') Decryption using Key #0: TMDETUX PMDVU Decryption using Key #1: SLCDSTW OLCUT Decryption using Key #2: R
ciphers/brute_force_caesar_cipher.py:4
↓ 1 callersMethoddecrypt
Function to decrypt text using pseudo-random numbers. >>> Onepad().decrypt([], []) '' >>> Onepad().decrypt([35], [])
ciphers/onepad_cipher.py:39
↓ 1 callersMethoddecrypt
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.decrypt('WHXYJOLM9C6XT085LL') 'TESTINGHILLCIPHERR'
ciphers/hill_cipher.py:168
↓ 1 callersMethoddecrypt
Performs shifting of the encoded_message w.r.t. the shuffled __key_list to create the decoded_message >>> ssc = ShuffledShif
ciphers/shuffled_shift_cipher.py:127
↓ 1 callersFunctiondecrypt_fractionated_morse
Decrypt a ciphertext message encrypted with Fractionated Morse Cipher. Args: ciphertext: The ciphertext message to decrypt. key:
ciphers/fractionated_morse_cipher.py:129
↓ 1 callersFunctiondecrypt_message
>>> decrypt_message('LFWOAYUISVKMNXPBDCRJTQEGHZ', 'Ilcrism Olcvs') 'Harshil Darji'
ciphers/simple_substitution_cipher.py:42
↓ 1 callersFunctiondecrypt_message
decrypt_message =============== Decrypts a trifid_cipher encrypted message. PARAMETERS ---------- * `message`:
ciphers/trifid_cipher.py:169
↓ 1 callersFunctiondecrypt_message
>>> decrypt_message('HDarji', 'Akij ra Odrjqqs Gaisq muod Mphumrs.') 'This is Harshil Darji from Dharmaj.'
ciphers/vigenere_cipher.py:28
↓ 1 callersFunctiondecrypt_message
>>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF' ... '{xIp~{HL}Gi') 'The affine
ciphers/affine_cipher.py:56
↓ 1 callersFunctiondecrypt_message
( encrypted_blocks: list[int], message_length: int, key: tuple[int, int], block_size: int = DE
ciphers/rsa_cipher.py:50
↓ 1 callersFunctiondecrypt_message
>>> decrypt_message(6, 'Hlia rDsahrij') 'Harshil Darji'
ciphers/transposition_cipher.py:39
↓ 1 callersFunctiondecrypt_message
>>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Itssg Vgksr'
ciphers/mono_alphabetic_ciphers.py:39
↓ 1 callersMethoddecrypt_string
input: 'content' of type string and 'key' of type int output: decrypted string 'content' if key not passed the method uses th
ciphers/xor_cipher.py:144
↓ 1 callersFunctiondefault_matrix_multiplication
Multiplication only for 2x2 matrices
divide_and_conquer/strassen_matrix_multiplication.py:6
↓ 1 callersFunctiondel_node
(root: MyNode, data: Any)
data_structures/binary_tree/avl_tree.py:198
↓ 1 callersMethoddel_node
(self, data: Any)
data_structures/binary_tree/avl_tree.py:289
↓ 1 callersMethoddelete_item
Deletes given item from heap if present
data_structures/heap/heap_generic.py:90
↓ 1 callersMethoddelete_minimum
(self, heap, positions)
graphs/minimum_spanning_tree_prims.py:68
↓ 1 callersFunctiondepth_first_search
(u, visited, graph)
graphs/g_topological_sort.py:29
↓ 1 callersFunctiondepth_first_search
Depth First Search on Graph :param graph: directed graph in dictionary format :param start: starting vertex as a string :returns: the trac
graphs/depth_first_search.py:6
↓ 1 callersFunctiondepth_first_search
Recur for all neighbours. If any neighbour is visited and in rec_stk then graph is cyclic. >>> graph = {0:[], 1:[0, 3], 2:[0, 4], 3:[5],
graphs/check_cycle.py:24
↓ 1 callersFunctiondepth_first_search
Perform Depth-First Search (DFS) on the graph starting from a node. Args: node: The current node being visited.
graphs/check_bipatrite.py:56
↓ 1 callersFunctiondepth_first_search
>>> boards = [] >>> depth_first_search([], [], [], boards, 4) >>> for board in boards: ... print(board) ['. Q . . ', '. . . Q
backtracking/n_queens_math.py:82
↓ 1 callersFunctiondepth_first_search
Returns the current area of the island >>> depth_first_search(0, 0, set(), matrix) 0
matrix/max_area_of_island.py:33
↓ 1 callersMethoddepth_first_search
(self, node: Node | None, path_sum: int)
data_structures/binary_tree/binary_tree_path_sum.py:80
↓ 1 callersMethoddepth_first_search
(self, node: Node | None)
data_structures/binary_tree/binary_tree_node_sum.py:61
↓ 1 callersMethodderivative
Compute the derivative of given operation/function Args: param: variable to be differentiated operation: fun
machine_learning/automatic_differentiation.py:281
↓ 1 callersMethoddetect
Returns the image with corners identified img_path : path of the image output : list of the corner positions, image
computer_vision/harris_corner.py:26
↓ 1 callersMethoddetect_cycle
Detects if there is a cycle in the linked list using Floyd's cycle detection algorithm. Returns: bool: True if t
data_structures/linked_list/floyds_cycle_detection.py:89
↓ 1 callersFunctiondetect_high_low_threshold
High-Low threshold detection. If an edge pixel's gradient value is higher than the high threshold value, it is marked as a strong edge pixel.
digital_image_processing/edge_detection/canny.py:73
↓ 1 callersFunctiondfs
(root, at, parent, out_edge_count)
graphs/articulation_points.py:9
↓ 1 callersFunctiondfs
(u, graph, visited_edge, path=None)
graphs/eulerian_path_and_circuit_for_undirected_graph.py:9
↓ 1 callersFunctiondfs
(u)
graphs/scc_kosaraju.py:4
↓ 1 callersFunctiondfs
(at, parent, bridges, id_)
graphs/finding_bridges.py:80
↓ 1 callersFunctiondfs
Use depth first search to find all vertices being in the same component as initial vertex >>> dfs(test_graph_1, 0, 5 * [False]) [0, 1
graphs/connected_components.py:13
↓ 1 callersFunctiondfs
DFS traversal
graphs/even_tree.py:20
↓ 1 callersFunctiondfs
(row_n: int, column_n: int)
matrix/matrix_based_game.py:146
↓ 1 callersMethoddfs
(self, s=-2, d=-1)
graphs/directed_and_undirected_weighted_graph.py:36
↓ 1 callersMethoddfs
(self, s=-2, d=-1)
graphs/directed_and_undirected_weighted_graph.py:302
↓ 1 callersMethoddfs
Perform depth-first search (DFS) traversal on the graph and print the visited vertices. Example: >>> g = Graph()
graphs/depth_first_search_2.py:57
↓ 1 callersFunctiondfs2
(u)
graphs/scc_kosaraju.py:14
↓ 1 callersMethoddfs_recursive
Perform a recursive depth-first search (DFS) traversal on the graph. :param start_vertex: The starting vertex for the traversal.
graphs/depth_first_search_2.py:81
← previousnext →1,001–1,100 of 3,909, ranked by callers