Quantcast
Channel: convert array to binary tree with recursive strategy - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by trincot for convert array to binary tree with recursive strategy

Given that the input data structure does not guarantee the relationship between parent and children is i*2+1 and i*2+2, a recursive solution is not really called for. The input sequence represents a...

View Article


Answer by ggorlen for convert array to binary tree with recursive strategy

First of all, int a[] = {10,4,7,2,3,-1,8,9,-1,2,4,5}; shouldn't produce the tree you expect, with 5 as the left child of 8. Since 8 is at index 6, its left child would be at index 6 * 2 + 1 == 13. So...

View Article

convert array to binary tree with recursive strategy

I need to create a binary tree starting from vector containing some zeros where a zero represents a node that doesn't exists. for example if I got:int a[] = {10,4,7,2,3,-1,8,9,-1,2,4,5};I would like my...

View Article
Browsing all 3 articles
Browse latest View live