When I view my bank statement, I notice that my expenses are sorted in ascending order by check number. The program that lists this data would have to utilize a sorting algorithm in order to print the expenses in order by check number because there are times when checks are processed out of order. For instance, if two separate checks are mailed to different cities, it is likely that the check going to the closer city would be processed before the other, however it may contain a higher check number. If my bank statement were to print expenses in the order they were processed rather than by check number, it would make it more difficult to find a check by its number.
Initially, I chose the selection sort algorithm to describe how a program might sort the data in a bank statement by check number. After researching, I realized that selection sort may not be the best option. Selection sort works by checking the data for the smallest number and then moving it to the beginning of the data list. After checking the value of the second element, it scans the data list for the next smallest number and swaps it with the second element and moves onto the third element. This process is continued until the data has been sorted (Discussion of Sorting Algorithms, 2006). The advantage of using selection sort is that it is a simple algorithm and relatively easy to implement in comparison to other algorithms (Selection Sort, 2006). Although selection sort is more efficient and faster than the bubble sort algorithm, it is rarely used. Instead, the insertion sort method is often chosen over selection sort (Selection Sort – Definition, 2006).
The insertion sort algorithm is faster and more efficient than bubble sort and is more stable than selection sort. For this reason, the insertion sort algorithm would likely be the better choice for sorting the data in a bank statement ordered by check number (Selection Sort, 2006). Insertion sort works by checking the value of the last two data elements and comparing them then putting them in the correct order. It then moves backwards, checking each element and comparing it to the already ordered list and placing it in the correct order until all of the data is sorted (Discussion of Sorting Algorithms, 2006).
Reference:
Farrell, J. (2006). Programming Logic and Design, Fourth Edition. Thomson Course Technology
Data Structures and Algorithms. Retrieved February 19, 2006 from http://www.cs.auckland.ac.nz/software/AlgAnim/sorting.html#insert_anim
Discussion of Sorting Algorithms. Retrieved February 19, 2006 from http://atschool.eduweb.co.uk/mbaker/sorts.html
Selection Sort. Retrieved February 19, 2006 from http://linux.wku.edu/~lamonml/algor/sort/selection.html
Selection Sort – Definition. February 19, 2006 from http://en.wikipedia.org/wiki/Selection_sort
The logic below represents a program that lists movies in a collection by their director. A new page is created for each director and the total number of movies by each director is calculated. In addition to totals by director, the program provides a grand total of movies in the collection.
In order to create a new page for each director, the program must contain a single-level control break (Farrell, 2006. pp. 265-266). To know when to create a new page, the program must be able to distinguish between the current director and a new director for each record processed. This is achieved by using a control break field (Performing Single-level Control Breaks, 2006). The control break field used in the logic below is previousDirector. During the execution of the houseKeeping() module, the value for the previousDirector field is set to be equal to the value of the movieDirector field. The value is compared to the movieDirector field for each record processed to determine if it is the same or if it has changed. If it has changed, then a new page of movies is created for a new director and the previousDirector field is updated to equal the movieDirector field. The control break field is also required to calculate the total number of movies for each director (Control Break, 2006).
Pseudo-code
start
perform houseKeeping()
while not eof
perform movieListLoop()
endwhile
perform finishUp()
stop
houseKeeping()
declare variables
open files
print heading
read movieRec
previousDirector = movieDirector
return
movieListLoop()
if movieDirector not equal to previousDirector then
perform directorChange()
endif
print movieTitle
directorTotal = directorTotal + 1
read movieRec
return
directorChange()
print “Total movies by director”, directorTotal
grandTotal = grandTotal + directorTotal
directorTotal = 0
previousDirector = movieDirector
return
finishUp()
perform directorChange()
print “Total number of movie titles”, grandTotal
close files
return
Flowcharts

References
Farrell, J. (2006). Programming Logic and Design, Fourth Edition. Thomson Course Technology
Performing Single-level Control Breaks. Retrieved February 18, 2006 from http://www.ccaurora.edu/csc116z/lecture_notes/chapter_7.htm
Control Break. Retrieved February 18, 2006 from http://cs.senecac.on.ca/~tmckenna/RPG544/controlbreak.htm