You are not logged in. Please login at to post your questions!


ENIGMA09 - Editorial



Author and Editorialist: Shubham Chauhan




Modulo Arithmetic , Tree


Problem Naturally can be transformed to a more formal way : How many vertices will a trie contain if we add all possible strings with length 2 * N with equal number of zeroes and ones to it. So first of all, it is obvious that upper half of this tree would be a full binary tree. Lets take a look on N = 3: level (0 - 1) vertex, level (1 - 2) vertices , level (2 - 4) vertices, level (3 - 8) vertices.

Starting from Nth level not every vertex will duplicate: only those that haven’t spent their 0’s or 1’s will.
So here is how to calculate how may vertices will be there on level i + 1 :
1. Lets assign Number of non duplicating vertices from level to PD(i) .
2. Count(i + 1) = PD(i) + (Count(i) - PD(i))*2.
3. And PD can be calculated pretty easily with binomial coefficients: PD(i) = 2 * C(i , N)
4. Everything else is implementation techniques: inverse modulo arithmetics + some fast way to calculate C(i , N) and sum counts


To be Update Soon

This question is marked "community wiki".

asked 16 Oct '15, 21:58

sumit.asr_128's gravatar image

accept rate: 10%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 16 Oct '15, 21:58

question was seen: 612 times

last updated: 16 Oct '15, 21:58