00:01
All right, so here we have the same algorithm under two conditions.
00:05
The first is that it will not be sorted, but we're looking for finding the closest two numbers, right? which is really just finding the distance between them.
00:16
So i'm going to call this algorithm closest, and we need a list of n real valued numbers.
00:29
And in order to have a distance, we need at least two elements.
00:35
So there must be at least two elements in this list.
00:40
So first, i'm going to initialize some parameters.
00:44
We'll set k equal to 1, the first index.
00:51
Set l equal to 2, the second index.
00:58
And then we're going to set m equal to their distance.
01:11
Okay, so that's just going to be a 2 minus a1.
01:21
And then we want the absolute value of this distance, because distance should be positive.
01:31
So they want to start iterating through every possible pair in this list.
01:37
So we'll have 4i as it runs from 1 to n.
01:47
And then we'll have a nested list.
01:55
So in this case we're going to have, we'll say j.
01:58
This one's going to run from i plus 1.
02:12
To n right and so what's happening here is that we're in i is equal to one it'll be at a sub one and then it's gonna compare a sub one to a a sub two a three four a five a six seven etc and then it's gonna jump to a two and then it'll compare a a sub two to a three eight eight four a five a six all the way okay so this is gonna allow us to compare every pair of them and we want to check their distance okay so we'll say if and with the absolute value here, a subj minus a sub i is less than m.
03:03
Then we will reset k equal to i, l equal to j, and m is now going to be equal to the absolute value of a so j minus a sub i.
03:36
And so this has gone through and made this comparison with every pair of numbers in this list, and then we want to return a sub i and a subjax.
04:01
We are finding the two closest numbers...