# Algorithm to identify differences between two sorted data sets

PROBLEM STATEMENT: Print the items that differ between the following two left and right sorted data sets:

``````A       A
B       C
C       D
D       E
G       F
H       EOF
EOF
``````

The proposed solution should print:

``````B E F G H
``````

Here is my data-driven implementation of this algorithm in pseudo-code. It appears to produce the desired results so my questions are:

• Are there any flaws in terms of logic, efficiency or anything else using this approach?
• Would this approach be called a data-driven design or would it be categorized under a different name?

Here is the pseudo-code:

``````METHOD PRINT_DIFFERENCES

WHILE LEFT_DATA_NOT_EOF AND RIGHT_DATA_NOT_EOF
WHILE LEFT_DATA_NOT_EOF AND RIGHT_DATA_NOT_EOF AND LEFT_KEY IS LESS THAN RIGHT_KEY
PRINT LEFT_KEY
LOOP

WHILE LEFT_DATA_NOT_EOF AND RIGHT_DATA_NOT_EOF AND RIGHT_KEY IS LESS THAN LEFT_KEY
PRINT RIGHT_KEY
LOOP

WHILE LEFT_DATA_NOT_EOF AND RIGHT_DATA_NOT_EOF AND LEFT_KEY IS EQUAL TO RIGHT_KEY
LOOP
LOOP

WHILE LEFT_DATA_NOT_EOF
PRINT LEFT_KEY
LOOP

WHILE RIGHT_DATA_NOT_EOF
PRINT RIGHT_KEY
LOOP
METHOD END

RESULT = MOVE TO NEXT LEFT RECORD

IF RESULT IS EQUAL TO TRUE THEN
SET LEFT_KEY FROM CURRENT LEFT CURSOR
END IF

RETURN RESULT
METHOD END

RESULT = MOVE TO NEXT RIGHT RECORD

IF RESULT IS EQUAL TO TRUE THEN
SET RIGHT_KEY FROM CURRENT RIGHT CURSOR
END IF

RETURN RESULT
METHOD END
``````
• that "pseudo code" really hurt the eyes Commented Oct 27, 2017 at 14:20
• A pseudo code is supposed to be easier to read than actual code .. right ? Commented Oct 27, 2017 at 14:27

I would simplify

``````WHILE LEFT_DATA_NOT_EOF AND RIGHT_DATA_NOT_EOF
IF LEFT_KEY IS LESS THAN RIGHT_KEY
PRINT LEFT_KEY

ELSE IF RIGHT_KEY IS LESS THAN LEFT_KEY
PRINT RIGHT_KEY

ELSE