Key Points from WEEK 4 9/27/2024 Lecture 4. How can you swap the values in two int variables using a temporary variable? Can you get the same result without a temporary variable? 5. Swap the names of two files that have very long file names that are difficult to remember, without recording anything except in the file names themselves. See if you invent the first algorithm using string concatenation and subtraction. Then we will improve it in two more steps. a : goat b : alligator a = a + b = goat + alligator = goatalligator (STORE the alligator with the goat in a) b = a - b = goatalligator - alligator = goat (RECOVER goat into b) a = a - b = goatalligator - goat = alligator (RECOVER alligator into a) a : alligator b : goat -=-=-=- First Improvement: -=-=-=- Extend this idea to numerical addition and subtraction. a : 5 b : 7 a = a + b = 5 + 7 = 12 (STORE the 5 with the 7 in a) b = a - b = 12 - 7 = 5 (RECOVER 5 into b) a = a - b = 12 - 5 = 7 (RECOVER 7 into a) a : 7 b : 5 -=-=-=- Second Improvement -=-=-=- Can you explain why the following algorithm gives the same result? In what way is it better than the previous one that uses addition? a : 101 b : 111 a = a XOR b = 101 XOR 111 = 010 (STORE 101 with 111 in a) b = a XOR b = 010 XOR 111 = 101 (RECOVER 101 into b) a = a XOR b = 010 XOR 101 = 111 (RECOVER 111 into a) a : 111 b : 101 Hint : (a XOR b) XOR b = a XOR (b XOR b) = a XOR 0 = a (RECOVER a)