top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is binary tree and how is it different then other trees?

+2 votes
384 views
What is binary tree and how is it different then other trees?
posted Dec 8, 2015 by Shishir Chaudhary

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Lets understand what is Tree Data Structure first as it it important to know what is tree to know what is binary Tree -

Tree is a graph without any loop/circuit, where we have exactly one way to connect two nodes. In the implementation form a tree is a abstract data type (ADT) that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes. Following are the tree terminology -
Root – The top node in a tree.
Parent – The converse notion of a child.
Siblings – Nodes with the same parent.
Descendant – A node reachable by repeated proceeding from parent to child.
Ancestor – A node reachable by repeated proceeding from child to parent.
Leaf – A node with no children.
Internal node – A node with at least one child.
External node – A node with no children.
Degree – Number of sub trees of a node.
Edge – Connection between one node to another.
Path – A sequence of nodes and edges connecting a node with a descendant.
Level – The level of a node is defined by 1 + (the number of connections between the node and the root).
Height of node – The height of a node is the number of edges on the longest downward path between that node and a leaf.
Height of tree – The height of a tree is the height of its root node.
Depth – The depth of a node is the number of edges from the node to the tree's root node.
Forest – A forest is a set of n ≥ 0 disjoint trees.

Now coming to the Binary Tree -
A tree is called Binary tree when any node can have max two child (node). Example

Binary Tree

answer Dec 8, 2015 by Salil Agrawal
Similar Questions
+3 votes

Given a binary tree print it in inward spiral order i.e first print level 1, then level n, then level 2, then n-1 and so on.

For Ex -

         1 
   2           3 
 4    5       6     7 
8 9  10 11  12 13  14 15 

Print- 1 15 14 13 12 11 10 9 8 2 3 7 6 5 4

+1 vote

This was asked today at Amazon interview -

Given two Binary Trees (not BST). Each node of both trees has an integer value. Validate whether both trees have the same integers, there could be repetitive integers.

Example
Tree1:
5
1 6
5 4 3 6

Tree2:
1
3 4
6 5

Output
Identical integers

Sample C/C++/Java code would be helpful.

...