ASU Interview Question for Accountants


Country: United States




Comment hidden because of low score. Click to expand.
2
of 4 vote

use BFS. That is. As we put node into queue, we count the number of items. Once we remove items from queue and inserts it's child, we are reaching the next level. first level we have 1 node, second level, 2, and then 4 and so on. There should be 2^i items at each level where i is the ith level.

- hiuhchan April 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Each node of the tree should have same height of it's left and right subtree. That solves it. If not true the method returns -1.

public int preOrder(Node root){
	if(root==null){
		return 0;
	}
	int lHeight = preOrder(root.getLChild());
	if(lHeight == -1){
		return -1;
	}
	int rHeight = preOrder(root.getRChild());
	if(rHeight == -1){
		return -1;
	}
	if(lHeight!=rHeight){
		return -1;
	}
	return lHeight + 1;
}

- s100banerjee May 01, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Number of nodes in the binary tree is 2^n-1. So just count the number of nodes in the binary tree, and return true if the count is equal to 2^n-1. where n is the height

- Raj May 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

that is great exept I have no idea what is n (n equals to..?). all I have is the tree root.

- Patrick May 08, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

n is number of nodes in the tree

int height(Tree n)
{
  if n == null return 0;
  return max(height(n.left), height(n.right)) + 1;
}

int count(Tree n)
{
  if n == null return 0;
  return count(n.left) + count(n.right)) + 1;
}

bool isFullTree(Tree t)
{
  int h = height(t);
  int count = count(t);
 return 2^h -1 == count

}

- pc May 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

This logic should work:

bool isBinaryCompleteTree(Node* root){
	if(root == NULL) return false;
	if(1 && root->left == 1 && root->right)
		return true;
	return (isBinaryCompleteTree(root->left) && isBinaryCompleteTree(root->right));
}

- Hars Vardhan May 01, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More