MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 3 callersFunctionheight
Recursive function for calculating the height of the binary tree. >>> height(None) 0 >>> height(make_tree()) 3
data_structures/binary_tree/binary_tree_traversals.py:85
↓ 3 callersFunctionhill_climbing
Implementation of the hill climbling algorithm. We start with a given state, find all its neighbors, move towards the neighbor which prov
searches/hill_climbing.py:86
↓ 3 callersFunctionhypercube_points
Generates random points uniformly distributed within an n-dimensional hypercube. Args: num_points: Number of points to generate.
data_structures/kd_tree/example/hypercube_points.py:12
↓ 3 callersMethodidentity
(self)
matrix/matrix_class.py:150
↓ 3 callersFunctionin_static_equilibrium
Check if a system is in equilibrium. It takes two numpy.array objects. forces ==> [ [force1_x, force1_y],
physics/in_static_equilibrium.py:34
↓ 3 callersMethodinorder_traversal
Return the inorder traversal of the tree >>> t = BinarySearchTree() >>> [i.label for i in t.inorder_traversal()] []
data_structures/binary_tree/binary_search_tree_recursive.py:234
↓ 3 callersMethodinorder_traverse
(self)
data_structures/binary_tree/red_black_tree.py:473
↓ 3 callersMethodinsert
insert a new value into the max heap >>> h = Heap() >>> h.insert(10) >>> h [10] >>> h = Heap()
data_structures/heap/heap.py:196
↓ 3 callersMethodinsert_at_nth
>>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_nth(-1, 666) Traceback (most recent call last): ..
data_structures/linked_list/doubly_linked_list.py:62
↓ 3 callersMethodinsert_nth
Insert data at given index. >>> linked_list = LinkedList() >>> linked_list.insert_tail("first") >>> linked_list.inser
data_structures/linked_list/singly_linked_list.py:192
↓ 3 callersMethodintersection
Calculate the intersection of this fuzzy set with another fuzzy set. Args: other: Another fuzzy set to intersect
fuzzy_logic/fuzzy_operations.py:93
↓ 3 callersMethodis_empty
Check if the Circular Linked List is empty. Returns: bool: True if the list is empty, False otherwise.
data_structures/linked_list/circular_linked_list.py:142
↓ 3 callersMethodis_empty
Checks if the tree is empty >>> t = BinarySearchTree() >>> t.is_empty() True >>> t.put(8) >>> t.is_e
data_structures/binary_tree/binary_search_tree_recursive.py:42
↓ 3 callersMethodis_empty
>>> stack = LinkedStack() >>> stack.is_empty() True >>> stack.push(1) >>> stack.is_empty() Fals
data_structures/stacks/stack_with_singly_linked_list.py:83
↓ 3 callersFunctionis_monotonic
Check if a list is monotonic. >>> is_monotonic([1, 2, 2, 3]) True >>> is_monotonic([6, 5, 4, 4]) True >>> is_monotonic([1, 3
data_structures/arrays/monotonic_array.py:2
↓ 3 callersFunctionis_prime
Checks to see if a number is a prime in O(sqrt(n)). A number is prime if it has exactly two factors: 1 and itself. >>> is_prime(0)
project_euler/problem_037/sol1.py:20
↓ 3 callersFunctionis_sorted
(lst)
data_structures/linked_list/skip_list.py:392
↓ 3 callersMethodleft
Returns the index of left child Examples: >>> priority_queue_test = PriorityQueue() >>> priority_queue_test.left(0)
graphs/dijkstra_algorithm.py:130
↓ 3 callersFunctionmake_matrix
>>> make_matrix() [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] >>> make_matrix(1) [[1]] >>> make_matrix(-2)
matrix/rotate_matrix.py:11
↓ 3 callersMethodmatch
Compute the common substring of the prefix of the node and a word Args: word (str): word to compare Returns:
data_structures/trie/radix_tree.py:18
↓ 3 callersMethodmean_squared_error
mean_squared_error: @param labels: a one-dimensional numpy array @param prediction: a floating point value return val
machine_learning/decision_tree.py:19
↓ 3 callersFunctionmerge
We merge 2 trees into one. Note: all left tree's values must be less than all right tree's
data_structures/binary_tree/treap.py:61
↓ 3 callersFunctionminor
>>> minor([[1, 2], [3, 4]], 1, 1) [[1]]
matrix/matrix_operation.py:116
↓ 3 callersMethodndvi
Normalized Difference self.nir/self.red Normalized Difference Vegetation Index, Calibrated NDVI - CDVI https://www.indexdatab
digital_image_processing/index_calculation.py:217
↓ 3 callersFunctionnearest_neighbour_search
Performs a nearest neighbor search in a KD-Tree for a given query point. Args: root (KDNode | None): The root node of the KD-Tree.
data_structures/kd_tree/nearest_neighbour_search.py:12
↓ 3 callersMethodnext_
(index: int)
data_structures/binary_tree/fenwick_tree.py:73
↓ 3 callersFunctionnormalize
Helper function to normalize R/G/B value -> return 255 if value > 255
digital_image_processing/sepia.py:22
↓ 3 callersMethodpar
Returns the index of parent Examples: >>> priority_queue_test = PriorityQueue() >>> priority_queue_test.par(1)
graphs/dijkstra_algorithm.py:156
↓ 3 callersFunctionplot
Utility function to plot how the given body-system evolves over time. No doctest provided since this function does not have a return value.
physics/n_body_simulation.py:213
↓ 3 callersMethodplot_curve
Plots the Bezier curve using matplotlib plotting capabilities. step_size: defines the step(s) at which to evaluate the Bezier cur
graphics/bezier_curve.py:75
↓ 3 callersMethodpooling
(self, featuremaps, size_pooling, pooling_type="average_pool")
neural_network/convolution_neural_network.py:145
↓ 3 callersMethodpreorder_traversal
Return the preorder traversal of the tree >>> t = BinarySearchTree() >>> [i.label for i in t.preorder_traversal()] [
data_structures/binary_tree/binary_search_tree_recursive.py:256
↓ 3 callersFunctionprint_preorder
Print pre-order traversal of the tree. >>> root = Node(1) >>> root.left = Node(2) >>> root.right = Node(3) >>> print_preorder(ro
data_structures/binary_tree/merge_two_binary_trees.py:56
↓ 3 callersMethodquery
Get range query value in log(N) time :param left: left element index :param right: right element index :return: eleme
data_structures/binary_tree/non_recursive_segment_tree.py:90
↓ 3 callersMethodquery_range
Get range query value in log(N) time :param i: left element index :param j: right element index :return: element comb
data_structures/binary_tree/segment_tree_other.py:149
↓ 3 callersFunctionquick_select
>>> quick_select([2, 4, 5, 7, 899, 54, 32], 5) 54 >>> quick_select([2, 4, 5, 7, 899, 54, 32], 1) 4 >>> quick_select([5, 4, 3, 2],
searches/quick_select.py:30
↓ 3 callersFunctionrand_fn
Returns a pseudorandom value modulo ``modulus`` based on the input ``value`` and attempt-specific ``step`` size. >>> rand_fn
maths/pollard_rho.py:58
↓ 3 callersMethodremove
Remove label from this tree.
data_structures/binary_tree/red_black_tree.py:150
↓ 3 callersMethodremove
Removes and returns the given node from the list Returns None if node.prev or node.next is None
other/lfu_cache.py:145
↓ 3 callersMethodretrace_path
Retrace the path from parents to parents until start node
graphs/bidirectional_breadth_first_search.py:98
↓ 3 callersMethodretrace_path
Retrace the path from parents to parents until start node
graphs/bidirectional_a_star.py:158
↓ 3 callersFunctionreverse
Reverses a portion of the list in place from index start to end. Parameters: start (int): Starting index of the portion to r
data_structures/arrays/rotate_array.py:32
↓ 3 callersMethodroll
(self)
maths/monte_carlo_dice.py:13
↓ 3 callersMethodrotate
(self, rotation: int)
data_structures/queues/queue_on_pseudo_stack.py:40
↓ 3 callersFunctionschur_complement
Schur complement of a symmetric matrix X given as a 2x2 block matrix consisting of matrices `A`, `B` and `C`. Matrix `A` must be quadrati
linear_algebra/src/schur_complement.py:7
↓ 3 callersFunctionscore_function
Calculate the score for a character pair based on whether they match or mismatch. Returns 1 if the characters match, -1 if they mismatch, and
dynamic_programming/smith_waterman.py:12
↓ 3 callersMethodsearch
(self)
graphs/bidirectional_a_star.py:103
↓ 3 callersMethodselect
(self, choices)
sorts/external_sort.py:48
↓ 3 callersMethodshortest_path
This shortest path function returns a string, describing the result: 1.) No path is found. The string is a human readable message to
graphs/breadth_first_search_shortest_path.py:49
↓ 3 callersFunctionsigmoid_function
Also known as Logistic Function. 1 f(x) = ------- 1 + e⁻ˣ The sigmoid function approaches a value of 1
machine_learning/logistic_regression.py:31
↓ 3 callersFunctionsplit
We split current tree into 2 trees with value: Left tree contains all values less than split value. Right tree contains all values great
data_structures/binary_tree/treap.py:35
↓ 3 callersFunctionsum_of_divisors
(n: int)
project_euler/problem_021/sol1.py:20
↓ 3 callersMethodswap
Swaps array elements at indices i and j, update the pos{} Examples: >>> priority_queue_test = PriorityQueue() >>> pr
graphs/dijkstra_algorithm.py:171
↓ 3 callersFunctionto_little_endian
Converts the given string to little-endian in groups of 8 chars. Arguments: string_32 {[string]} -- [32-char string] Raises:
hashes/md5.py:18
↓ 3 callersMethodunion
Union finds the roots of components for two nodes, compares the components in terms of size, and attaches the smaller one to the larger one to
graphs/boruvka.py:68
↓ 3 callersMethodupdate
Update an element in log(N) time :param p: position to be update :param v: new value >>> st = SegmentTree([3, 1, 2,
data_structures/binary_tree/non_recursive_segment_tree.py:71
↓ 3 callersFunctionvol_spherical_cap
Calculate the volume of the spherical cap. >>> vol_spherical_cap(1, 2) 5.235987755982988 >>> vol_spherical_cap(1.6, 2.6) 16.6211
maths/volume.py:35
↓ 2 callersMethod__available_resources
Check for available resources in line with each resource in the claim vector
other/bankers_algorithm.py:68
↓ 2 callersMethod__dft
(self, which)
maths/radix2_fft.py:82
↓ 2 callersMethod__init__
(self, radius: float)
geometry/geometry.py:127
↓ 2 callersMethod__init__
(self, graph, sources, sinks)
graphs/edmonds_karp_multiple_source_and_sink.py:2
↓ 2 callersFunction__prepare
A helper function that generates the triagrams and assigns each letter of the alphabet to its corresponding triagram and stores this in a d
ciphers/trifid_cipher.py:62
↓ 2 callersMethod__str__
(self)
project_euler/problem_054/sol1.py:330
↓ 2 callersMethod_add_item
Try to add 3 elements when the size is 5 >>> hm = HashMap(5) >>> hm._add_item(1, 10) >>> hm._add_item(2, 20)
data_structures/hashing/hash_map.py:134
↓ 2 callersMethod_bubble_up
(self, elem: T)
graphs/minimum_spanning_tree_prims2.py:134
↓ 2 callersMethod_check_obey_kkt
(self, index)
machine_learning/sequential_minimum_optimization.py:162
↓ 2 callersMethod_choose_a2
Choose the second alpha using a heuristic algorithm Steps: 1: Choose alpha2 that maximizes the step size (|E1 - E2|).
machine_learning/sequential_minimum_optimization.py:263
↓ 2 callersFunction_construct_hull
Parameters --------- points: list or None, the hull of points from which to choose the next convex-hull point left: Point, t
divide_and_conquer/convex_hull.py:365
↓ 2 callersFunction_cross_product
Calculate the cross product of vectors OA and OB. Returns: > 0: Counter-clockwise turn (left turn) = 0: Collinear <
geometry/jarvis_march.py:44
↓ 2 callersMethod_delete
(self, node)
data_structures/linked_list/deque_doubly.py:49
↓ 2 callersMethod_design_matrix
Constructs a polynomial regression design matrix for the given input data. For input data x = (x₁, x₂, ..., xₙ) and polynomial degree
machine_learning/polynomial_regression.py:55
↓ 2 callersFunction_error
:param data_set: train data or test data :param example_no: example number whose error has to be checked :return: error in example pointe
machine_learning/gradient_descent.py:22
↓ 2 callersMethod_expand
(self, data)
neural_network/convolution_neural_network.py:169
↓ 2 callersFunction_extract_images
Extract the images into a 4D uint8 numpy array [index, y, x, depth]. Args: f: A file object that can be passed into a gzip reader. Ret
neural_network/input_data.py:47
↓ 2 callersFunction_extract_labels
Extract the labels into a 1D uint8 numpy array [index]. Args: f: A file object that can be passed into a gzip reader. one_hot: Does o
neural_network/input_data.py:86
↓ 2 callersFunction_get
(k)
data_structures/hashing/tests/test_hash_map.py:8
↓ 2 callersMethod_get_valid_parent
Returns index of valid parent as per desired ordering among given index and both it's children
data_structures/heap/heap_generic.py:49
↓ 2 callersMethod_heapify_down
Fixes the heap in downward direction of given index
data_structures/heap/heap_generic.py:72
↓ 2 callersFunction_hypothesis_value
Calculates hypothesis function value for a given input :param data_input_tuple: Input tuple of a particular example :return: Value of hyp
machine_learning/gradient_descent.py:33
↓ 2 callersMethod_insert
(self, predecessor, e, successor)
data_structures/linked_list/deque_doubly.py:40
↓ 2 callersMethod_insert_repair
Repair the coloring from inserting into a tree.
data_structures/binary_tree/red_black_tree.py:112
↓ 2 callersMethod_is_flush
(self)
project_euler/problem_054/sol1.py:253
↓ 2 callersFunction_is_matrix_spd
Returns True if input matrix is symmetric positive definite. Returns False otherwise. For a matrix to be SPD, all eigenvalues must be po
linear_algebra/src/conjugate_gradient.py:12
↓ 2 callersFunction_is_point_on_segment
Check if a point lies on the line segment between p1 and p2.
geometry/jarvis_march.py:58
↓ 2 callersMethod_is_same_kind
(self)
project_euler/problem_054/sol1.py:279
↓ 2 callersMethod_norm
(self, data)
machine_learning/sequential_minimum_optimization.py:376
↓ 2 callersMethod_parent
Returns parent index of given index if exists else None
data_structures/heap/heap_generic.py:21
↓ 2 callersMethod_resize
(self, new_size: int)
data_structures/hashing/hash_map.py:114
↓ 2 callersFunction_run_operation
(obj, fun, *args)
data_structures/hashing/tests/test_hash_map.py:20
↓ 2 callersMethod_set_value
_set_value functions allows to update value at a particular hash Examples: 1. _set_value in HashTable of size 5 >>>
data_structures/hashing/hash_table.py:133
↓ 2 callersFunction_shape
(matrix: list[list[int]])
matrix/matrix_operation.py:169
↓ 2 callersMethod_swap
Performs changes required for swapping two elements in the heap
data_structures/heap/heap_generic.py:35
↓ 2 callersFunction_validate_list
>>> _validate_list(["a"], "mock_name") >>> _validate_list("a", "mock_name") Traceback (most recent call last): ... ValueE
dynamic_programming/viterbi.py:264
↓ 2 callersFunction_validate_nested_dict
>>> _validate_nested_dict({"a":{"b": 0.5}}, "mock_name") >>> _validate_nested_dict("invalid", "mock_name") Traceback (most recent call la
dynamic_programming/viterbi.py:315
↓ 2 callersFunctionactual_power
Function using divide and conquer to calculate a^b. It only works for integer a,b. :param a: The base of the power operation, an integer
divide_and_conquer/power.py:1
↓ 2 callersFunctionadd
adds addend to digit array given in digits starting at index k
project_euler/problem_551/sol1.py:148
↓ 2 callersMethodadd_edge
Destination vertex and weight.
graphs/prim.py:42
↓ 2 callersMethodadd_entity
Adds an entity, making sure the entity does not override another entity >>> wt = WaTor(WIDTH, HEIGHT) >>> wt.set_pla
cellular_automata/wa_tor.py:153
↓ 2 callersMethodadd_neighbor
Add a pointer to a vertex at neighbor's list.
graphs/prim.py:38
↓ 2 callersMethodadd_node
(self, node: T)
graphs/minimum_spanning_tree_kruskal2.py:54
← previousnext →301–400 of 3,909, ranked by callers