- Introduction
- Installation
- Full Documenation
- Like it / Hate it
- References
["algo"] web1 is a cohesive Python Module for Algorithms. This library is an experimental collection of diverse useful algorithms from different fields of Computer Science implemented in Python. You can find the actual implementation of provided algorithms in algo.py file.
This is the Official Documentation of algo module. This API provides an implementation of different algorithms. The algorithms library defines functions for a variety of purposes (e.g. data structures, searching, sorting, counting, manipulating data) that operate on ranges of elements. Provided algorithms were collected after one year research that analyzed the most commonly used algoithms in Software Engineering. The module was created in order to help Python developers to easily utilize those frequently used algorithms without having to implement them. Written algorithms include topics from different subfields of Computer Science. The current version of the module contains 50 algorithms. We are planning to increase the number of algorithms in the second version of this API. It is important to note that the license of algo module is distributed under [Apache Licese] web2.
In order to fully use the algo module firstly download the whole package from the following link: https://github.com/Rafa1994/Python-algo-Module (click on "Download zip" on the right side). Then open the terminal and go to the directory where the module package is located. After that run this command from terminal:
For Windows, open a command prompt windows (Start ‣ Accessories) and change the command to:
Finally in the same package directory type this following command:
Tree(entry, left = None, right = None) : - Creates a General Structure for Tree. A Tree is a non-linear abstract data type or data structure that simulates a hierarchical tree structure, with a root value and subtrees of children, represented as a set of linked nodes.
-
Tree method: tree_print() - Gives the visualised structure of the tree created by Tree class.
-
Function: swap_tree(tree) - Swaps the left and right branches of a tree.
-
Function: traversal(tree) - Traverses the tree in order to get all elements in some sort of list.
-
Function: tree_to_list(tree) - Saves all data in tree in the list.
-
Function: equal_trees(t1, t2) - Checks if trees t1 and t2 are equal.
-
Function: tree_size(t) - Returns the number of elements in a tree t.
-
Function: tree_height(t) - Returns the height of a tree t.
Binary_Tree(data = None), self.left = None, self.right = None : - Creates a structure for Binary Tree. A binary search tree (BST) is a node-based binary tree data structure which has the following properties: a) The left subtree of a node contains only nodes with keys less than the node’s key, b) The right subtree of a node contains only nodes with keys greater than the node’s key, c) Both the left and right subtrees must also be binary search trees.
-
Binary_Tree method: insert(self, data) - Inserts new node with data.
-
Binary_Tree method: lookup(self, data, parent = None) - Looks up a node containing data and returns also its parent.
-
Binary_Tree method: delete(self, data) - Deletes a node containing data from binary tree.
-
Binary_Tree method: children_count(self) - Counts the number of nodes in a tree.
-
Binary_Tree method: print_tree(self) - Prints the content of the Binary tree.
-
Binary_Tree method: compare_trees(self, node) - Compates two binary trees.
-
Binary_Tree method: tree_data(self) - A generator that gets a binary tree node data.
A sorting algorithm is an algorithm that puts elements of a list(lst) in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists(lst).
-
Bubble_Sort(lst) - For description read: http://en.wikipedia.org/wiki/Bubble_sort
-
Short_Bubble(lst) - Faster version of Bubble Sort.
-
Selection_Sort(lst) - For description read: http://en.wikipedia.org/wiki/Selection_sort
-
Insertion_Sort(lst) - For description read: http://en.wikipedia.org/wiki/Insertion_sort
-
Shell_Sort(lst) - For description read: http://en.wikipedia.org/wiki/Shellsort
-
Merge_Sort(lst) - For description read: http://en.wikipedia.org/wiki/Merge_sort
-
Quick_Sort(lst) - For descritopn read: http://en.wikipedia.org/wiki/Quicksort
Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value.
-
Hash(string) - Hashing function that converts a string value to an integer value.
-
Fast_Hash(string) - A faster version of Hash(string) function.
Number theory is a branch of pure mathematics devoted primarily to the study of the integers, sometimes called "The Queen of Mathematics" because of its foundational place in the discipline. Number theorists study prime numbers as well as the properties of objects made out of integers or defined as generalizations of the integers.
-
is_prime(num) - Checks whether a given number num is a prime number or not.
-
primes(limit) - Gives the list of all prime numbers less that the limit. Read http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
-
Prime_Factorization(x) - Gives a list of all prime factors of the number x.
-
fib(n) - Generates the n-th Fibonacci number in a fast way.
-
LCM(a, b) - Counts the LCM for numbers a and b. For description read: http://en.wikipedia.org/wiki/Least_common_multiple
-
Count_Totatives(n) - Counts the totatives a number n. Read: http://en.wikipedia.org/wiki/Totative
-
GCD(a,b) - Counts the GCD for numbers a and b. For description read: http://en.wikipedia.org/wiki/Greatest_common_divisor
-
Factor(n) - Provides all the factors of the number n.
-
Pell_Equations(n, k) - Returns the list of first k solutions of the Pell's equation ( x^2 - n*(y^2) = 1 ).
-
perfect(n) - Checks whether the number n is a perfect number or not. Read: http://en.wikipedia.org/wiki/Perfect_number
In computer science, a search algorithm is an algorithm for finding an item with specified properties among a collection of items. The items may be stored individually as records in a database; or may be elements of a search space defined by a mathematical formula or procedure.
-
Binary_Search(seq, key) - Finds the position of given input key in a sequence seq. Read: http://en.wikipedia.org/wiki/Binary_search_algorithm
-
DFS(graph, start, path = []) - Implementation of DFS for traversing and searching the graph. Read: http://en.wikipedia.org/wiki/Depth-first_search
-
KMP(string, word) - Searches the substring word in a string. Read: http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
-
BMH(text, pattern) - Searches a substring pattern in a text. Read: http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool_algorithm
-
RKS(substring, string) - Finds any one of a set of pattern strings in a text. Read: http://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
-
shuffle(seq) - Shuffles all the items in the list.
-
jaccard_index(dataset_1, dataset_2) - Calculates Jaccard similarity coefficient for two datasets. Read more: http://en.wikipedia.org/wiki/Jaccard_index
-
Levenshtein_distance(s1, s2) - Measure the distance between two sequences. Read more: http://en.wikipedia.org/wiki/Levenshtein_distance
-
find_max_subarray(numbers) - Finds the contiguous subarray within a one-dimensional array of numbers which has the largest sum.
-
permutations(l) - A generator that retursn all the permutations of the given list l.
-
is_polindrom(string) - Checks whether the given string is a polindrom or not.
-
Most_Common(lst) - Identifies the most common element in the given list lst.
-
is_Anagram(s1,s2) - Checks whether strings s1 and s2 are anagrams or not.
-
Find_Nonrepeat(s) - Finds the first nonrepeated character in the string s.
-
atoi(str) - Converts str into an integer, and returns that integer.
-
Weighted_Random(W) - Generate random integers given a list W of integers.
-
Hamming_Distance(str1, str2) - Calculates the distance between two strings of equal length. Read more: http://en.wikipedia.org/wiki/Hamming_distance
This API has been written by [Rafayel Mkrtchyan] web3. For additional comments and suggestions you can contact [email protected]. I don't claim to be perfect so if you find a bug in this library, please send me an email preferably with a test that revealed that error so that I know what I need to fix.