A programmer wants to install a software library named software library number . However, to make library work, he needs library and library first, but library depends on library , and so on.
The following dependency diagram depicts this situation:
One way to install all the libraries might be
1 2 3 4 5 6 7 8 9 10
. But,
1 4 5 2 3 6 9 7 8 10
is also a valid sequence. However,
1 3 2 4 5 6 7 8 9 10
is not, since library
cannot be installed before
2
.
What is the total number of possible valid sequences?
This problem is a part of Tessellate S.T.E.M.S.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let's write all the nodes in the dependency diagram in a linear manner, just to make it easier for analyzing:-
1_ _ _ _ 6 _ _ _ 10 where 1,2,3..... are the library numbers.
Now, since library-1 will always be installed at the very beginning, we fix it's place in the sequence (as shown above). Similarly, library-6 will always be installed after installing the first 5 libraries no matter the sequence. So we fix it's position (as shown). We do the same for library-10 as well, since it will always be installed right at the end.
Now, considering libraries between 1 and 6 - we can observe that the second library to be installed can never be 3 or 5, so we eliminate all the sequences where 3 or 5 is the second library installed. Listing out the possible sequences of libraries where library-4 was installed second:
Here we notice that only (A), (B) and (E) are possible i.e half of the possible sequences. Similarly, only half of all sequences are possible in the case where library-2 is installed second. Total = 6 sequences.
Considering libraries between 6 and 10 and listing out all the possible sequences independently of the order of first 6 libraries:
Only (C), (E) and (F) are possible. Total = 3 sequences.
Combining, we get a total of 6 * 3= 18 total possible sequences in which the library-10 can be installed.