1
00:00:00,570 --> 00:00:07,770
Let's now go ahead and discuss the pseudocode for the recursive approach that we have just now discussed

2
00:00:07,770 --> 00:00:09,150
in the previous video.

3
00:00:09,150 --> 00:00:11,670
So we would need to write a function.

4
00:00:11,670 --> 00:00:14,340
And this function will have some inputs.

5
00:00:14,340 --> 00:00:19,980
And inside this function we would have to write the base case and the recursive case.

6
00:00:19,980 --> 00:00:24,030
Now we have already discussed the three possibilities for the base case.

7
00:00:24,030 --> 00:00:31,230
Now when it comes to these inputs over here we'll need two indices index one, which can be used as

8
00:00:31,230 --> 00:00:35,070
a pointer to iterate over the characters in word one.

9
00:00:35,070 --> 00:00:40,560
And let's say we are using index two to iterate over the characters in word two.

10
00:00:40,590 --> 00:00:43,710
Now in the base case, we have three possibilities.

11
00:00:43,710 --> 00:00:51,510
So if both of these become greater than the last valid indices in word one and word two together, then

12
00:00:51,510 --> 00:00:58,020
we can just return zero, or if only one of them is greater than the last valid index, and there are

13
00:00:58,020 --> 00:01:04,680
still valid characters in the other word, then we would have to return the number of remaining characters.

14
00:01:07,670 --> 00:01:08,990
In the other word.

15
00:01:09,440 --> 00:01:12,290
So we have discussed this in the previous video.

16
00:01:12,290 --> 00:01:18,290
And when it comes to the choice diagram, we have discussed that there are two possibilities at a high

17
00:01:18,290 --> 00:01:18,860
level.

18
00:01:18,860 --> 00:01:27,230
One is that we find that the characters at index one and index two in word one and word two, respectively,

19
00:01:27,230 --> 00:01:28,190
are equal.

20
00:01:28,190 --> 00:01:32,930
And the other possibility is that we see that the two characters are not equal.

21
00:01:32,930 --> 00:01:38,360
Now, if they are equal, we don't need to do any operations, and we can just find the number of operations

22
00:01:38,360 --> 00:01:43,460
required for the remaining parts of word one and word two, respectively.

23
00:01:43,460 --> 00:01:48,920
Now, if they are not equal, we have discussed that there are three possibilities insert, delete and

24
00:01:48,920 --> 00:01:49,610
replace.

25
00:01:49,610 --> 00:01:56,450
Now we have seen how to move the indices index one and index two in these three cases in the previous

26
00:01:56,450 --> 00:01:56,990
video.

27
00:01:56,990 --> 00:02:00,560
So for each of these we would have to find the answer.

28
00:02:00,560 --> 00:02:02,660
So insert would be one plus.

29
00:02:02,660 --> 00:02:06,440
Again recursively calling the function with the respective indices.

30
00:02:06,440 --> 00:02:08,360
As we have discussed in the previous video.

31
00:02:08,360 --> 00:02:11,990
And we would have to do the same thing for delete and replace.

32
00:02:11,990 --> 00:02:17,930
And then we would have to return the minimum among these three values that we get.

33
00:02:17,930 --> 00:02:22,100
So this is how we will recursively solve this question.

34
00:02:22,100 --> 00:02:25,520
And this is the pseudocode for the approach that we have discussed.
