MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

Functionbinary_xor
Take in 2 integers, convert them to binary, return a binary number that is the result of a binary xor operation on the integers provided.
bit_manipulation/binary_xor_operator.py:4
Methodbiography
(self)
web_programming/instagram_crawler.py:74
Functionbitap_string_match
Retrieves the index of the first occurrence of pattern in text. Args: text: A string consisting only of lowercase alphabetical chara
strings/bitap_string_match.py:17
Methodbitstring
(self)
data_structures/hashing/bloom_filter.py:88
Functionbitwise_addition_recursive
>>> bitwise_addition_recursive(4, 5) 9 >>> bitwise_addition_recursive(8, 9) 17 >>> bitwise_addition_recursive(0, 4) 4 >>>
bit_manipulation/bitwise_addition_recursive.py:7
Methodbndvi
Normalized Difference self.nir/self.blue self.blue-normalized difference vegetation index https://www.indexdatabase.de/db
digital_image_processing/index_calculation.py:226
Methodboruvka
Performs Borůvka's algorithm to find MST.
graphs/boruvka.py:83
Methodboruvka_mst
Implementation of Boruvka's algorithm >>> g = Graph() >>> g = Graph.build([0, 1, 2, 3], [[0, 1, 1], [0, 2, 1],[2, 3, 1]])
graphs/minimum_spanning_tree_boruvka.py:150
Functionbreadth_first_search
Implementation of breadth first search using queue.Queue. >>> ''.join(breadth_first_search(G, 'A')) 'ABCDEF'
graphs/breadth_first_search_2.py:32
Functionbreadth_first_search_with_deque
Implementation of breadth first search using collection.queue. >>> ''.join(breadth_first_search_with_deque(G, 'A')) 'ABCDEF'
graphs/breadth_first_search_2.py:53
Functionbrightness
Fundamental Transformation/Operation that'll be performed on every bit.
digital_image_processing/change_brightness.py:9
Functionbruteforce
Uses decrypt function by guessing every key >>> bruteforce("HWe olordll")[4] 'Hello World'
ciphers/rail_fence_cipher.py:87
Functionbuild_menu
(name, value, weight)
other/greedy.py:23
Functionbuild_tree
Builds the tree for arr and returns the root of the constructed tree >>> build_tree(test_array) Node(min_value=0 max_value=9)
data_structures/binary_tree/wavelet_tree.py:35
Functionbuiltin_voltage
This function can calculate the Builtin Voltage of a pn junction diode. This is calculated from the given three values. Examples - >>
electronics/builtin_voltage.py:8
Methodbulk_insert
bulk_insert is used for entering more than one element at a time in the HashTable. Examples: 1. >>> ht = Has
data_structures/hashing/hash_table.py:88
Methodbwdrvi
self.blue-wide dynamic range vegetation index https://www.indexdatabase.de/db/i-single.php?id=136 :return: index
digital_image_processing/index_calculation.py:300
Methodcache_decorator_inner
(func: Callable[[T], U])
other/lru_cache.py:307
Methodcache_decorator_inner
(func: Callable[[T], U])
other/lfu_cache.py:290
Methodcache_decorator_wrapper
(*args: T)
other/lru_cache.py:313
Methodcache_decorator_wrapper
(*args: T)
other/lfu_cache.py:296
Methodcache_info
()
other/lru_cache.py:323
Methodcache_info
()
other/lfu_cache.py:306
Functioncalculate_prob
This method takes path and two dict as argument and than calculates entropy of them. :param dict: :param dict: :return: Prints
maths/entropy.py:15
Methodcalculate_remaining_burst_time_of_processes
This method calculate remaining burst time of processes >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >
scheduling/multi_level_feedback_queue.py:111
Functioncalculate_resistance
Function calculates the total resistance of the resistor using the color codes. Function takes number_of_bands, color_code_list as input and
electronics/resistor_color_code.py:295
Methodcalculation
performs the calculation of the index with the values instantiated in the class :str index: abbreviation of index name to perform
digital_image_processing/index_calculation.py:123
Functioncall_func
(*args, **kwargs)
machine_learning/sequential_minimum_optimization.py:438
Functioncamel_to_snake_case
Transforms a camelCase (or PascalCase) string to snake_case >>> camel_to_snake_case("someRandomString") 'some_random_string'
strings/camel_case_to_snake_case.py:1
Functioncan_complete_journey
This function returns the index from which to start the journey in order to reach the end. Args: gas_quantities [list]: Amount o
greedy_methods/gas_station.py:62
Functioncapacitor_parallel
Ceq = C1 + C2 + ... + Cn Calculate the equivalent resistance for any number of capacitors in parallel. >>> capacitor_parallel([5.71389, 1
electronics/capacitor_equivalence.py:6
Functioncapacitor_series
Ceq = 1/ (1/C1 + 1/C2 + ... + 1/Cn) >>> capacitor_series([5.71389, 12, 3]) 1.6901062252507735 >>> capacitor_series([5.71389, 12, -3])
electronics/capacitor_equivalence.py:26
Functioncapitalize
Capitalizes the first letter of a sentence or word. >>> capitalize("hello world") 'Hello world' >>> capitalize("123 hello world")
strings/capitalize.py:1
Functioncapture_area
Input Param: ------------ capture_radius: The radius of orbital capture and impact for a central body of mass M and a projectile movi
physics/basic_orbital_capture.py:66
Functioncapture_radii
Input Params: ------------- target_body_radius: Radius of the central body SI units: meters | m target_body_mass: Mass of the central
physics/basic_orbital_capture.py:20
Functioncarrier_concentration
This function can calculate any one of the three - 1. Electron Concentration 2, Hole Concentration 3. Intrinsic Concentration giv
electronics/carrier_concentration.py:8
Functioncasimir_force
Input Parameters ---------------- force -> Casimir Force : magnitude in Newtons area -> Surface area of each plate : magnitude in sq
physics/casimir_effect.py:49
Functioncatalan
:param number: nth catalan number to calculate :return: the nth catalan number Note: A catalan number is only defined for positive intege
maths/special_numbers/catalan_number.py:11
Functioncategorical_cross_entropy
Calculate categorical cross-entropy (CCE) loss between true class labels and predicted class probabilities. CCE = -Σ(y_true * ln(y_pred)
machine_learning/loss_functions.py:93
Functioncategorical_focal_cross_entropy
Calculate the mean categorical focal cross-entropy (CFCE) loss between true labels and predicted probabilities for multi-class classification
machine_learning/loss_functions.py:151
Methodccci
Canopy Chlorophyll Content Index https://www.indexdatabase.de/db/i-single.php?id=224 :return: index
digital_image_processing/index_calculation.py:189
Functioncelsius_to_fahrenheit
Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
conversions/temperature_conversions.py:4
Functioncelsius_to_kelvin
Convert a given value from Celsius to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
conversions/temperature_conversions.py:32
Functioncelsius_to_rankine
Convert a given value from Celsius to Rankine and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
conversions/temperature_conversions.py:56
Functioncenter_of_mass
Input Parameters ---------------- particles: list(Particle): A list of particles where each particle is a tuple with it's (x, y, z) p
physics/center_of_mass.py:34
Functioncentripetal
The Centripetal Force formula is given as: (m*v*v)/r >>> round(centripetal(15.5,-30,10),2) 1395.0 >>> round(centripetal(10,15,5),2)
physics/centripetal_force.py:24
Methodchange
Changes (sets) the index as number >>> cont = NumberContainer() >>> cont.change(0, 10) >>> cont.change(0, 20)
other/number_container_system.py:125
Functioncharging_capacitor
Find capacitor voltage at any nth second after initiating its charging. Examples -------- >>> charging_capacitor(source_voltage=.2,r
electronics/charging_capacitor.py:21
Functioncharging_inductor
Find inductor current at any nth second after initiating its charging. Examples -------- >>> charging_inductor(source_voltage=5.8,re
electronics/charging_inductor.py:32
Functionchebyshev_distance
This function calculates the Chebyshev distance (also known as the Chessboard distance) between two n-dimensional points represented as lists
maths/chebyshev_distance.py:1
Functioncheck_cycle
Returns True if graph is cyclic else False >>> check_cycle(graph={0:[], 1:[0, 3], 2:[0, 4], 3:[5], 4:[5], 5:[]}) False >>> check_cycl
graphs/check_cycle.py:6
Functioncheck_polygon
Takes list of possible side lengths and determines whether a two-dimensional polygon with such side lengths can exist. Returns a boolean
maths/check_polygon.py:4
Functionchi_squared_statistic_values_sorting_key
(key: int)
ciphers/decrypt_caesar_with_chi_squared.py:234
Functionchinese_remainder_theorem
>>> chinese_remainder_theorem(5,1,7,3) 31 Explanation : 31 is the smallest number such that (i) When we divide it by 5,
maths/chinese_remainder_theorem.py:36
Functionchinese_remainder_theorem2
>>> chinese_remainder_theorem2(5,1,7,3) 31 >>> chinese_remainder_theorem2(6,1,4,3) 14
maths/chinese_remainder_theorem.py:75
Methodci
Coloration Index https://www.indexdatabase.de/db/i-single.php?id=11 :return: index
digital_image_processing/index_calculation.py:324
Methodci_green
Chlorophyll Index self.green https://www.indexdatabase.de/db/i-single.php?id=128 :return: index
digital_image_processing/index_calculation.py:308
Methodci_rededge
Chlorophyll Index self.redEdge https://www.indexdatabase.de/db/i-single.php?id=131 :return: index
digital_image_processing/index_calculation.py:316
Methodcircular_convolution
This function performs the circular convolution of the first and second signal using matrix method Usage: >>> convol
electronics/circular_convolution.py:34
Methodclear
>>> queue = LinkedQueue() >>> for i in range(1, 6): ... queue.put(i) >>> queue.clear() >>> len(queue)
data_structures/queues/linked_queue.py:139
Methodclear
Clear the heap. >>> rh = RandomizedHeap([3, 1, 3, 7]) >>> rh.clear() >>> rh.pop() Traceback (most recent cal
data_structures/heap/randomized_heap.py:175
Methodclear
>>> stack = LinkedStack() >>> stack.push("Java") >>> stack.push("C") >>> stack.push("Python") >>> str(st
data_structures/stacks/stack_with_singly_linked_list.py:147
Functionclear_bit
Set the bit at position to 0. Details: perform bitwise and for given number and X. Where X is a number with all the bits - ones and bit
bit_manipulation/single_bit_manipulation_operations.py:24
Methodclear_graph
Clears all vertices and edges.
graphs/graph_adjacency_matrix.py:191
Methodclear_graph
Clears all vertices and edges.
graphs/graph_adjacency_list.py:183
Functionclimb_stairs
LeetCdoe No.70: Climbing Stairs Distinct ways to climb a number_of_steps staircase where each time you can either climb 1 or 2 steps.
dynamic_programming/climbing_stairs.py:4
Functionclone_graph
This function returns a clone of a connected undirected graph. >>> clone_graph(Node(1)) Node(value=1, neighbors=[]) >>> clone_graph(N
graphs/deep_clone_graph.py:36
Functioncollect_solution_file_paths
()
scripts/validate_solutions.py:82
Functioncolor
Wrapper function to call subroutine called util_color which will either return True or False. If True is returned colored_vertices list i
backtracking/coloring.py:88
Functioncombination_sum_iv_bottom_up
Function checks the all possible combinations with using bottom up approach, and returns the count of possible combination in O(N^2) Time Com
dynamic_programming/combination_sum_iv.py:75
Functioncombination_sum_iv_dp_array
Function checks the all possible combinations, and returns the count of possible combination in O(N^2) Time Complexity as we are using Dynami
dynamic_programming/combination_sum_iv.py:45
Functioncompare_points
Compare two points by polar angle relative to min_point.
geometry/graham_scan.py:176
Functioncompute_bridges
Return the list of undirected graph bridges [(a1, b1), ..., (ak, bk)]; ai <= bi >>> compute_bridges(__get_demo_graph(0)) [(3, 4), (2, 3),
graphs/finding_bridges.py:60
Functionconnect
(graph, a, b, edge)
graphs/prim.py:47
Functionconnected_components
This function takes graph as a parameter and then returns the list of connected components >>> connected_components(test_graph_1) [[0
graphs/connected_components.py:33
Functionconstruct_highway
Build the highway following the parameters given >>> construct_highway(10, 2, 6) [[6, -1, 6, -1, 6, -1, 6, -1, 6, -1]] >>> construct_
cellular_automata/nagel_schrekenberg.py:31
Methodcontains_sum
The function returns True if array contains the target_sum, False otherwise. Runtime : O(n) Space: O(n) >>>
data_structures/arrays/prefix_sum.py:61
Functioncontrast
Fundamental Transformation/Operation that'll be performed on every bit.
digital_image_processing/change_contrast.py:20
Functionconvert_binary_prefix
Wikipedia reference: https://en.wikipedia.org/wiki/Metric_prefix >>> convert_binary_prefix(1, BinaryUnit.giga, BinaryUnit.mega) 1024
conversions/prefix_conversions.py:73
Functionconvert_si_prefix
Wikipedia reference: https://en.wikipedia.org/wiki/Binary_prefix Wikipedia reference: https://en.wikipedia.org/wiki/International_System_of_U
conversions/prefix_conversions.py:44
Functionconvert_speed
Convert speed from one unit to another using the speed_chart above. "km/h": 1.0, "m/s": 3.6, "mph": 1.609344, "knot": 1.852,
conversions/speed_conversions.py:25
Methodconvolution
(self, data)
neural_network/convolution_neural_network.py:339
Functioncosine_similarity
Calculates cosine similarity between two data. :param input_a: ndarray of first vector. :param input_b: ndarray of second vector. :re
machine_learning/similarity_search.py:143
Functioncoulombs_law
Calculate the electrostatic force of attraction or repulsion between two point charges >>> coulombs_law(15.5, 20, 15) 12382849136.06
physics/coulombs_law.py:18
Functioncouloumbs_law
Apply Coulomb's Law on any three given values. These can be force, charge1, charge2, or distance, and then in a Python dict return name/value
electronics/coulombs_law.py:8
Methodcount_islands
(self)
matrix/count_islands_in_matrix.py:29
Functioncount_negatives_binary_search
An O(m logn) solution that uses binary search in order to find the boundary between positive and negative numbers >>> [count_negatives_b
matrix/count_negative_numbers_in_sorted_matrix.py:85
Functioncount_negatives_brute_force
This solution is O(n^2) because it iterates through every column and row. >>> [count_negatives_brute_force(grid) for grid in test_grids]
matrix/count_negative_numbers_in_sorted_matrix.py:102
Functioncount_negatives_brute_force_with_break
Similar to the brute force solution above but uses break in order to reduce the number of iterations. >>> [count_negatives_brute_force_w
matrix/count_negative_numbers_in_sorted_matrix.py:112
Functioncount_time
(func)
machine_learning/sequential_minimum_optimization.py:437
Functioncount_vowels
Count the number of vowels in a given string. :param s: Input string to count vowels in. :return: Number of vowels in the input string.
strings/count_vowels.py:1
Functioncramers_rule_2x2
Solves the system of linear equation in 2 variables. :param: equation1: list of 3 numbers :param: equation2: list of 3 numbers :retur
matrix/cramers_rule_2x2.py:5
Functioncreate_linked_list
>>> new_linked_list = LinkedList() >>> new_linked_list.get_head_data() is None True >>> new_linked_list.get_tail_data() is None T
data_structures/linked_list/doubly_linked_list_two.py:166
Functioncreate_ngram
Create ngrams from a sentence >>> create_ngram("I am a sentence", 2) ['I ', ' a', 'am', 'm ', ' a', 'a ', ' s', 'se', 'en', 'nt', 'te',
strings/ngram.py:6
Methodctvi
Corrected Transformed Vegetation Index https://www.indexdatabase.de/db/i-single.php?id=244 :return: index
digital_image_processing/index_calculation.py:332
Methodcvi
Chlorophyll vegetation index https://www.indexdatabase.de/db/i-single.php?id=391 :return: index
digital_image_processing/index_calculation.py:199
Methodcycle_nodes
(self)
graphs/directed_and_undirected_weighted_graph.py:146
Methodcycle_nodes
(self)
graphs/directed_and_undirected_weighted_graph.py:371
Functiondamerau_levenshtein_distance
Implements the Damerau-Levenshtein distance algorithm that measures the edit distance between two strings. Parameters: first_str
strings/damerau_levenshtein_distance.py:11
Functiondecimal_to_binary_iterative
Convert an Integer Decimal Number to a Binary Number as str. >>> decimal_to_binary_iterative(0) '0b0' >>> decimal_to_binary_iterative
conversions/decimal_to_binary.py:4
← previousnext →2,901–3,000 of 3,909, ranked by callers