Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is N in this given scenario

I am trying to implement this code and this website has kindly provided their algorithm but I am trying to Find out what is "N" I understood what "I" and "M" is but not "N", is "N" the Total input(in the below example 5 because there are 5 letters)?

Algorithm:

Combinations are generated in lexicographical order. The algorithm uses indexes of the elements of the set. Here is how it works on example: Suppose we have a set of 5 elements with indexes 1 2 3 4 5 (starting from 1), and we need to generate all combinations of size m
= 3.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

First, we initialize the first combination of size m – with indexes in ascending order

1 2 3

Then we check the last element (i = 3). If its value is less than n – m + i, it is incremented by 1.

1 2 4

Again we check the last element, and since it is still less than n – m

  • i, it is incremented by 1.

1 2 5

Now it has the maximum allowed value: n – m + i = 5 – 3 + 3 = 5, so we move on to the previous element (i = 2).

If its value less than n – m + i, it is incremented by 1, and all following elements are set to value of their previous neighbor plus 1

1 (2+1)3 (3+1)4 = 1 3 4

Then we again start from the last element i = 3

1 3 5

Back to i = 2

1 4 5

Now it finally equals n – m + i = 5 – 3 + 2 = 4, so we can move to first element (i = 1) (1+1)2 (2+1)3 (3+1)4 = 2 3 4

And then,

2 3 5

2 4 5

3 4 5

  • and it is the last combination since all values are set to the maximum possible value of n – m + i.

Input:
A
B
C
D
E

Output:

A B C

A B D

A B E

A C D

A C E

A D E

B C D

B C E

B D E

C D E

>Solution :

Take a look at the very first paragraf of the link you provided.

It states that

This combinations calculator generates all possible combinations of m elements from the set of n elements.

So yes, n is the number of elements or letters that the algorithm needs to use.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading