Quick Elementary Combinatorics Question / Verification

There are 834,906,933 possible 5 character variable names, 848,373,173 possible variable names with length at most 5, and 217,141 possible variable names with the desired property.
  • #1
tylerc1991
166
0

Homework Statement



I am using a book that doesn't have any solutions in it, so I would like to be sure that I am doing the problems right before I move on. The question is below:

In a programming language, a variable name must start with a letter or the underscore character, and succeeding characters must be letters, digits, or the underscore character. Uppercase and lowercase letters are considered different.
(a) How many variable names with exactly 5 characters can be formed?
(b) How many are there with at most 5 characters?
(c) How many are there with at most 5 characters, if they must read the same forwards and backwards? (note that kayak is acceptable but Kayak is not).

The Attempt at a Solution


(a) There are 53 possible characters for the first position, and 63 possibilities for the remaining 4 positions. So there are
[itex]53 \cdot 63^4 = 834,906,933[/itex]
possible 5 character variable names.

(b) For some [itex]k[/itex], there are [itex]53 \cdot 63^{k-1}[/itex] possible variable names of length [itex]k[/itex]. So the number of possible variable names with length at most 5 is
[itex]\sum_{k=1}^5 53 \cdot 63^{k-1} = 848,373,173[/itex] possible variable names with length at most 5.

(c) For length 1, there are only 53 such possible variable names. For length 2, the first and last characters must be the same, so there are again only 53 such possible variable names. For length 3, there are 53 * 63 variable names, and the same number of variable names of length 4. For length 5, there are 53 * 63 * 63 possible variable names. Hence, there are
[itex]53 + 53 + 53 \cdot 63 + 53 \cdot 63 + 53 \cdot 63^2 = 217,141[/itex]
possible variable names with the desired property.

Thanks!
 
Physics news on Phys.org
  • #2
tylerc1991 said:

Homework Statement



I am using a book that doesn't have any solutions in it, so I would like to be sure that I am doing the problems right before I move on. The question is below:

In a programming language, a variable name must start with a letter or the underscore character, and succeeding characters must be letters, digits, or the underscore character. Uppercase and lowercase letters are considered different.
(a) How many variable names with exactly 5 characters can be formed?
(b) How many are there with at most 5 characters?
(c) How many are there with at most 5 characters, if they must read the same forwards and backwards? (note that kayak is acceptable but Kayak is not).

The Attempt at a Solution


(a) There are 53 possible characters for the first position, and 63 possibilities for the remaining 4 positions. So there are
[itex]53 \cdot 63^4 = 834,906,933[/itex]
possible 5 character variable names.

(b) For some [itex]k[/itex], there are [itex]53 \cdot 63^{k-1}[/itex] possible variable names of length [itex]k[/itex]. So the number of possible variable names with length at most 5 is
[itex]\sum_{k=1}^5 53 \cdot 63^{k-1} = 848,373,173[/itex] possible variable names with length at most 5.

(c) For length 1, there are only 53 such possible variable names. For length 2, the first and last characters must be the same, so there are again only 53 such possible variable names. For length 3, there are 53 * 63 variable names, and the same number of variable names of length 4. For length 5, there are 53 * 63 * 63 possible variable names. Hence, there are
[itex]53 + 53 + 53 \cdot 63 + 53 \cdot 63 + 53 \cdot 63^2 = 217,141[/itex]
possible variable names with the desired property.

Thanks!

Your calculations look correct to me.
 

FAQ: Quick Elementary Combinatorics Question / Verification

What is combinatorics?

Combinatorics is a branch of mathematics that deals with the study of counting and arranging objects or sets of objects in various ways.

What is the purpose of this type of question?

The purpose of a quick elementary combinatorics question is to test a person's ability to apply basic counting principles to solve a problem.

How do I approach solving a combinatorics question?

The first step in solving a combinatorics question is to identify the type of problem (e.g. permutation, combination, etc.) and then apply the appropriate counting principle (e.g. factorial, nCr, etc.) to determine the total number of possible outcomes.

Can you provide an example of a combinatorics question?

Sure, here's an example: In a group of 10 students, how many ways can we choose a team of 3 students to participate in a science fair project? The answer would be 10 choose 3, or 10C3, which equals 120 possible combinations.

How can I verify my answer for a combinatorics question?

You can verify your answer by using a different counting principle or by testing your solution with a smaller, simpler problem. Additionally, you can use a calculator or online tool to check your calculations.

Similar threads

Replies
9
Views
2K
Replies
2
Views
4K
Replies
7
Views
2K
Replies
1
Views
1K
Replies
1
Views
2K
Replies
3
Views
2K
Back
Top