8
$\begingroup$

I'm working on a programming algorithm and need a little math help. I'm in 10th grade and I think the question I'm asking is actually a permutation and combination logic question. Okay, so I've 62 characters as follows:

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

I want to know how many unique characters can be made from this? For example, for length 1 character, there could be 62 unique characters. Length 2 character, there could be 00,01,02,03....AA,AB,AC...FA,FB,FC,FD...ZA,ZB,ZC...0A,0B,0C...,etc.

I hope you are getting me what I'm trying to say. And the maximum length of the string should be 7 characters.

So, in total, how many unique random strings can be generated from these 62 characters!?

$\endgroup$

1 Answer 1

10
$\begingroup$

Using $n$ unique characters, there are exactly $n^k$ strings of length $k$.

Think of it this way:

You have $n$ choices for the first character, $n$ for the second one... $n$ for the $k$-th one.

So the amount of options is

$$\underbrace{n·n·n\ldots n}_{k\text{ times}} = n^k$$

If you want to know the amount of strings with $n$ unique characters with length up to $k$ then you need to add:

$$n^1 + n^2 + n^3 + ... + n^k = \frac{n^{k+1}-n}{n-1}$$

$\endgroup$
3
  • $\begingroup$ That means 62^7? $\endgroup$
    – mehulmpt
    Aug 15, 2014 at 13:11
  • $\begingroup$ @MehulMohan there are exaclty $62^7$ strings with exactly length $7$, but if you want to include those with length $1, 2,3,4,5$ and &6& you have to add them up. Check my edit for a simpler way to compute it. $\endgroup$
    – Darth Geek
    Aug 15, 2014 at 13:16
  • 1
    $\begingroup$ Genius! Thanks bro! $\endgroup$
    – mehulmpt
    Aug 15, 2014 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .