Skip to content

12. Pseudocode standards

Alex Parry edited this page Oct 2, 2025 · 4 revisions

Pseudocode conventions

We have published a full set of pseudocode conventions which are used throughout the Ada Computer Science platform.

Exemplar code

The following pseudocode is from our Ada Computer Science content page on the binary search algorithm (recursive), which includes a detailed explanation of the algorithm.

FUNCTION binary_search_recursive(items, search_item, first, last)

    // Base case for recursion: The recursion will stop when the
    // index of the first item is greater than the index of last
    IF first > last THEN
        RETURN -1 // Return -1 if the search item is not found

    // Recursively call the function
    ELSE
        // Find the midpoint position (in the middle of the range)
        midpoint = (first + last) DIV 2

        // Compare the item at the midpoint to the search item
        IF items[midpoint] = search_item THEN
            // If the item has been found, return the midpoint position
            RETURN midpoint

        // Check if the item at the midpoint is less than the search item
        ELSEIF search_item > items[midpoint] THEN
            // Focus on the items after the midpoint
            first = midpoint + 1
            RETURN binary_search(items, search_item, first, last)

        // Otherwise the item at the midpoint is greater than the search item
        ELSE
            // Focus on the items before the midpoint
            last = midpoint - 1
            RETURN binary_search(items, search_item, first, last)
        ENDIF
    ENDIF
ENDFUNCTION

Visit our pseudocode convention page for more information about the pseudocode used on Ada CS.

Clone this wiki locally