Computer
Principles
Computer Principles Courses
The following exercises demonstrate the execution of common algorithm studied in computer principle courses. Animated exercises for sorting algorithms, recursion examples, data manipulation and array based data structures are included. The pseudo code approach provides a clear yet executable set of instructions for the algorithm. The debugger in the model enables the student "watch" the algorithm at work in terms of variable value and output.
Recursion
Example
Recursion, the concept of a method invoking itself until reaching a base case, is particularly demonstrable in graphics. This exercise diagrams a set on concentric circles with random color bands. The MakeCircle recursive method continually calls itself with a new diameter, until the diameter reaches a minimum width. Students can change the size of the inside circle, increase the band width and give band color a hue of a primary color (versus being completely randomly chosen). The MakeCircle method highlights the two key parts of a recursive function - the recursive call and the base case.
Selection Sort
Animation 1
This exercise implements the selection sort (or min-max) algorithm for ordering numbers. The exercise has a PopulateArray function to create the data set to be sorted. The main function contains the nested for loops, the hall mark of the algorithm. In addition to performing the sort itself, the model identifies the min value and shows its movement with the index of the data array being considered. The animation gives a clear vision of how the algorithm works by watching the values move within in-place sort. Students can modify the model by increasing the dataset size or changing the range of numbers in the population set. Also, changing the model to sort in decreasing order is a good challenge to explore.
Selection Sort
Animation 2
This exercise implements the selection sort (or min-max) algorithm and displays the current data set after each pass. The sort is an in-place sort and its progress can be seen through analyzing consecutive rows show the values of the array after a pass. The index of the data element is each pass is highlighted. Students can change the algorithm to sort in decreasing order and also modify the coloring and animation of the output. Counts of comparisons can be added, if the lesson also involved comparing the efficiency of the sort versus other algorithms (e.g. quick-sort, bubble sort).
Encryption
This exercise demonstrates the Caesar Cypher encryption approach of offsetting the message by a prescribed set of letters. The model shows how each letter is converted to a number, the offset added and then re-coded back to a character. The process only involves encryption at this time. Several modifications and enhancements can be made including altering the offset and performing decryption. The model also presently does not account for wrapping to the letter A after moving past letter Z. A fun use of the model is have students enter their names as input and see the result encryption, or decryption. The worksheet provides additional information and questions.
List Processing
Number Frequency
One design technique using array is "frequency arrays" . These arrays hold frequencies of values based on the array index. The index 1 may hold the number of occurrences in of the value of 1 in the underlying dataset. The concept is similar to a hash map, though the array does hold a particular value ( of a key value pair) , but rather just the number of occurrences of the key. It is a great exercise to begin the studies of key and their distribution.
Students can change the number of values in the array and the range of number in the underlying dataset. An advanced form of the problem would be a mapping of ranges of values to a particular index.
List Processing
Searching a List
This exercise demonstrates how to search an array and count the occurrences of a target value. The data array, named mylist, is first populated by random numbers from 1 to 10. A for loop is then used to access each element and count the number of matches with the target value. Alternatives to the problem include making the search be a function that returns true or false if the target value exists in the array.
Students can change the size of the data array (mylist), and alter the target value. The model can also use a binary sort. After populating the array, use mylist.sort() to sort the array. This will then allow the binary search approach to be valid. Students can employ counters to show the savings of using the binary search.