background preloader

Math

Facebook Twitter

Count Letter Frequencies. English text contains some letters more than others. It is possible to compute a table of letter frequencies. We do this with a method in the C# language. This may be part of a homework assignment or required for simple textual analysis. Example The first part of the solution is declaring an array to store the frequencies. In the C# programming language, the char type is 2 bytes, which means it contains 65535 elements to store. ArrayInt Array Description of part 1. Char Type Description of part 2. File.ReadAllText: TXT Next:We add up frequencies by iterating over each letter, and casting it to an int. Finally:We display all letter or digit characters we found. Console.WriteLine Correct Incorrect code is worse than useless in production environments. Input file aaaa bbbbb aaaa bbbbb aaaa bbbbb CCcc xx y y y y y Z Output Letter: C Frequency: 2 Letter: Z Frequency: 1 Letter: a Frequency: 12 Letter: b Frequency: 15 Letter: c Frequency: 2 Letter: x Frequency: 2 Letter: y Frequency: 5 Summary.

Genetic Algorithm. A genetic algorithm is a class of adaptive stochastic optimization algorithms involving search and optimization. Genetic algorithms were first used by Holland (1975). The basic idea is to try to mimic a simple picture of natural selection in order to find a good algorithm. The first step is to mutate, or randomly vary, a given collection of sample programs. The second step is a selection step, which is often done through measuring against a fitness function.

There are a large number of different types of genetic algorithms. Like a gradient flow optimization, it is possible for the process to get stuck in a local maximum of the fitness function. Holland created an electronic organism as a binary string ("chromosome"), and then used genetic and evolutionary principles of fitness-proportionate selection for reproduction (including random crossover and mutation) to search enormous solution spaces efficiently.

Data Structures and Algorithms with Object-Oriented Design Patterns in Python. Dijkstra's algorithm. Graph search algorithm The algorithm exists in many variants. Dijkstra's original algorithm found the shortest path between two given nodes,[6] but a more common variant fixes a single node as the "source" node and finds shortest paths from the source to all other nodes in the graph, producing a shortest-path tree. For a given source node in the graph, the algorithm finds the shortest path between that node and every other.[7]: 196–206 It can also be used for finding the shortest paths from a single node to a single destination node by stopping the algorithm once the shortest path to the destination node has been determined. For example, if the nodes of the graph represent cities and costs of edge paths represent driving distances between pairs of cities connected by a direct road (for simplicity, ignore red lights, stop signs, toll roads and other obstructions), then Dijkstra's algorithm can be used to find the shortest route between one city and all other cities.

(where . History[edit] Dijkstra's Algorithm Animated. List of algorithms.