romilshah29
BAN USER1. Init completeLevel to 0
2. Start level order traversal (This can be done either by maintaining a delimeter for each level in the queue or by two queue method.)
3 Initialize a flag - isComplete to true.
4. Check for existence of both children for all nodes of current level
5. Break whenever we find isComplete to be false.
6. At completion of level, switch to next level and increment completeLevel.
Both vectors and deques provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors are very similar to a plain array that grows by reallocating all of its elements in a unique block when its capacity is exhausted, the elements of a deques can be divided in several chunks of storage, with the class keeping all this information and providing a uniform access to the elements. Therefore, deques are a little more complex internally, but this generally allows them to grow more efficiently than the vectors with their capacity managed automatically, specially in large sequences, because massive reallocations are avoided.
So deques can be preferred over vector when the estimated size of data is not clearly known and much reallocation is expected.
When an element is inserted into a deque there is a check for available space for the new entry. If no space is available a chunk of memory is allocated and linking information is added to deque class.
1. Traverse the matrix in row order and calculate the sum of each row.
- romilshah29 July 25, 20122. Create lists of row numbers corresponding to every sum. 0 will have only 1 row, 1 will have n row numbers, and so on. Each of these lists now represent the levels of n-ary tree.
3. Now start with list with sum 0 and create root node. Add all row numbers contained in list sum 1 as children of the root node.
4. Now set root node column to 0 for all rows. So level 2 rows will just have their parent's column set as 1. For all level 2 rows find the only column set as 1 and add current row as a child of that node.
Repeat for all levels.