1
00:00:00,430 --> 00:00:07,990
In this video, let's compare the pseudocode that we have over here with the backtracking blueprint

2
00:00:07,990 --> 00:00:10,030
that we had previously discussed.

3
00:00:10,030 --> 00:00:13,570
So notice over here we have the base condition.

4
00:00:13,570 --> 00:00:15,370
And that's what we have over here.

5
00:00:15,370 --> 00:00:24,010
If I is equal to length of the array which is given to us, then push that particular instance of the

6
00:00:24,010 --> 00:00:28,270
current uh array into the results array and then return.

7
00:00:28,270 --> 00:00:31,150
So that's our base condition, which is what we have over here.

8
00:00:31,390 --> 00:00:36,730
And then notice that over here we have for choice in choices.

9
00:00:36,730 --> 00:00:39,190
And we were doing this for each choice.

10
00:00:39,190 --> 00:00:46,870
But over here in this pseudocode over here we don't need this for loop because there are just two choices

11
00:00:46,870 --> 00:00:49,390
which is exclude and include.

12
00:00:49,390 --> 00:00:49,780
Right.

13
00:00:49,780 --> 00:00:56,500
So over here this part deals with exclude and this part where we push to the current array.

14
00:00:56,500 --> 00:01:00,160
And then uh we call the function recursively.

15
00:01:00,160 --> 00:01:02,740
And later we pop from the array.

16
00:01:02,740 --> 00:01:05,560
So this part over here is the include part.

17
00:01:05,560 --> 00:01:08,920
So we have dealt with this as well from the blueprint.

18
00:01:08,920 --> 00:01:15,490
And then notice over here in this question including or excluding every element is valid.

19
00:01:15,490 --> 00:01:19,420
So there is no need for this is valid check at this point.

20
00:01:19,420 --> 00:01:22,090
So that is not there in the pseudocode over here.

21
00:01:22,090 --> 00:01:27,820
And then finally we have the backtracking step over here which is reverting the choice.

22
00:01:27,820 --> 00:01:33,370
And the choice was to push to the uh current array which would become a subset.

23
00:01:33,370 --> 00:01:39,970
Now the backtracking or reverting the choice is popping that element which we just now included.

24
00:01:40,210 --> 00:01:42,220
For example, node is over here.

25
00:01:42,220 --> 00:01:47,320
Let's say at this point the current array had one as an element in it.

26
00:01:47,320 --> 00:01:52,510
And then we excluded element the next element which is element seven.

27
00:01:52,510 --> 00:01:54,790
And we got a subset which is just one.

28
00:01:54,790 --> 00:01:55,960
And then we return.

29
00:01:55,960 --> 00:02:01,840
We come back to this place and then we include the next element which is seven.

30
00:02:01,840 --> 00:02:05,350
So the current array becomes one seven and later.

31
00:02:05,530 --> 00:02:08,650
Notice over here another subset is one eight.

32
00:02:08,650 --> 00:02:15,790
So whatever we added over here which is seven has to be popped out when we come back so that the array

33
00:02:15,790 --> 00:02:16,570
becomes one.

34
00:02:16,570 --> 00:02:18,400
And then this call returns.

35
00:02:18,400 --> 00:02:24,400
And then we come over here and we are able to add 8 to 1 and it becomes one eight.

36
00:02:24,400 --> 00:02:27,250
And finally from there we come over here and we get this.

37
00:02:27,250 --> 00:02:31,180
So remember that's why because the changes are made in place.

38
00:02:31,180 --> 00:02:37,060
That's why the backtracking step or in this case popping the element that was added is important.
