edited by
29,808 views
93 93 votes
The number of $4$ digit numbers having their digits in non-decreasing order (from left to right) constructed by using the digits belonging to the set $\{1, 2, 3\}$ is ________.

19 Answers

Best answer
121 121 votes
We can arrive at a solution by constructing a graph for each starting digit. For example root $3$ means - starting with $3$ it can have $3$ children $1,2,3$ and the construction goes.

$3$ can have three children $1, 2,3$

$2$ can have two children $1, 2$

$1$ can have only $1$ as child.

Graph need to be done till four levels as we need $4$ digits and we have $3$ such graphs starting with $3$, $2$ and $1.$
And finally count the total number of leaves of all the graphs gives our answer as $15.$
selected by
83 83 votes

Dynamic Programming Approach

$$\begin{array}{|c|c|c|c|c|} \hline \textbf{} &  \textbf{1 digit}& \textbf{2 digits} & \textbf{3 digits} & \textbf{4 digits} \\\hline \textbf{Starting 3} & 1 & 1 & 1 & 1  \\\hline \textbf{Starting 2} & 1 & 2 & 3 & 4 \\\hline \textbf{Starting 1} & 1 & 3 & 6 & 10 \\\hline \end{array}$$

Here Starting $1$ means numbers starting with $1$. And cell $(i, j)$ is for number of numbers starting with $i$ and having $j$ digits. We can have the relation $$ c(i, j) = \Sigma_{k=1}^i c(k, j-1)$$ as per the non-decreasing condition given in the question. So, our answer will be $$c(1,4) + c(2, 4) + c(3, 4) = 1 + 4 + 10 = 15$$


Brute force

  • 3 3 3 3
  • 2 2 2 2
  • 2 2 2 3 
  • 2 2 3 3
  • 2 3 3 3
  • 1 1 1 1
  • 1 1 1 2
  • 1 1 1 3
  • 1 1 2 2
  • 1 1 2 3
  • 1 1 3 3
  • 1 2 2 2
  • 1 2 2 3
  • 1 2 3 3
  • 1 3 3 3
edited by
47 47 votes
We can form a 4 digit number by selecting $x_1$ 1s, $x_2$ 2s and $x_3$ 3s. Then $x_1 + x_2 + x_3 = 4$. The number of solutions of this equation is $\binom{6}{2} = 15$. Each such solution can be arranged in non-decreasing order. Hence the answer is 15.
34 34 votes

In such question where at each step choices get ruled out and set is small better to use tree method.

The four digit number is $d_1d_2d_3d_4$ and we start by making a tree rooted by $d_4$. This number can be any of the number from {1,2,3}.

Then, based on $d_4$ we construct the next level of tree what next nodes can it connect to so that we won't break the property of the digits such that they are non-decreasing. Have a look at trees.

The tree is not built fully for the cases where we break the non-decreasing property like in above tree when $d_3$ is 2 or 3 we didn't continue to build that tree. So, we won't count those cases.

 


 

Finally in all three trees count the number of leaf nodes which are at a height of 3 and thus our 4 digited number maintaining the non-decreasing property.

so total such  numbers are 1+4+10=15

11 11 votes
This problem is same as the number of ways to select 4 numbers from $\{1,2,3\}$ where repetition is allowed. Because, if we select one such sequence of numbers, there will be only 1 way to arrange these numbers in non-decreasing order.
Answer is: C(4+3-1, 3) = C(6, 2) = 15
8 8 votes

I have got a simple solution, Draw n trees, for n nodes, and the child of the tree is either equal to its parent or greater than the parent. Each node can have maximum n children. Count the no. of leaf nodes. The ith level represents ith position in the number. Here answer is 15.

Answer:
Position:
Show:

Related questions

51 51 votes
8 answers 8 answers
17.2k
17.2k views
Kathleen asked Sep 14, 2014
17,235 views
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it, counting repetiti...
43 43 votes
6 answers 6 answers
16.8k
16.8k views
Kathleen asked Sep 23, 2014
16,777 views
The number of binary strings of $n$ zeros and $k$ ones in which no two ones are adjacent is$^{n-1}C_k$$^nC_k$$^nC_{k+1}$None of the above
51 51 votes
6 answers 6 answers
13.5k
13.5k views
Misbah Ghaya asked Nov 29, 2016
13,463 views
How many substrings (of all lengths inclusive) can be formed from a character string of length $n$? Assume all characters to be distinct, prove your answer.
68 68 votes
5 answers 5 answers
20.5k
20.5k views
go_editor asked Feb 16, 2015
20,525 views
Consider the following C program:#include<stdio.h int f1(void); int f2(void); int f3(void); int x=10; int main() { int x=1; x += f1() + f2 () + f3() + f2(); printf("%d", ...