MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionheaps
Pure python implementation of the iterative Heap's algorithm, returning all permutations of a list. >>> heaps([]) [()] >>> heaps(
divide_and_conquer/heaps_algorithm_iterative.py:10
↓ 1 callersFunctionhorner
Evaluate a polynomial at specified point using Horner's method. In terms of computational complexity, Horner's method is an efficient method
maths/polynomial_evaluation.py:18
↓ 1 callersFunctionhoroscope
(zodiac_sign: int, day: str)
web_programming/daily_horoscope.py:13
↓ 1 callersFunctionhubble_parameter
Input Parameters ---------------- hubble_constant: Hubble constante is the expansion rate today usually given in km/(s*Mpc) radi
physics/hubble_parameter.py:30
↓ 1 callersFunctionhuffman
Parse the file, build the tree, then run through the file again, using the letters dictionary to find and print out the bitstring for eac
data_compression/huffman.py:69
↓ 1 callersFunctionidentity
(n: int)
matrix/nth_fibonacci_using_matrix_exponentiation.py:33
↓ 1 callersFunctionidentity
:param n: dimension for nxn matrix :type n: int :return: Identity matrix of shape [n, n] >>> identity(3) [[1, 0, 0], [0, 1, 0], [
matrix/matrix_operation.py:83
↓ 1 callersFunctionignore_overflow_warnings
Ignore some overflow and invalid value warnings. >>> ignore_overflow_warnings()
fractals/julia_sets.py:148
↓ 1 callersFunctionim2col
(image, block_size)
digital_image_processing/filters/convolve.py:8
↓ 1 callersFunctionimply_gate
Calculate IMPLY of the input values >>> imply_gate(0, 0) 1 >>> imply_gate(0, 1) 1 >>> imply_gate(1, 0) 0 >>> imply_g
boolean_algebra/imply_gate.py:20
↓ 1 callersFunctionin_order
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:64
↓ 1 callersFunctionin_order_iter
>>> root = TreeNode(1) >>> tree_node2 = TreeNode(2) >>> tree_node3 = TreeNode(3) >>> tree_node4 = TreeNode(4) >>> tree_node5 = Tr
searches/binary_tree_traversal.py:202
↓ 1 callersFunctionin_reverse
Prints the elements of the given Linked List in reverse order >>> in_reverse(LinkedList()) '' >>> in_reverse(make_linked_list([69, 88, 73]
data_structures/linked_list/print_reverse.py:110
↓ 1 callersMethodinc
(self, num_occur: int)
machine_learning/frequent_pattern_growth.py:46
↓ 1 callersFunctionincrement_score
Calculates the score for a move based on the number of elements removed. >>> increment_score(3) 6 >>> increment_score(0) 0
matrix/matrix_based_game.py:164
↓ 1 callersFunctionindian_phone_validator
Determine whether the string is a valid phone number or not :param phone: :return: Boolean >>> indian_phone_validator("+91123456789")
strings/indian_phone_validator.py:4
↓ 1 callersFunctioninfix_2_postfix
>>> infix_2_postfix("a+b^c") # doctest: +NORMALIZE_WHITESPACE Symbol | Stack | Postfix ---------------------------- a |
data_structures/stacks/infix_to_prefix_conversion.py:18
↓ 1 callersFunctioninfix_2_prefix
>>> infix_2_prefix("a+b^c") # doctest: +NORMALIZE_WHITESPACE Symbol | Stack | Postfix ---------------------------- c |
data_structures/stacks/infix_to_prefix_conversion.py:127
↓ 1 callersFunctioninfix_to_postfix
>>> infix_to_postfix("(1*(2+3)+4))") Traceback (most recent call last): ... ValueError: Mismatched parentheses >>> infix_to_p
data_structures/stacks/infix_to_postfix_conversion.py:45
↓ 1 callersMethodinit
Initialize the Fenwick tree with arr in O(N) Parameters: arr (list): list of elements to initialize the tree with
data_structures/binary_tree/fenwick_tree.py:28
↓ 1 callersMethodinitializer
(self, back_units)
neural_network/back_propagation_neural_network.py:53
↓ 1 callersFunctioninorder
In-order traversal visits left subtree, root node, right subtree. >>> list(inorder(make_tree())) [4, 2, 5, 1, 3]
data_structures/binary_tree/binary_tree_traversals.py:59
↓ 1 callersFunctioninorder
>>> inorder(make_tree()) [6, 10, 14, 15, 20, 25, 60]
data_structures/binary_tree/inorder_tree_traversal_2022.py:46
↓ 1 callersMethodinorder
Perform an inorder traversal and append values of the nodes to a list named arr
data_structures/binary_tree/binary_search_tree.py:318
↓ 1 callersFunctioninsert
Insert element Split current tree with a value into left, right, Insert new node into the middle Merge left, node, right into root
data_structures/binary_tree/treap.py:83
↓ 1 callersMethodinsert
Insert the value into the heap. >>> rh = RandomizedHeap() >>> rh.insert(3) >>> rh.insert(1) >>> rh.insert(3)
data_structures/heap/randomized_heap.py:111
↓ 1 callersMethodinsert
(self, data: Any)
data_structures/binary_tree/avl_tree.py:285
↓ 1 callersMethodinsert
Insert a word into the tree Args: word (str): word to insert >>> RadixNode("myprefix").insert("mystring") >>> r
data_structures/trie/radix_tree.py:50
↓ 1 callersMethodinsert
Inserts a word into the Trie :param word: word to be inserted :return: None
data_structures/trie/trie.py:23
↓ 1 callersMethodinsert_after_node
(self, node: Node, node_to_insert: Node)
data_structures/linked_list/doubly_linked_list_two.py:110
↓ 1 callersMethodinsert_at_head
(self, data)
data_structures/linked_list/doubly_linked_list.py:56
↓ 1 callersMethodinsert_at_tail
(self, data)
data_structures/linked_list/doubly_linked_list.py:59
↓ 1 callersMethodinsert_head
Insert a node with the given data at the beginning of the Circular Linked List.
data_structures/linked_list/circular_linked_list.py:52
↓ 1 callersMethodinsert_many
Inserts a list of words into the Trie :param words: list of string words :return: None
data_structures/trie/trie.py:14
↓ 1 callersFunctioninsert_next
Inserts the '(index-1)th' element into place >>> col = [3, 2, 4, 2] >>> insert_next(col, 1) >>> col [2, 3, 4, 2] >>> col =
sorts/recursive_insertion_sort.py:39
↓ 1 callersFunctioninsert_node
(node: MyNode | None, data: Any)
data_structures/binary_tree/avl_tree.py:150
↓ 1 callersMethodinsert_tail
Insert a node with the given data at the end of the Circular Linked List.
data_structures/linked_list/circular_linked_list.py:46
↓ 1 callersMethodinsert_word
(self, text: str)
strings/autocomplete_using_trie.py:10
↓ 1 callersFunctioninsertion_sort
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> insertion_sort(array, 0, len(array)) [1, 2, 4, 6, 7, 8, 8, 12,
sorts/intro_sort.py:10
↓ 1 callersFunctioninsertion_sort
A pure Python implementation of the insertion sort algorithm :param collection: some mutable ordered collection with heterogeneous comparable
sorts/insertion_sort.py:27
↓ 1 callersFunctioninsertion_sort
(lst: list[Any])
sorts/tim_sort.py:19
↓ 1 callersFunctioninteract_treap
Commands: + value to add value into treap - value to erase all nodes with value >>> root = interact_treap(None, "+1") >>
data_structures/binary_tree/treap.py:121
↓ 1 callersFunctioninterpolate
Given a list of data points (1,y0),(2,y1), ..., return a function that interpolates the data points. We find the coefficients of the interpol
project_euler/problem_101/sol1.py:113
↓ 1 callersMethodinterpret_tableau
Given the final tableau, add the corresponding values of the basic decision variables to the `output_dict` >>> {key: float(value) for
linear_programming/simplex.py:307
↓ 1 callersFunctionintersection
function is the f we want to find its root x0 and x1 are two random starting points >>> intersection(lambda x: x ** 3 - 1, -5, 5) 0.9
maths/numerical_analysis/intersection.py:5
↓ 1 callersFunctionintro_sort
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> max_depth = 2 * math.ceil(math.log2(len(array))) >>> intro_sort
sorts/intro_sort.py:166
↓ 1 callersFunctioninverse
>>> inverse([[1, 2], [3, 4]]) [[-2.0, 1.0], [1.5, -0.5]] >>> inverse([[1, 1], [1, 1]])
matrix/matrix_operation.py:141
↓ 1 callersMethodinverse
(self)
matrix/matrix_class.py:223
↓ 1 callersFunctioninvert_matrix
Returns the inverse of a square matrix using NumPy. Parameters: matrix (list[list[float]]): A square matrix. Returns: list[list
linear_algebra/matrix_inversion.py:4
↓ 1 callersFunctioninvert_modulo
This function find the inverses of a i.e., a^(-1) >>> invert_modulo(2, 5) 3 >>> invert_modulo(8,7) 1
maths/modular_division.py:43
↓ 1 callersFunctionis_balanced
>>> is_balanced("") True >>> is_balanced("()") True >>> is_balanced("[]") True >>> is_balanced("{}") True >>> is_
other/nested_brackets.py:17
↓ 1 callersFunctionis_breakable
>>> string = 'a' >>> is_breakable(1) True
dynamic_programming/word_break.py:84
↓ 1 callersFunctionis_carmichael_number
Examples: >>> is_carmichael_number(4) False >>> is_carmichael_number(561) True >>> is_carmichael_number(562) False >>
maths/special_numbers/carmichael_number.py:35
↓ 1 callersFunctionis_combination_valid
Checks if a combination (a tuple of 9 digits) is a valid product equation. >>> is_combination_valid(('3', '9', '1', '8', '6', '7', '2',
project_euler/problem_032/sol32.py:19
↓ 1 callersFunctionis_complete
Check if the board (matrix) has been completely filled with non-zero values. >>> is_complete([[1]]) True >>> is_complete([[1, 2], [
backtracking/knight_tour.py:35
↓ 1 callersFunctionis_digit_cancelling
(num: int, den: int)
project_euler/problem_033/sol1.py:23
↓ 1 callersMethodis_empty
Conditional boolean method to determine if the priority queue is empty or not. Examples: >>> priority_queue_test = PriorityQ
graphs/dijkstra_algorithm.py:30
↓ 1 callersMethodis_empty
Checks whether the queue is empty or not >>> cq = CircularQueue(5) >>> cq.is_empty() True >>> cq.enqueue("A")
data_structures/queues/circular_queue.py:28
↓ 1 callersMethodis_empty
(self)
data_structures/linked_list/__init__.py:89
↓ 1 callersMethodis_empty
>>> linked_list = DoublyLinkedList() >>> linked_list.is_empty() True >>> linked_list.insert_at_tail(1) >>> li
data_structures/linked_list/doubly_linked_list.py:179
↓ 1 callersMethodis_empty
(self)
data_structures/heap/binomial_heap.py:253
↓ 1 callersMethodis_empty
(self)
data_structures/binary_tree/avl_tree.py:22
↓ 1 callersMethodis_empty
(self)
data_structures/stacks/stack_with_doubly_linked_list.py:82
↓ 1 callersFunctionis_even
input: integer 'number' returns true if 'number' is even, otherwise false. >>> is_even(0) True >>> is_even(8) True >>> i
maths/primelib.py:319
↓ 1 callersFunctionis_for_table
>>> is_for_table('__1','011',2) True >>> is_for_table('01_','001',1) False
boolean_algebra/quine_mc_cluskey.py:67
↓ 1 callersMethodis_full
(self)
data_structures/binary_tree/basic_binary_tree.py:23
↓ 1 callersFunctionis_in_circle
(x: float, y: float)
maths/monte_carlo.py:24
↓ 1 callersMethodis_in_unit_circle
True, if the point lies in the unit circle False, otherwise
maths/pi_monte_carlo_estimation.py:9
↓ 1 callersMethodis_invertable
(self)
matrix/matrix_class.py:175
↓ 1 callersFunctionis_ip_v4_address_valid
print "Valid IP address" If IP is valid. or print "Invalid IP address" If IP is invalid. >>> is_ip_v4_address_valid("192.168.0.23")
maths/is_ip_v4_address_valid.py:12
↓ 1 callersFunctionis_isogram
An isogram is a word in which no letter is repeated. Examples of isograms are uncopyrightable and ambidextrously. >>> is_isogram('Uncopyr
strings/is_isogram.py:6
↓ 1 callersFunctionis_magic_gon
Check if the solution set is a magic n-gon ring Check that the first number is the smallest number on the outer ring Take a list, and che
project_euler/problem_068/sol1.py:104
↓ 1 callersFunctionis_match
>>> is_match("", "") True >>> is_match("aa", "a") False >>> is_match("abc", "abc") True >>> is_match("abc", "*c") Tru
dynamic_programming/wildcard_matching.py:19
↓ 1 callersFunctionis_mirror
Check if two subtrees are mirror images of each other. Parameters: left: The root node of the left subtree. right: The root node of
data_structures/binary_tree/symmetric_tree.py:125
↓ 1 callersFunctionis_palindrome
Check if an integer is palindromic. >>> is_palindrome(12521) True >>> is_palindrome(12522) False >>> is_palindrome(12210)
project_euler/problem_125/sol1.py:19
↓ 1 callersFunctionis_palindrome
Returns True if a number is palindrome. >>> is_palindrome(12567321) False >>> is_palindrome(1221) True >>> is_palindrom
project_euler/problem_055/sol1.py:30
↓ 1 callersFunctionis_palindrome_recursive
Return True if s is a palindrome otherwise return False. >>> all(is_palindrome_recursive(key) == value for key, value in test_data.items())
strings/palindrome.py:59
↓ 1 callersFunctionis_palindrome_slice
Return True if s is a palindrome otherwise return False. >>> all(is_palindrome_slice(key) == value for key, value in test_data.items())
strings/palindrome.py:74
↓ 1 callersFunctionis_pentagonal
Returns True if n is pentagonal, False otherwise. >>> is_pentagonal(330) True >>> is_pentagonal(7683) False >>> is_pent
project_euler/problem_045/sol1.py:30
↓ 1 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_041/sol1.py:20
↓ 1 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
project_euler/problem_058/sol1.py:40
↓ 1 callersFunctionis_prime
Determines whether number is prime >>> is_prime(3) True >>> is_prime(4) False
project_euler/problem_131/sol1.py:18
↓ 1 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
project_euler/problem_049/sol1.py:32
↓ 1 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_010/sol1.py:17
↓ 1 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_010/sol2.py:19
↓ 1 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/sol2.py:18
↓ 1 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/sol3.py:19
↓ 1 callersFunctionis_proth_number
:param number: positive integer number :return: true if number is a Proth number, false otherwise >>> is_proth_number(1) False >>
maths/special_numbers/proth_number.py:62
↓ 1 callersFunctionis_right
Check if the triangle described by P(x1,y1), Q(x2,y2) and O(0,0) is right-angled. Note: this doesn't check if P and Q are equal, but that's h
project_euler/problem_091/sol1.py:17
↓ 1 callersFunctionis_safe
This function returns a boolean value True if it is safe to place a queen there considering the current state of the board. Parameters:
backtracking/n_queens.py:16
↓ 1 callersFunctionis_safe
This function checks the grid to see if each row, column, and the 3x3 subgrids contain the digit 'n'. It returns False if it is not 'safe
backtracking/sudoku.py:44
↓ 1 callersFunctionis_safe
Checking whether coordinate (row, col) is valid or not. >>> is_safe(0, 0, 5, 5) True >>> is_safe(-1,-1, 5, 5) False
matrix/max_area_of_island.py:21
↓ 1 callersMethodis_safe
(self, i: int, j: int, visited: list[list[bool]])
matrix/count_islands_in_matrix.py:12
↓ 1 callersFunctionis_sorted
(collection: list)
sorts/bogo_sort.py:33
↓ 1 callersFunctionis_square_form
Determines if num is in the form 1_2_3_4_5_6_7_8_9 >>> is_square_form(1) False >>> is_square_form(112233445566778899) True >
project_euler/problem_206/sol1.py:36
↓ 1 callersFunctionis_square_free
# doctest: +NORMALIZE_WHITESPACE This functions takes a list of prime factors as input. returns True if the factors are square free.
maths/is_square_free.py:10
↓ 1 callersFunctionis_sri_lankan_phone_number
Determine whether the string is a valid sri lankan mobile phone number or not References: https://aye.sh/blog/sri-lankan-phone-number-regex
strings/is_srilankan_phone_number.py:4
↓ 1 callersFunctionis_substring_divisible
Returns True if the pandigital number passes all the divisibility tests. >>> is_substring_divisible((0, 1, 2, 4, 6, 5, 7, 3, 8, 9))
project_euler/problem_043/sol1.py:24
↓ 1 callersFunctionis_valid
Checks for length of barcode and last-digit Returns boolean value of validity of barcode >>> is_valid(8718452538119) True >>> is
strings/barcode_validator.py:35
↓ 1 callersFunctionis_valid
Check if a word can be placed at the given position. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ...
backtracking/crossword_puzzle_solver.py:4
← previousnext →1,401–1,500 of 3,909, ranked by callers