Techniques for searching arrays are normally taught during entry level programming classes after the student has had an introduction to language syntax, data types, and control structures (especially looping). While studying these techniques, students learn logical thinking skills and sharpen their sense of creativity. There will be times when a programmer will need to search an entire array to look for specific data, whether it be integer values, floating point values, or character values.
Problems requiring insertion into an array, deletion from an array, finding maximum and minimum values, and simply determining if a value is present require some method of searching. In this article, I introduce two standard methods for searching arrays: a linear search, and a binary search. I will first present a simple problem to be solved by searching, and then show examples of each search method using the C++ and ADA programming languages.
Like array searching techniques, techniques for sorting array data are normally taught during entry level programming classes after control structures have been investigated. Also like search algorithms, sort algorithms require logical thinking and “looping” skills.
It is extremely important for beginning programmers to fully understand these algorithms. The student should never attempt to use an algorithm that he does not actually understand. Fully understanding the algorithm will prevent logic errors and program “bugs”.
There are many problems that may require a programmer to write a function to sort a particular array. Maybe a teacher would like to sort her grade book in descending order based on student term grades to reward her top students. Maybe a bank owner would like to sort a list of accounts in ascending order based on “bounced” check history to reward his reliable clients.
I will present the following four standard sorting techniques: selection sort, bubble sort, merge sort, and tag sort. The tag sort is actually dependent upon a selection or bubble sort. The neat aspect of a tag sort is that it doesn’t actually manipulate array elements. It simply keeps track of a sorted “order” of the elements.
You will see more about this later in the reading. Please note that with minimal changes, these algorithms may be applied to arrays used to store integer, floating-point, and character values. In this article, I will first present a simple sorting problem, and then show examples of each sort method using the C++ and ADA programming languages.