background preloader

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. The Dijkstra algorithm uses labels that are positive integers or real numbers, which are totally ordered. Dijkstra's algorithm uses a data structure for storing and querying partial solutions sorted by distance from the start. (where is the number of nodes).[10] The idea of this algorithm is also given in Leyzorek et al. 1957. . History[edit] Algorithm[edit] is may hold.

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. 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.

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. Example The first part of the solution is declaring an array to store the frequencies. 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 We counted the letter frequencies in a string or file using the C# language. Review:Most important in the solution is how the array is declared and the constants are used.

Related: