Bifalgorithm post · Brisk · Chapter 1

How does counting the complement simplify an “at least one” condition?

How does counting the complement simplify an “at least one” condition? (Brisk · Chapter 1) — "Sometimes we have something difficult to count, but we can turn i…

Ideas in this flowchart

  • Le dénombrement par le complément simplifie les problèmes difficiles
  • Méthode générale du dénombrement par complément
  • Compter les éléments qui ne satisfont pas la contrainte
  • Soustraire ce complément du nombre total d’éléments
  • Exemple : dénombrement de mots de passe
  • Les mots de passe ont une longueur de 6 à 10 caractères et chaque caractère peut être une lettre, un chiffre ou un caractère spécial
  • Sans la contrainte supplémentaire, chaque caractère offre 67 choix : 26 lettres majuscules, 26 lettres minuscules, 10 chiffres et 5 caractères spéciaux
  • Nombre total de chaînes : 67¹⁰ + 67⁹ + 67⁸ + 67⁷ + 67⁶ = 1 850 456 557 795 600 384
  • Le complément est constitué des mots de passe de 6 à 10 caractères uniquement alphabétiques
  • Chaque caractère alphabétique offre 52 choix
  • Nombre de mots de passe illégaux : 52¹⁰ + 52⁹ + 52⁸ + 52⁷ + 52⁶ = 147 389 519 403 536 384
  • Nombre de mots de passe légitimes : 1 850 456 557 795 600 384 − 147 389 519 403 536 384 = 1 708 735 865 301 022 720
  • Lorsque les cas conformes sont difficiles à compter, il faut essayer de compter les cas qui ne le sont pas
Feed/

How does counting the complement simplify an “at least one” condition?

Channel

Brisk

1 page

"Sometimes we have something difficult to count, but we can turn it around in terms of something much easier. Often this involves counting the complement of something, then subtracting from the total. Suppose a certain website mandated that user passwords be between 6–10 characters in length—every character being an uppercase letter, lowercase letter, digit, or special character (*, #, @, % or &)—but it also required each password to have at least one digit or special character. Without the “at least one digit or special character” part, there are 26 + 26 + 10 + 5 = 67 different choices for each character, so there are 67¹⁰ + 67⁹ + 67⁸ + 67⁷ + 67⁶ = 1,850,456,557,795,600,384 strings. It is easier to count the passwords that don’t satisfy the extra constraint: strings with 6–10 alphabetic-only characters. That is 52¹⁰ + 52⁹ + 52⁸ + 52⁷ + 52⁶ = 147,389,519,403,536,384 illegal passwords. Now subtract: total number of strings − number of illegal passwords = number of legitimate passwords. Therefore, 1,850,456,557,795,600,384 − 147,389,519,403,536,384 = 1,708,735,865,301,022,720 legitimate passwords. The lesson learned is that if counting the elements in some set involves accounting for a lot of different sticky scenarios, it’s worth a try to count the elements not in the set instead, and see if that’s easier."

Flowchart preview
Series cover
👍
0
0 comments0 shares

Sign in to view and post comments.