MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 2 callersFunctiongood_file_paths
(top_dir: str = ".")
scripts/build_directory_md.py:7
↓ 2 callersFunctiongrid_values
Convert grid into a dict of {square: char} with '0' or '.' for empties.
data_structures/arrays/sudoku_solver.py:77
↓ 2 callersFunctionheapify
:param unsorted: unsorted list containing integers numbers :param index: index :param heap_size: size of the heap :return: None >
sorts/heap_sort.py:6
↓ 2 callersFunctionheapify
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> heapify(array, len(array) // 2, len(array))
sorts/intro_sort.py:39
↓ 2 callersFunctionhexagonal_num
Returns nth hexagonal number >>> hexagonal_num(143) 40755 >>> hexagonal_num(21) 861 >>> hexagonal_num(10) 190
project_euler/problem_045/sol1.py:17
↓ 2 callersFunctionhexagonal_numbers
:param len: max number of elements :type len: int :return: Hexagonal numbers as a list Tests: >>> hexagonal_numbers(10)
maths/series/hexagonal_numbers.py:18
↓ 2 callersFunctionhorizontal_distance
r""" Returns the horizontal distance that the object cover Formula: .. math:: \frac{v_0^2 \cdot \sin(2 \alpha)}{g}
physics/horizontal_projectile_motion.py:48
↓ 2 callersMethodinsert
Insert the value into the heap. >>> sh = SkewHeap() >>> sh.insert(3) >>> sh.insert(1) >>> sh.insert(3)
data_structures/heap/skew_heap.py:159
↓ 2 callersMethodinsert_before_node
(self, node: Node, node_to_insert: Node)
data_structures/linked_list/doubly_linked_list_two.py:99
↓ 2 callersMethodinsert_data
insert_data is used for inserting a single element at a time in the HashTable. Examples: >>> ht = HashTable(3) >>>
data_structures/hashing/hash_table.py:247
↓ 2 callersMethodinsert_many
Insert many words in the tree Args: words (list[str]): list of words >>> RadixNode("myprefix").insert_many(["mystring",
data_structures/trie/radix_tree.py:39
↓ 2 callersFunctioninvert_modulo
>>> invert_modulo(2, 5) 3 >>> invert_modulo(8,7) 1
maths/chinese_remainder_theorem.py:59
↓ 2 callersFunctionis_9_pandigital
Checks whether n is a 9-digit 1 to 9 pandigital number. >>> is_9_pandigital(12345) False >>> is_9_pandigital(156284973) True
project_euler/problem_038/sol1.py:44
↓ 2 callersMethodis_empty
(self)
graphs/minimum_spanning_tree_prims2.py:97
↓ 2 callersMethodis_empty
>>> queue = LinkedQueue() >>> queue.is_empty() True >>> for i in range(1, 6): ... queue.put(i) >>
data_structures/queues/linked_queue.py:83
↓ 2 callersMethodis_empty
Checks whether the queue is empty or not >>> cq = CircularQueueLinkedList() >>> cq.is_empty() True >>> cq.enq
data_structures/queues/circular_queue_linked_list.py:40
↓ 2 callersMethodis_empty
Check if linked list is empty. >>> linked_list = LinkedList() >>> linked_list.is_empty() True >>> linked_list
data_structures/linked_list/singly_linked_list.py:325
↓ 2 callersMethodis_full
>>> S = Stack() >>> S.is_full() False >>> S = Stack(1) >>> S.push(10) >>> S.is_full() True
data_structures/stacks/stack.py:110
↓ 2 callersFunctionis_hermitian
Checks if a matrix is Hermitian. >>> import numpy as np >>> A = np.array([ ... [2, 2+1j, 4], ... [2-1j, 3, 1j], ... [4,
linear_algebra/src/rayleigh_quotient.py:10
↓ 2 callersFunctionis_luhn
Perform Luhn validation on an input string Algorithm: * Double every other digit starting from 2nd last digit. * Subtract 9 if number
hashes/luhn.py:6
↓ 2 callersFunctionis_operand
Return True if the given char c is an operand, e.g. it is a number >>> is_operand("1") True >>> is_operand("+") False
data_structures/stacks/prefix_evaluation.py:14
↓ 2 callersFunctionis_palindrome
Return True if s is a palindrome otherwise return False. >>> all(is_palindrome(key) == value for key, value in test_data.items()) True
strings/palindrome.py:21
↓ 2 callersFunctionis_palindrome
Return true if the input n is a palindrome. Otherwise return false. n can be an integer or a string. >>> is_palindrome(909) True
project_euler/problem_036/sol1.py:21
↓ 2 callersFunctionis_pentagonal
Returns True if n is pentagonal, False otherwise. >>> is_pentagonal(330) True >>> is_pentagonal(7683) False >>> is_pent
project_euler/problem_044/sol1.py:15
↓ 2 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) False
data_structures/hashing/number_theory/prime_numbers.py:9
↓ 2 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_046/sol1.py:25
↓ 2 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. Returns boolean representin
project_euler/problem_027/sol1.py:26
↓ 2 callersFunctionis_prime
For 2 <= n <= 1000000, return True if n is prime. >>> is_prime(87) False >>> is_prime(23) True >>> is_prime(25363)
project_euler/problem_035/sol1.py:30
↓ 2 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. Returns boolean representin
project_euler/problem_007/sol1.py:18
↓ 2 callersFunctionis_prime_low_num
(num: int)
ciphers/rabin_miller.py:28
↓ 2 callersFunctionis_public
(name: str)
data_structures/hashing/tests/test_hash_map.py:91
↓ 2 callersFunctionis_square
>>> is_square([]) True >>> is_square(matrix_1_to_4) True >>> is_square(matrix_5_to_9_high) False
matrix/matrix_multiplication_recursion.py:58
↓ 2 callersFunctionjohnson
Compute all-pairs shortest paths using Johnson's algorithm. Reference: https://en.wikipedia.org/wiki/Johnson%27s_algorithm Args
graphs/johnson.py:75
↓ 2 callersFunctionknapsack
(w, wt, val, n)
dynamic_programming/knapsack.py:29
↓ 2 callersFunctionkruskal
>>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1)]) [(2, 3, 1), (0, 1, 3), (1, 2, 5)] >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0,
graphs/minimum_spanning_tree_kruskal.py:1
↓ 2 callersMethodletter_to_numbers
Return the pair of numbers that represents the given letter in the polybius square >>> np.array_equal(BifidCipher().letter_t
ciphers/bifid.py:25
↓ 2 callersFunctionlin_search
Perform linear search in list. Returns -1 if element is not found. Parameters ---------- left : int left index bound. right :
searches/ternary_search.py:20
↓ 2 callersFunctionlr_rotation
r""" A A Br / \ / \ / \ B C LR Br C RR
data_structures/binary_tree/avl_tree.py:126
↓ 2 callersFunctionlucas_lehmer_test
>>> lucas_lehmer_test(p=7) True >>> lucas_lehmer_test(p=11) False # M_11 = 2^11 - 1 = 2047 = 23 * 89
maths/lucas_lehmer_primality_test.py:16
↓ 2 callersFunctionmake_table_row
>>> make_table_row(("One", "Two", "Three")) '| One | Two | Three |'
boolean_algebra/nor_gate.py:48
↓ 2 callersFunctionmatrix_chain_multiply
Find the minimum number of multiplcations required to multiply the chain of matrices Args: `arr`: The input array of integers.
dynamic_programming/matrix_chain_multiplication.py:54
↓ 2 callersFunctionmatrix_chain_order
Source: https://en.wikipedia.org/wiki/Matrix_chain_multiplication The dynamic programming solution is faster than cached the recursive solut
dynamic_programming/matrix_chain_multiplication.py:99
↓ 2 callersFunctionmax_height
r""" Returns the maximum height that the object reach Formula: .. math:: \frac{v_0^2 \cdot \sin^2 (\alpha)}{2 g}
physics/horizontal_projectile_motion.py:78
↓ 2 callersFunctionmax_tasks
Create a list of Task objects that are sorted so the highest rewards come first. Return a list of those task ids that can be completed before
scheduling/job_sequence_with_deadline.py:28
↓ 2 callersFunctionmd_prefix
Markdown prefix based on indent for bullet points >>> md_prefix(0) '\\n##' >>> md_prefix(1) ' *' >>> md_prefix(2) '
scripts/build_directory_md.py:21
↓ 2 callersFunctionmedian_filter
:param gray_img: gray image :param mask: mask size :return: image with median filter
digital_image_processing/filters/median_filter.py:9
↓ 2 callersFunctionmerge
(left: list[Any], right: list[Any])
sorts/tim_sort.py:30
↓ 2 callersFunctionmerge
sorting left-half and right-half individually then merging them into result
sorts/iterative_merge_sort.py:15
↓ 2 callersMethodmerge
Merge 2 nodes together. >>> SkewNode.merge(SkewNode(10),SkewNode(-10.5)).value -10.5 >>> SkewNode.merge(SkewNode(10),
data_structures/heap/skew_heap.py:59
↓ 2 callersMethodmerge
Merge 2 nodes together. >>> rhn1 = RandomizedHeapNode(10) >>> rhn2 = RandomizedHeapNode(20) >>> RandomizedHeapNode.m
data_structures/heap/randomized_heap.py:38
↓ 2 callersMethodmerge_trees
In-place merge of two binomial trees of equal size. Returns the root of the resulting tree
data_structures/heap/binomial_heap.py:23
↓ 2 callersMethodminor
returns the minor along (x, y)
linear_algebra/src/lib.py:383
↓ 2 callersMethodmove_and_reproduce
Attempts to move to an unoccupied neighbouring square in either of the four directions (North, South, East, West). If the mov
cellular_automata/wa_tor.py:257
↓ 2 callersFunctionmultiply
(matrix_a: list[list[int]], matrix_b: list[list[int]])
matrix/nth_fibonacci_using_matrix_exponentiation.py:19
↓ 2 callersFunctionmultiply
>>> multiply([[1,2],[3,4]],[[5,5],[7,5]]) [[19, 15], [43, 35]] >>> multiply([[1,2.5],[3,4.5]],[[5,5],[7,5]]) [[22.5, 17.5], [46.5, 37
matrix/matrix_operation.py:60
↓ 2 callersFunctionmutate
Mutate a random gene of a child with another one from the list. >>> random.seed(123) >>> mutate("123456", list("ABCDEF")) '12345A'
genetic_algorithm/basic_string.py:48
↓ 2 callersFunctionnaive_pattern_search
>>> naive_pattern_search("ABAAABCDBBABCDDEBCABC", "ABC") [4, 10, 18] >>> naive_pattern_search("ABC", "ABAAABCDBBABCDDEBCABC") []
strings/naive_string_search.py:12
↓ 2 callersFunctionnext_prime
(value, factor=1, **kwargs)
data_structures/hashing/number_theory/prime_numbers.py:50
↓ 2 callersMethodnumbers_to_letter
Return the letter corresponding to the position [index1, index2] in the polybius square >>> BifidCipher().numbers_to_letter(
ciphers/bifid.py:40
↓ 2 callersFunctionoutput
:param data_set: test data or train data :param example_no: example whose output is to be fetched :return: output for that example
machine_learning/gradient_descent.py:49
↓ 2 callersFunctionparse_grid
Convert grid to a dict of possible values, {square: digits}, or return False if a contradiction is detected.
data_structures/arrays/sudoku_solver.py:64
↓ 2 callersFunctionpartition
>>> partition(5) 7 >>> partition(7) 15 >>> partition(100) 190569292 >>> partition(1_000) 2406146786403262247369214972
dynamic_programming/integer_partition.py:11
↓ 2 callersFunctionpass_and_relaxation
( graph: dict, v: str, visited_forward: set, visited_backward: set, cst_fwd: dict, cst
graphs/bi_directional_dijkstra.py:19
↓ 2 callersFunctionpeak_signal_to_noise_ratio
(original: float, contrast: float)
data_compression/peak_signal_to_noise_ratio.py:17
↓ 2 callersFunctionpig_latin
Compute the piglatin of a given string. https://en.wikipedia.org/wiki/Pig_Latin Usage examples: >>> pig_latin("pig") 'igpay'
strings/pig_latin.py:1
↓ 2 callersFunctionplot_partition_boundary
We cannot get the optimal w of our kernel SVM model, which is different from a linear SVM. For this reason, we generate randomly distributed
machine_learning/sequential_minimum_optimization.py:567
↓ 2 callersMethodpop
Pop the root element
data_structures/heap/max_heap.py:53
↓ 2 callersMethodpop
pop the top element off the stack
data_structures/stacks/stack_with_doubly_linked_list.py:58
↓ 2 callersFunctionpopulate_output
(root: Node | None, level: int)
data_structures/binary_tree/binary_tree_traversals.py:129
↓ 2 callersMethodpostorder_traverse
(self)
data_structures/binary_tree/red_black_tree.py:480
↓ 2 callersFunctionprecedence
Return integer value representing an operator's precedence, or order of operation. https://en.wikipedia.org/wiki/Order_of_operations
data_structures/stacks/infix_to_postfix_conversion.py:28
↓ 2 callersMethodpredict
Make predictions on input data. Parameters: - features (np.ndarray): The input data for making predictions. Returns
machine_learning/gradient_boosting_classifier.py:56
↓ 2 callersMethodpredict
(self, test_samples, classify=True)
machine_learning/sequential_minimum_optimization.py:143
↓ 2 callersMethodprefix
Prefix sum of all elements in [0, right) in O(lg N) Parameters: right (int): right bound of the query (exclusive)
data_structures/binary_tree/fenwick_tree.py:129
↓ 2 callersMethodpreorder_traverse
(self)
data_structures/binary_tree/red_black_tree.py:466
↓ 2 callersFunctionprice_plus_tax
>>> price_plus_tax(100, 0.25) 125.0 >>> price_plus_tax(125.50, 0.05) 131.775
financial/price_plus_tax.py:6
↓ 2 callersFunctionprime_factors
Returns prime factors of n as a list. >>> prime_factors(0) [] >>> prime_factors(100) [2, 2, 5, 5] >>> prime_factors(2560)
maths/prime_factors.py:8
↓ 2 callersFunctionprint_linked_list
Print the entire linked list iteratively. This function prints the elements of a linked list separated by '->'. Parameters:
data_structures/linked_list/rotate_to_the_right.py:12
↓ 2 callersFunctionprint_solution
A function to print the solution in the form of a 9x9 grid
backtracking/sudoku.py:112
↓ 2 callersMethodprint_stack
(self)
data_structures/stacks/stack_with_doubly_linked_list.py:85
↓ 2 callersMethodprocess
(self)
digital_image_processing/resize/resize.py:30
↓ 2 callersMethodprocess
(self)
digital_image_processing/dithering/burkes.py:56
↓ 2 callersMethodprocess
Calculate y[n] >>> issubclass(FilterType, Protocol) True
audio_filters/show_response.py:13
↓ 2 callersMethodprocess_text
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.process_text('Testing Hill Cipher') 'TESTINGHILLCIPH
ciphers/hill_cipher.py:104
↓ 2 callersFunctionrank_till_index
Returns the number of occurrences of num in interval [0, index] in the list >>> root = build_tree(test_array) >>> rank_till_index(root,
data_structures/binary_tree/wavelet_tree.py:70
↓ 2 callersFunctionrayleigh_quotient
Returns the Rayleigh quotient of a Hermitian matrix A and vector v. >>> import numpy as np >>> A = np.array([ ... [1, 2, 4],
linear_algebra/src/rayleigh_quotient.py:30
↓ 2 callersFunctionread_key_file
(key_filename: str)
ciphers/rsa_cipher.py:63
↓ 2 callersFunctionremove_non_letters
>>> remove_non_letters("Hi! how are you?") 'Hi how are you' >>> remove_non_letters("P^y%t)h@o*n") 'Python' >>> remove_non_letters
strings/detecting_english_programmatically.py:27
↓ 2 callersMethodreplace_digits
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.replace_digits(19) 'T' >>> hill_cipher.repla
ciphers/hill_cipher.py:74
↓ 2 callersMethodreplace_letters
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.replace_letters('T') 19 >>> hill_cipher.repl
ciphers/hill_cipher.py:64
↓ 2 callersFunctionres
Reduces large number to a more manageable number >>> res(5, 7) 4.892790030352132 >>> res(0, 5) 0 >>> res(3, 0) 1 >>>
maths/largest_of_very_large_numbers.py:6
↓ 2 callersFunctionreverse_column
(matrix: list[list[int]])
matrix/rotate_matrix.py:74
↓ 2 callersFunctionreverse_row
(matrix: list[list[int]])
matrix/rotate_matrix.py:69
↓ 2 callersMethodright
Returns the index of right child Examples: >>> priority_queue_test = PriorityQueue() >>> priority_queue_test.right(0
graphs/dijkstra_algorithm.py:143
↓ 2 callersFunctionrl_rotation
(node: MyNode)
data_structures/binary_tree/avl_tree.py:143
↓ 2 callersFunctionrotator
()
hashes/enigma_machine.py:10
↓ 2 callersMethodrvi
Ratio-Vegetation-Index http://www.seos-project.eu/modules/remotesensing/remotesensing-c03-s01-p01.html :return: index
digital_image_processing/index_calculation.py:424
↓ 2 callersMethodsearch
(self)
graphs/bidirectional_breadth_first_search.py:62
↓ 2 callersFunctionseed
(canvas: list[list[bool]])
cellular_automata/game_of_life.py:49
↓ 2 callersFunctionsend_file
(filename: str = "mytext.txt", testing: bool = False)
file_transfer/send_file.py:1
← previousnext →501–600 of 3,909, ranked by callers