The Advanced part of Pascal is not covered in Cmpe 150 Introduction to Computing. However, as you read sorting , searching, stacks and queues, you will discover that they are not really difficult. For stacks and queues, you may refer to the site of the course Cmpe 250.

Here, you will be given the algorithms for searching techniques, since they could be of major help to you. They are taken form the book "Pascal" by Elliot Koffmann.


Binary Search
 
Algorithm
1. Compute the subscript of the middle element
2. if the array bounds are improper then 
3. return a result of 0.
else if the target is the middle value then
4. return the subscript of the middle element.
else if the target is less than the middle value then
5. Search the subarray with subscripts First..Middle-1
else 
6. Search the subarray with subscripts Middle+1..Last.


Bubble Sort
 
Algorithm
1. repeat
2. for each pair of adjacent array elements do
3. if the values in a pair are out of order then
Exchange the values
until the array is sorted


Insertion Sort
 
Algorithm
1. for each value of NextPos from 2 to N do
begin
2. Save the element at NextPos in NextVal
3. Make room in the sorted subarray (elements 1..NextPos-1) by shifting all values larger than NextVal down one position.
4. Insert NextVal in the original position of the smallest value moved.
end

MergeSort
Recursive Algorithm
1. if First < Last then
begin
2. Set Middle to (First + Last) div 2
3. MergeSort Table [ First .. Middle ]
4. MergeSort Table [ Middle+1 .. Last ]
5. Merge Table [ First .. Middle] with Table [Middle+1 .. Last]
end


QuickSort
Recursive Algorithm
1. if First < Last then
begin
2. Partition the elements in the subarray First..Last so that the pivot value is in place (subscript is PivIndex).
3. Apply QuickSort to the subarray First..PivIndex-1
4. Apply QuickSort to the subarray PivIndex+1..Last
end

A First Look A First Look at Pascal Basic Input/Output Identifiers & Types
Constants Standard Functions If..Then Statement Case Statement
Repetitions Procedures and Functions Enumerated /Subrange Types Sets
I/O, Text Files Arrays Records Recursion
Pointer How to Debug Previous Exam Questions Advanced
ASCII Code Table Homepage University Homepage Computer Engineering Dept.