| ||||||||
|
Algorithms are the heart of programs--they are the instructions for performing particular tasks. In computer programs, algorithms are constructed using the specifics of the programming language (and any libraries related to that language). Generally speaking, algorithms are measured by:
Algorithms must balance each of these factors to be useful. RecursionComputer algorithms are often recursive (the routine calls itself). Recursion can be multiply recursive (the routine calls itself multiple times) or indirectly recursive (the routine calls another routine which calls the first. Recursion is useful in breaking complex problems into smaller, simpler sets of instructions that can be called repeatedly to solve an apparently complex problem. Common recursion problems include factorial solutions (e.g., 3! = 3 * 2 * 1), Fibonacci Numbers (0, 1, 1, 2, 3, 5, 8, 13, ... add the last two to get the next), curves, and so forth. Data Structures for AlgorithmsLists: list structures are commonly used to organize data in a program. List processing considerations include:
Special types of lists include stacks and queues:
Arrays: arrays are very structured lists (table-like) organized around specific data types (and even different data types). Arrays range from single (more like a list) to multi-dimensional (lists of lists (of even more lists)). Trees: a special type of list which is based on "tree-like" (root, branch, leaves) nodes which connect to sub-trees. Tree terminology includes roots (a starting point), branches (connectors to sub-trees), and depth (how far down the tree goes). Trees are used extensively for decision list branching (the basis of many expert systems), network modeling (computers hooked to servers hooked to more servers). Dealing with Data using Algorithms...Sorting: putting lists, trees, and arrays into order (sequential, etc.) is common problem for algorithms. Some of the common methods for sorting include:
Searching: is the process of finding things in the lists after they are sorted (see last section). There are various types of searches:
Searching strings: apply the above techniques. String searches tend to be the most intensive due to the large variations in string constitution (number of letters/digits) and size and the need to find sub-strings (e.g., find "frog" in words like "froggy") Hashing: a kind of "guessing game" in which you estimate "where in the list" you will find what you want, place that range of values in a table (called a hash table) and search it. Chaining via linked lists is often used to manage the hash. Network algorithms: used to search, traverse, and analyze network structures to find out size, aggregate behavior (performance), distances of paths in a network, scheduling (time dependent problems), etc.. Key is understanding how the network is structures (uni- or bi-directional paths between nodes). Creating AlgorithmsFrom a programming point of view, there are two things to consider:
Testing is essential to:
|
|
Copyright © 1999
- 2005 |