Nt1310 Unit 1 Case Study

757 Words2 Pages

1. How many ancestors does a node at level n in a binary tree have? Provide justification.

The definition of a binary tree states that if a tree is not empty, then a root node has two sub trees Tr and Tl, such that Tr and Tl are binary trees. Under this definition, every node, except for the root node, has one parent. Levels of the tree is a measure of distance from the root node, assuming the root node's level is 1, node n's level is 1 plus the level of its parent. Since the root node is level 1 and every node has one parent, the number of ancestors of a node at level n is n-1.

2. Prove that a strictly binary tree (regular binary tree) with n leaves contains 2n-1 nodes. Provide justification.

A strictly binary tree, full binary tree requires …show more content…

Implement inorder traversal for the right in-thread tree in the previous problem.

void sort(int ray[], int start, int end)
{
if(start > end) return; sort(ray, start*2 + 1, end); printf("%d ", ray[start]); sort(ray, start*2 + 2, end);
}
int main()
{
int raySize = sizeof(ray)/sizeof(int); sort(ray, 0, ray_size-1); getchar(); return 0;
}

7. Define the Fibonacci binary tree of order n as follows: If n=0 or n=1, the tree consists of a single node. If n>1, the tree consists of a root, with the Fibonacci tree of order n-1 as the left subtree and the Fibonacci tree of order n-2 as the right subtree. Write a method that builds a Fibonacci binary tree of order n and returns a pointer to it. struct node { int text; struct node *left; struct node *right;
}
typedef struct node *node; node acci(int n)
{
node p = getnode();

if (n == 0 || n == 1) { p->left = NULL; p->right = NULL; } else { p->left = acci(n - 1); p->right = acci(n - 2); } return p;
}

8. Answer the following questions about Fibonacci binary tree defined in the previous

More about Nt1310 Unit 1 Case Study

Open Document