ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
Find the largest number in a binary tree
 Question Submitted By :: Guyav
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Find the largest number in a binary tree
Answer
# 1
Well..it's not a binary search tree.So we need to traverse
entire binary tree and check with the all node elements and
find the max value.
struct node
{
int data;
struct node *l;
struct node *r;
};
typedef struct node *nd;
int maximum(nd root)
{
static int max;
nd cur = root;
if(cur!=NULL)
{
if(cur->data>max)
max=cur->data;
maximum(root->l);
maximum(root->r);
}
return max;
}

 
Is This Answer Correct ?    2 Yes 0 No
Guest
 
  Re: Find the largest number in a binary tree
Answer
# 2
Well..it's not a binary search tree.So we need to traverse
entire binary tree and check with the all node elements and
find the max value.
struct node
{
int data;
struct node *l;
struct node *r;
};
typedef struct node *nd;
int maximum(nd root)
{
static int max;
nd cur = root;
if(cur!=NULL)
{
if(cur->data>max)
max=cur->data;
maximum(root->l);
maximum(root->r);
}
return max;
}
 
Is This Answer Correct ?    0 Yes 0 No
Raghuram.A
 
 
 
  Re: Find the largest number in a binary tree
Answer
# 3
3333598209374158490386452138699.3
 
Is This Answer Correct ?    1 Yes 0 No
Guest
 
  Re: Find the largest number in a binary tree
Answer
# 4
The Largest Node in the Binary tree is the Rightmost node 
of the tree.
Hence we would traverse the Tree Till The Rightmost child 
of the node is traversed.

the code is as follows:


#include<stdio.h>
#include<conio.h>

struct node
{
  int data;
  struct node *left,*right;
}*tree;

struct node* MAX(struct node* q)
{ 
    struct node* temp;  
 while(q->right!=NULL)
    {
       temp=q;
        q=q->right;
     }
 return temp;
}


this algorithm will find the largest element of the tree in 
o(log n).
 
Is This Answer Correct ?    0 Yes 0 No
Bharat Pandey
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw... Oracle3
how can u draw a rectangle in C Wipro24
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18. Infosys3
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD Synergy6
program to find the roots of a quadratic equation  1
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable. Microsoft4
plz send me all data structure related programs  2
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. Microsoft2
write the function. if all the character in string B appear in string A, return true, otherwise return false. Google7
Finding a number which was log of base 2 NetApp1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
plz send me all data structure related programs  1
Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique. Microsoft3
Write a function to find the depth of a binary tree. Adobe4
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Wipro2
How do you write a program which produces its own source code as its output?  4
Link list in reverse order. NetApp7
program to Reverse a linked list Ness-Technologies3
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.  2
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com