MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionsurface_area_cuboid
Calculate the Surface Area of a Cuboid. >>> surface_area_cuboid(1, 2, 3) 22 >>> surface_area_cuboid(0, 0, 0) 0 >>> su
maths/area.py:31
↓ 1 callersFunctionsurface_area_cylinder
Calculate the Surface Area of a Cylinder. Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder Formula: 2 * pi * r * (h + r)
maths/area.py:173
↓ 1 callersFunctionsurface_area_hemisphere
Calculate the Surface Area of a Hemisphere. Formula: 3 * pi * r^2 >>> surface_area_hemisphere(5) 235.61944901923448 >>> su
maths/area.py:83
↓ 1 callersFunctionsurface_area_sphere
Calculate the Surface Area of a Sphere. Wikipedia reference: https://en.wikipedia.org/wiki/Sphere Formula: 4 * pi * r^2 >>> sur
maths/area.py:59
↓ 1 callersFunctionsurface_area_torus
Calculate the Area of a Torus. Wikipedia reference: https://en.wikipedia.org/wiki/Torus :return 4pi^2 * torus_radius * tube_radius >>>
maths/area.py:205
↓ 1 callersFunctionswap
Return a tuple (b, a) when given two integers a and b >>> swap(2,3) (3, 2) >>> swap(3,4) (4, 3) >>> swap(67, 12) (12, 67)
data_structures/binary_tree/lowest_common_ancestor.py:9
↓ 1 callersMethodswap_nodes
Swap the positions of two nodes in the Linked List based on their data values. Args: node_data_1: Data value of the
data_structures/linked_list/swap_nodes.py:67
↓ 1 callersFunctionswap_odd_even_bits
1. We use bitwise AND operations to separate the even bits (0, 2, 4, 6, etc.) and odd bits (1, 3, 5, 7, etc.) in the input number. 2.
bit_manipulation/swap_all_odd_and_even_bits.py:10
↓ 1 callersFunctionsylvester
:param number: nth number to calculate in the sequence :return: the nth number in Sylvester's sequence >>> sylvester(8) 113423713055
maths/sylvester_sequence.py:11
↓ 1 callersFunctiontabu_search
Pure implementation of Tabu search algorithm for a Travelling Salesman Problem in Python. :param first_solution: The solution for the fi
searches/tabu_search.py:188
↓ 1 callersFunctiontarjan
Tarjan's algo for finding strongly connected components in a directed graph Uses two main attributes of each node to track reachability, the
graphs/tarjans_scc.py:4
↓ 1 callersFunctionten_pence
(x: int)
project_euler/problem_031/sol1.py:28
↓ 1 callersFunctiontest
A set of unit tests.
data_structures/arrays/sudoku_solver.py:44
↓ 1 callersFunctiontest2
()
matrix/sherman_morrison.py:262
↓ 1 callersFunctiontest_abs_val
>>> test_abs_val()
maths/abs.py:74
↓ 1 callersFunctiontest_cancer_data
()
machine_learning/sequential_minimum_optimization.py:450
↓ 1 callersFunctiontest_conjugate_gradient
>>> test_conjugate_gradient() # self running tests
linear_algebra/src/conjugate_gradient.py:154
↓ 1 callersFunctiontest_delete_doesnt_leave_dead_nodes
()
data_structures/linked_list/skip_list.py:373
↓ 1 callersFunctiontest_delete_removes_only_given_key
()
data_structures/linked_list/skip_list.py:340
↓ 1 callersFunctiontest_deleted_items_are_not_founded_by_find_method
()
data_structures/linked_list/skip_list.py:325
↓ 1 callersFunctiontest_deleting_item_from_empty_list_do_nothing
()
data_structures/linked_list/skip_list.py:318
↓ 1 callersFunctiontest_demonstration
()
machine_learning/sequential_minimum_optimization.py:505
↓ 1 callersFunctiontest_disjoint_set
>>> test_disjoint_set()
data_structures/disjoint_set/disjoint_set.py:63
↓ 1 callersFunctiontest_gradient_descent
()
machine_learning/gradient_descent.py:130
↓ 1 callersFunctiontest_insert
()
data_structures/linked_list/skip_list.py:249
↓ 1 callersFunctiontest_insert_overrides_existing_value
()
data_structures/linked_list/skip_list.py:269
↓ 1 callersFunctiontest_insertion_speed
Test that the tree balances inserts to O(log(n)) by doing a lot of them.
data_structures/binary_tree/red_black_tree.py:560
↓ 1 callersFunctiontest_iter_always_yields_sorted_values
()
data_structures/linked_list/skip_list.py:391
↓ 1 callersFunctiontest_miller_rabin
Testing a nontrivial (ends in 1, 3, 7, 9) composite and a prime in each range.
ciphers/deterministic_miller_rabin.py:90
↓ 1 callersFunctiontest_power_iteration
>>> test_power_iteration() # self running tests
linear_algebra/src/power_iteration.py:84
↓ 1 callersFunctiontest_rabin_karp
>>> test_rabin_karp() Success.
strings/rabin_karp.py:54
↓ 1 callersFunctiontest_running_key_encrypt
>>> key = "How does the duck know that? said Victor" >>> ciphertext = running_key_encrypt(key, "DEFEND THIS") >>> running_key_decrypt(key
ciphers/running_key_cipher.py:52
↓ 1 callersFunctiontest_search
()
data_structures/linked_list/skip_list.py:302
↓ 1 callersFunctiontest_searching_empty_list_returns_none
()
data_structures/linked_list/skip_list.py:297
↓ 1 callersFunctiontest_stack
>>> test_stack()
data_structures/stacks/stack.py:161
↓ 1 callersFunctiontest_trie
()
data_structures/trie/radix_tree.py:194
↓ 1 callersFunctiontests
()
linear_algebra/src/rayleigh_quotient.py:54
↓ 1 callersFunctiontim_sort
>>> tim_sort("Python") ['P', 'h', 'n', 'o', 't', 'y'] >>> tim_sort((1.1, 1, 0, -1, -1.1)) [-1.1, -1, 0, 1, 1.1] >>> tim_sort(list
sorts/tim_sort.py:43
↓ 1 callersFunctiontime_max_subarray
(input_size: int)
divide_and_conquer/max_subarray.py:87
↓ 1 callersFunctiontime_solve
(grid)
data_structures/arrays/sudoku_solver.py:176
↓ 1 callersFunctionto_grayscale
Helper function to create pixel's greyscale representation Src: https://pl.wikipedia.org/wiki/YUV
digital_image_processing/sepia.py:15
↓ 1 callersFunctionto_title_case
Converts a string to capitalized case, preserving the input as is >>> to_title_case("Aakash") 'Aakash' >>> to_title_case("aak
strings/title.py:1
↓ 1 callersMethodtop
Return the smallest value from the heap. >>> sh = SkewHeap() >>> sh.insert(3) >>> sh.top() 3 >>> sh.
data_structures/heap/skew_heap.py:198
↓ 1 callersMethodtop
Return the smallest value from the heap. >>> rh = RandomizedHeap() >>> rh.insert(3) >>> rh.top() 3 >
data_structures/heap/randomized_heap.py:153
↓ 1 callersMethodtop
return the top element of the stack
data_structures/stacks/stack_with_doubly_linked_list.py:70
↓ 1 callersFunctiontop_down_cut_rod
Constructs a top-down dynamic programming solution for the rod-cutting problem via memoization. This function serves as a wrapper for ``_
dynamic_programming/rod_cutting.py:56
↓ 1 callersFunctiontopological_sort
Perform topological sort on a directed acyclic graph.
sorts/topological_sort.py:18
↓ 1 callersFunctiontopological_sort
(graph, visited)
graphs/g_topological_sort.py:38
↓ 1 callersFunctiontopology_sort
Use depth first search to sort graph At this time graph is the same as input >>> topology_sort(test_graph_1, 0, 5 * [False]) [1, 2, 4
graphs/strongly_connected_components.py:13
↓ 1 callersFunctiontraceback
r""" Perform traceback to find the optimal local alignment. Starts from the highest scoring cell in the matrix and traces back recursively
dynamic_programming/smith_waterman.py:129
↓ 1 callersFunctiontrack_edge
Edge tracking. Usually a weak edge pixel caused from true edges will be connected to a strong edge pixel while noise responses are unconnecte
digital_image_processing/edge_detection/canny.py:94
↓ 1 callersMethodtrain
train: @param x: a one-dimensional numpy array @param y: a one-dimensional numpy array. The contents of y are the lab
machine_learning/decision_tree.py:45
↓ 1 callersMethodtrain
Performs the feedforwarding and back propagation process for the given number of iterations. Every iteration will update the
neural_network/two_hidden_layers_neural_network.py:157
↓ 1 callersMethodtrain
(self, xdata, ydata, train_round, accuracy)
neural_network/back_propagation_neural_network.py:126
↓ 1 callersFunctiontransform
Calculate a Lorentz transformation for movement in the x direction given a velocity and a four-vector for an inertial reference frame If
physics/lorentz_transformation_four_vector.py:137
↓ 1 callersFunctiontransformation_matrix
Calculate the Lorentz transformation matrix for movement in the x direction: | y -γβ 0 0| |-γβ y 0 0| | 0 0 1 0| | 0
physics/lorentz_transformation_four_vector.py:89
↓ 1 callersMethodtransition
(self, node: str)
graphs/markov_chain.py:30
↓ 1 callersFunctiontranspose
>>> transpose([[1,2],[3,4]]) # doctest: +ELLIPSIS <map object at ... >>> transpose([[1,2],[3,4]], return_map=False) [[1, 3], [2, 4]]
matrix/matrix_operation.py:95
↓ 1 callersFunctiontrapezoidal_area
Treats curve as a collection of linear lines and sums the area of the trapezium shape they form :param fnc: a function which defines a cu
maths/area_under_curve.py:10
↓ 1 callersFunctiontrapezoidal_area
Treats curve as a collection of linear lines and sums the area of the trapezium shape they form :param fnc: a function which defines a cu
maths/numerical_analysis/numerical_integration.py:10
↓ 1 callersFunctiontrapezoidal_rule
Implements the extended trapezoidal rule for numerical integration. The function f(x) is provided below. :param boundary: List containin
maths/trapezoidal_rule.py:6
↓ 1 callersFunctiontraverse_keys
(node)
data_structures/linked_list/skip_list.py:383
↓ 1 callersFunctiontraverse_tree
Recursively traverse the Huffman Tree to set each Letter's bitstring dictionary, and return the list of Letters
data_compression/huffman.py:54
↓ 1 callersFunctiontree_sort
>>> tree_sort([]) () >>> tree_sort((1,)) (1,) >>> tree_sort((1, 2)) (1, 2) >>> tree_sort([5, 2, 7]) (2, 5, 7) >>>
sorts/tree_sort.py:42
↓ 1 callersFunctiontriangle
Recursively draw the Sierpinski triangle given the vertices of the triangle and the recursion depth
fractals/sierpinski_triangle.py:48
↓ 1 callersFunctiontriangle_number_generator
()
project_euler/problem_012/sol2.py:26
↓ 1 callersFunctiontruth_table
>>> print(truth_table(nor_gate)) Truth Table of NOR Gate: | Input 1 | Input 2 | Output | | 0 | 0 | 1 | |
boolean_algebra/nor_gate.py:37
↓ 1 callersFunctiontry_key
Given an encrypted message and a possible 3-character key, decrypt the message. If the decrypted message contains a invalid character, i.e. n
project_euler/problem_059/sol1.py:44
↓ 1 callersFunctiontwenty_pence
(x: int)
project_euler/problem_031/sol1.py:32
↓ 1 callersFunctiontwo_pence
(x: int)
project_euler/problem_031/sol1.py:20
↓ 1 callersFunctiontwo_pointer
>>> two_pointer([2, 7, 11, 15], 9) [0, 1] >>> two_pointer([2, 7, 11, 15], 17) [0, 3] >>> two_pointer([2, 7, 11, 15], 18) [1,
maths/two_pointer.py:24
↓ 1 callersFunctiontwo_pound
(x: int)
project_euler/problem_031/sol1.py:44
↓ 1 callersFunctiontwo_sum
>>> two_sum([2, 7, 11, 15], 9) [0, 1] >>> two_sum([15, 2, 11, 7], 13) [1, 2] >>> two_sum([2, 7, 11, 15], 17) [0, 3] >>> t
maths/two_sum.py:18
↓ 1 callersFunctionucal
>>> ucal(1, 2) 0 >>> ucal(1.1, 2) 0.11000000000000011 >>> ucal(1.2, 2) 0.23999999999999994
maths/numerical_analysis/newton_forward_interpolation.py:8
↓ 1 callersFunctionugly_numbers
Returns the nth ugly number. >>> ugly_numbers(100) 1536 >>> ugly_numbers(0) 1 >>> ugly_numbers(20) 36 >>> ugly_number
maths/special_numbers/ugly_numbers.py:12
↓ 1 callersMethodunion
(self, data1: T, data2: T)
graphs/minimum_spanning_tree_kruskal2.py:44
↓ 1 callersMethodunion
(self, item1, item2)
graphs/minimum_spanning_tree_boruvka.py:128
↓ 1 callersMethodunion
Calculate the union of this fuzzy set with another fuzzy set. Args: other (FuzzySet): Another fuzzy set to union with.
fuzzy_logic/fuzzy_operations.py:141
↓ 1 callersFunctionunique_prime_factors
Find unique prime factors of an integer. Tests include sorting because only the set matters, not the order in which it is produced. >
project_euler/problem_047/sol1.py:24
↓ 1 callersFunctionunit_basis_vector
returns a unit basis vector with a One at index 'pos' (indexing at 0)
linear_algebra/src/lib.py:205
↓ 1 callersFunctionunitsolved
(unit)
data_structures/arrays/sudoku_solver.py:201
↓ 1 callersMethodunshift
(self, index)
sorts/external_sort.py:82
↓ 1 callersFunctionupdate
Update the speed of the cars >>> update([-1, -1, -1, -1, -1, 2, -1, -1, -1, -1, 3], 0.0, 5) [-1, -1, -1, -1, -1, 3, -1, -1, -1, -1, 4]
cellular_automata/nagel_schrekenberg.py:81
↓ 1 callersMethodupdate
Update an element in log(N) time :param i: position to be update :param val: new value >>> import operator >>
data_structures/binary_tree/segment_tree_other.py:136
↓ 1 callersFunctionupdate_area_of_max_square
(row: int, col: int)
matrix/largest_square_area_in_matrix.py:61
↓ 1 callersFunctionupdate_area_of_max_square_using_dp_array
( row: int, col: int, dp_array: list[list[int]] )
matrix/largest_square_area_in_matrix.py:97
↓ 1 callersFunctionupdate_image_and_anno
- all_img_list <type: list>: list of all images - all_annos <type: list>: list of all annotations of specific image - idxs <type: list>:
computer_vision/mosaic_augmentation.py:87
↓ 1 callersFunctionupdate_image_and_anno
- img_list <type: list>: list of all images - anno_list <type: list>: list of all annotations of specific image - flip_type <type: int>:
computer_vision/flip_augmentation.py:78
↓ 1 callersMethodupdate_position
Euler algorithm for position >>> body_1 = Body(0.,0.,1.,0.) >>> body_1.update_position(1.) >>> body_1.position
physics/n_body_simulation.py:86
↓ 1 callersMethodupdate_recursive
update(1, 1, N, a, b, v) for update val v to [a,b]
data_structures/binary_tree/segment_tree.py:59
↓ 1 callersFunctionupdate_step
Updates the body-system and applies the change to the patch-list used for plotting >>> body_system_1 = BodySystem([Body(0,0,0,0), Body(10
physics/n_body_simulation.py:185
↓ 1 callersMethodupdate_system
For each body, loop through all other bodies to calculate the total force they exert on it. Use that force to update the body's vel
physics/n_body_simulation.py:136
↓ 1 callersFunctionupdate_tree
Update the FP-Tree with a transaction. Args: items: List of items in the transaction. in_tree: The current node in the FP-Tr
machine_learning/frequent_pattern_growth.py:128
↓ 1 callersMethodupdate_velocity
Euler algorithm for velocity >>> body_1 = Body(0.,0.,0.,0.) >>> body_1.update_velocity(1.,0.,1.) >>> body_1.vel
physics/n_body_simulation.py:59
↓ 1 callersFunctionupf_len
Memoize upf() length results for a given value. >>> upf_len(14) 2
project_euler/problem_047/sol1.py:50
↓ 1 callersFunctionupper_bound
Returns the index of the first element strictly greater than the item. :param sorted_collection: The sorted list to search.
searches/binary_search.py:293
↓ 1 callersFunctionutil_color
Pseudo-Code Base Case: 1. Check if coloring is complete 1.1 If complete return True (meaning that we successfully colored the gr
backtracking/coloring.py:36
↓ 1 callersFunctionutil_hamilton_cycle
Pseudo-Code Base Case: 1. Check if we visited all of vertices 1.1 If last visited vertex has path to starting vertex return True
backtracking/hamiltonian_cycle.py:49
↓ 1 callersFunctionvalid_coloring
For each neighbour check if the coloring constraint is satisfied If any of the neighbours fail the constraint return False If all neighbo
backtracking/coloring.py:10
↓ 1 callersFunctionvalid_connection
Checks whether it is possible to add next into path by validating 2 statements 1. There should be path between current and next vertex 2.
backtracking/hamiltonian_cycle.py:11
← previousnext →2,201–2,300 of 3,909, ranked by callers