Can we estimate the upper bound of number of nodes of a trie? I'm using the array based implementation of trie, so i have to declare an array with the highest number of nodes, i know when inserting 32bit numbers the node count cant be greater than (N*32), but the actual upper bound should be way less right? Because for each node there are only two options for the next node? Am I right on this and if i am, can we estimate that value?

Doesn't single insertion require 32 nodes? But for random insertions I don't know the expected value.

I think that this construction is optimal:

Greedy construction for 4 bitsLet's notice that the pattern of counts is $$$2, 2, 4, 8, 16, 32, 64, 128, 256$$$... So the answer is $$$2 * 32 + 2 * 31 + 4 * 30 + 8 * 29$$$... and so on while the sum of coefficients is less than $$$n$$$.

Let's call the group of nodes which are at distance $$$x$$$ from the root 'level $$$x$$$' of the trie. In a binary tree, the number of nodes in level $$$x$$$ of the tree is at most $$$2^x$$$. Furthermore, in a trie, the number of nodes in any level is at most $$$N$$$.

Hence, the maximum number of nodes needed is $$$\sum\limits_{x=0}^{31}min(2^x, N)$$$. For $$$N = 10^6$$$, this number is $$$13048575$$$. I believe it is also possible to construct a trie with this number of nodes. (Construct a complete binary tree of minimal height such that it contains N leaves, then extend each of these leaves in a chain until each leaf is at depth 31. Then assign labels to each edge.)

If you add $$$N$$$ 32bit numbers in bitwise trie, the upper bound equal to $$$2^{\lfloor log(N)\rfloor} + (32 - \lfloor log(N)\rfloor) * N$$$