General Programming |
|
Any questions mail me at general@teentwo.8m.com 1.Five steps to writing an effective program The art of creating a sucesfull program lies in these five steps : "Design of the algorithm: This is the stage where the problem to be solved is established and the best solution is proposed, also create schematic diagrams of the different proposals. Coding the algorithm: This stage consist of writing the program in the programming language. Translation to machine language: This is the creation of the object program, in other words, the written program as a sequence of ones and zeros that can be interpreted by the processor. Test the program: This step is underrated andmostly forgotten, after the translation of the program into machine language, test the program. The last stage is the elimination of detected faults. The correction of a fault normally requires the repetition of all the steps from the first or second." From the 1996 "Assembler Tutorial of the University of Guadajara" Any questions mail me at general@teentwo.8m.com Sorting is not used very much in general, but as soon as you start using database related procedures it helps to sort your data in one way or the other.There are a few ways to sort data, the easy, the slow and hard, and the fast way. There are of course other sorting methods like quicksort; mergesort and much more, these sorting methods are more complex. Bubble sort : This is the easy sorting method, it compares the first number with the second, if the second is smaller than the first, it swaps them, else it just ignores it, and goes on. It continues to tests the number with the following number. Ex. Now it has stepped through all the numbers once, these steps are continued till there are no more numbers left to swap. Here are the rest of the steps. 1 3 5 4 7 2 8 9 Selection sort : This sorting is easy to understand but harder to program. Selection sort seeks the smallest element and places it in front. Now the first number is sorted. It continues by the second number and goes through the array looking for the smallest one and swap them, now the third number, and so forth. Ex. As you can see this method of sorting is much faster than bubble sort since it only has to go through all the numbers once to look for the place number. Insertion sort : Insertion sort starts by comparing the first two elements and then places the smallest one in the correct position. Then it looks at the first 3 elements and puts the smallest one in the correct position relative to the previous numbers. It does this by moving the element on the right to the left until it reaches the correct position. Ex. This is the fastest sorting method of all since it puts a number in its correct position the first time. Any questions mail me at general@teentwo.8m.com Before you can start searching for something all the elements has to be sorted. There are two methods of searching namely: If the array of elements you are using is small (1...20) it is faster to use linear searching but when you use a large array (21...1000) it is better to use binary searching. Linear Searching Linear searching starts from the front of the elements and starts comparing all the numbers until the number has been found. Ex. You have to find 5 1 3 5 6 12 15 18 19 25 33 35 39 41 43 Binary Searching Binary Search goes to the middle of all the elements and then checks if the middle element is the correct one if not, it tests if the correct one is smaller or bigger than the middle one. If it is smaller it goes to the middle of the smaller half, if it is bigger it goes to the middle of the bigger half. This process is repeated until the element is found. Ex. You have to find 5 This is a very effective method of searching but unfortunately it only works if all the elements are sorted. Any questions mail me at general@teentwo.8m.com Recursion is a concept. The word recursion is from the verb to recur, wich means to occur again, to repeat. A procedure or function that calls itself is said to be a recursive procedure or function. When you started programming you were probably told not to us a function name with in itself, causing you to rule out any possibility of recursion making it a hard concept to understand. Recursion is used in math quite often ex. n! This description of n! provides a different definition for
each value of n. That is the definition of 2! is 2 * 1, the definition of 3! is 3 * 2 * 1
and so forth. Of course recursion is not limited to math. Computer languages such as Pascal that support recursion gives the programmer a powerful tool to solve certain problems by reducing it's complexity. When writing a recursive procedure or function there are 2
rules to keep by... Any questions mail me at general@teentwo.8m.com |
|
This page is best viewed in 800x600x256. This page was last edited Tuesday, June 27, 2000 |