Data Structures & Algorithms Multiple Choice Questions on “Generating Partitions”.
1. What is meant by integer partition? Answer: c 2. How many partitions will be formed for the integer 3? Answer: b 3. What is meant by number theory? Answer: a 4. Which of the following is true according to Ramanujan’s congruence? Answer: b 5. The no. of partitions of which of the following integer will be divisible by 5? Answer: c 6. What is the output of the following code? a) b) c) d) Answer: d 7. While generating partitions of integer 3 we consider 2 1 and 1 2 to be different partitions. Answer: b 8. What is the approach implemented in the following code? a) greedy approach 9. What will be the output of the following code? a) b) c) d) Answer: a 10. Which of the following correctly represents the code to print partitions of a number? b) c) d) Answer: a
a) representing an integer as sum of positive and negative real numbers
b) representing an integer as sum of positive and negative integers
c) representing an integer as sum of positive integers
d) representing an integer as sum of positive real numbers
Clarification: Integer partition is the way of representing an integer as sum of positive integers. Partitions differing only in their order are considered to be same.
a) 2
b) 3
c) 4
d) 8
Clarification: We need to find the combinations of positive integers which give 3 as their sum. These will be {3}, {2,1}, {1,1,1}. Thus the correct answer is 3.
a) study of integers
b) study of complex numbers
c) numerology
d) theory of origination of mathematics
Clarification: Number theory is a branch of mathematics that deals with the study of integers. Partitioning of a number comes under the study of number theory.
a) No. of partitions are divisible by 5 for a number 3 more than a multiple of 5
b) No. of partitions are divisible by 5 for a number 4 more than a multiple of 5
c) No. of partitions are divisible by 5 for a number 2 more than a multiple of 5
d) No. of partitions are divisible by 5 for a number 1 more than a multiple of 5
Clarification: Ramanujan’s congruence are some relations found for the no. of partitions of an integer. According to it, the number of partitions of an integer is divisible by 5 if that integer is 4 more than a multiple of 5.
a) 3
b) 5
c) 9
d) 6
Clarification: According to Ramanujan’s congruence number of partitions of an integer is divisible by 5 if that integer is 4 more than a multiple of 5. So out of the given options 9 is the only integer which satisfies this condition.#include
3
1 2
1 1 1
1 1 1
2 1
3
1 1 1
1 2
3
3
2 1
1 1 1
Clarification: The given code prints the partition of a number in decreasing order. This code uses the approach of dynamic programming.
a) true
b) false
Clarification: Partitions differing in order are considered to be same. Thus 2 1 and 1 2 are considered to be same when we generate partitions of integer 3.#include
b) dynamic programming
c) recursion(divide and conquer)
d) backtracking
Answer: b
Clarification: The given code prints the partition of a number in decreasing order. This code uses the approach of dynamic programming. We can also use recursion for fulfilling the same purpose.#include
3
2 1
1 1 1
1 1 1
2 1
3
1 1 1
1 2
3
3
1 2
1 1 1
Clarification: The given code prints the partition of a number in decreasing order. This code uses the approach of recursion. The same purpose can be fulfilled by using dynamic programming.
a)#include
#include
#include
#include
Clarification: In the correct code we need to pass n as second argument in the function partitn() and need to check for the condition i>n. The code prints the partitions in decreasing order.