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 ?    4 Yes 3 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 4 No
Raghuram.A
 
 
 
  Re: Find the largest number in a binary tree
Answer
# 3
3333598209374158490386452138699.3
 
Is This Answer Correct ?    3 Yes 2 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 ?    2 Yes 6 No
Bharat Pandey
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { int i=400,j=300; printf("%d..%d"); }  1
main() { int i = 257; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }  1
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }  1
main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4 HCL1
main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }  1
# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }  1
main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }  1
void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above HCL1
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }  1
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }  1
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }  1
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }  1
main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }  1
Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9). Microsoft10
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0 HCL1
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }  1
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }  1
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }  1
main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }  1
Printf can be implemented by using __________ list.  1
 
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