Re: [algogeeks] Re: TRIE problem

2012-02-17 Thread rajul jain
I think you should use TST data structure for this problem.
You can find some implementation HERE http://bit.ly/ADPNn5

On Thu, Feb 16, 2012 at 11:32 AM, pavan pavankri...@gmail.com wrote:

 i am getting WA by implementing TRIE .can anyone help me with the test
 cases for which the following code is failing.

 #includestdio.h
 #includestdlib.h
 #includestring.h
 #includeiostream
 #define MAX 26
 #define LEN 1000
 using namespace std;


 struct node
 {
char c;
int isterminal;
int no_children;
struct node* children[MAX];
 };
 struct node* createnode(char ch)
 {
struct node* nl=(struct node*)malloc(sizeof(struct node));
if(nl==NULL)
printf(memory allocation error);
else
{
nl-c=ch;
nl-no_children=0;
nl-isterminal=-1;
}
return nl;
 }
 struct node* insert(char* str,int i,int len,struct node* root)
 {
char ch=str[i];
if(i==len)
{
root-isterminal=1;
return root;
}
if(root-children[ch-'a']==NULL || root-children[ch-'a']-
 isterminal==-1)
{
struct node* nl=createnode(ch);
root-children[ch-'a']=nl;
root-children[ch-'a']-isterminal=0;
root-no_children++;
}
root-children[ch-'a']=insert(str,i+1,len,root-children[ch-'a']);
return root;
 }
 int countchildren(struct node* root,char* buffer,int len)
 {
int index=0;
static int count=0;
if(root-isterminal==1)
{
printf(%s\n,buffer);
count++;
}
for(int i=0;iMAX;i++)
{
if(root-children[i]!=NULL)
{
buffer[len]=root-children[i]-c;
buffer[len+1]='\0';

  countchildren(root-children[i],buffer,len+1);
}
}
return count;
 }
 int solve(char* str,int i,int len,struct node* root)
 {
int c;
char ch=str[i];
char buffer[LEN];
if(ilen)
{
if(root==NULL || root-children[ch-'a']==NULL)
return 0;
else
{
return solve(str,i+1,len,root-children[ch-'a']);
}
}
else
{
strcpy(buffer,str);
c=countchildren(root,buffer,strlen(str));
//printf(count %d\n,c);
return 1;
}
 }
 int main()
 {
struct node* trie=createnode('$');
char str[1000];
int t,k;
scanf(%d,t);
while(t--)
{
scanf(%s,str);
trie=insert(str,0,strlen(str),trie);
}
scanf(%d,k);
for(int i=1;i=k;i++)
{
scanf(%s,str);
printf(Case #%d:\n,i);
if(!solve(str,0,strlen(str),trie))
printf(No match.\n);
}
return 0;
 }

 On Feb 15, 11:56 am, shady sinv...@gmail.com wrote:
  will TRIE be the best solution for this problem ?
 
  Linkhttp://www.spoj.pl/problems/DICT/

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Bit Magic ....Always Stuck ..

2011-10-16 Thread rajul jain
I have read this question earlier
the algo is like this
1)Traverse from right to left , once we passed 1, turn on next 0 and also
turn off the one that's just to right side of
that.
example xxx11011  become xx101011
2) for making number small just rearrange all 1's to be as right as
possible.
xx101011 become  xx100111
similary you can get larger number by rearrange all 1's to left .


On Wed, Mar 2, 2011 at 1:20 AM, bittu shashank7andr...@gmail.com wrote:

 Given an integer, print the next smallest and next largest number that
 have the same number of 1 bits in their binary representation.

 Example for n=12
 next smallest  with same no. of set bit is 17  but  to found next
 largest ..we have to be careful ..

 let c others ..??



 Thanks  Regards
 Shashank











 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] what is the use of fflush ?

2011-10-09 Thread rajul jain
just take input a and b in one statement like this scanf(%d %d ,a ,b);


On Sun, Oct 9, 2011 at 4:50 PM, Saravanan Selvamani 
saravananselvam...@gmail.com wrote:

 Hi,
  In the following programming when i gave character input rather
 than integer , the following scanf statement is not working . so i introduce
 the fflush(stdin) before the last scanf statement.
 But i get the same error as i before .
  #includestdio.h
  int main()
  {
  int a,b;
  scanf(%d,a);
 
 fflush(stdin);
 scanf(%d,b);
 printf(%d,b); //prints some
 garbage value.
 return 0;
  }
 so then what is the use of the fflush(stdin) and how to correct the above
 error? Thanks in advance.
 Regards
 P.S.Saravanan.
 --
 why so serious?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Sapient Help!!

2011-10-03 Thread rajul jain
Hi akanksha
Thanks for your information .Today i have cleared my written, can you please
share some information about both interview process specifically that
attribute round  what sort of question they asked in that interview.

Rajul

On Fri, Sep 30, 2011 at 5:35 PM, Akanksha . akanksha...@gmail.com wrote:

 I m a 2011 passout n sapient had visited my clg in jan 2011.. first of
 all, u ll go thru a written test consising of apti ( quant, logical
 reasoning n english ) and one paper of c,ds n c++ combined... den u r
 shortlisted for technical interview in which dey ask u some puzzles n
 ques related to dbms, ds, os etc(depends on ur inteviewer),once u
 clear ur technical round, u ll hav a hr interview which is also an
 elimination round.. so prepare well n all d best :)

 On Fri, Sep 30, 2011 at 4:59 PM, Prags onlypr...@gmail.com wrote:
  @Akaknsha- hv sapient visited ur college ?? if yes , then what is its
  procedure ?
 
  On Wed, Sep 28, 2011 at 9:32 PM, Akanksha . akanksha...@gmail.com
 wrote:
 
  wrk culture is gud mostly.. if u want to do gud technical wrk den
  avoid dis company otherwise if u r interested in management or nething
  like dat den u can go for it..
 
  On Wed, Sep 28, 2011 at 8:15 PM, rohit rajuljain...@gmail.com wrote:
   Is anybody know about sapient working culture?
  
   --
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
  
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Mentor Graphics Help !!

2011-09-14 Thread rajul jain
If anybody know about placement procedure of mentor graphics pls help

On Mon, Aug 22, 2011 at 11:09 PM, Ankur Garg ankurga...@gmail.com wrote:

 Also to add,

 If you post profile in their portal no reply comes...How to apply ...can
 any one here refer my candidature for Mentor Graphics ..I have 2 yrs work ex
 working with IBM ISL

 Regards
 Ankur


 On Mon, Aug 22, 2011 at 7:23 PM, Mangal Dass mangaldass1...@gmail.comwrote:

 Anybody pls tell me the questions coming into Information-Mosaic campus
 test.
 Pls tell me both the pattern as well as questions whatever u r remembered.

 Thanks a lot,

 On 8/22/11, sourabh jakhar sourabhjak...@gmail.com wrote:
  i also want to know abt the off campus recruitment  of mentor graphics
  On Mon, Aug 22, 2011 at 6:49 PM, Decipher ankurseth...@gmail.com
 wrote:
 
  Can anyone tell me the interview procedure of Mentor Graphics along
 with
  some interview questions ??
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To view this discussion on the web visit
  https://groups.google.com/d/msg/algogeeks/-/NiJZzcypKH0J.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
 
  --
  SOURABH JAKHAR,(CSE)(Final year)
  ROOM NO 167 ,
  TILAK,HOSTEL
  'MNNIT ALLAHABAD
 
  The Law of Win says, Let's not do it your way or my way; let's do it
 the
  best way.
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Indus Valley Recruitment

2011-09-05 Thread rajul jain
paper was totally calculation based , dont forget to bring your calculator
in exam.

On Mon, Sep 5, 2011 at 8:10 PM, NITISH SHARMA cooln...@gmail.com wrote:

 Its coming on 8th n eligibility is 80% aggregate in btech

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Indus Valley Recruitment

2011-09-05 Thread rajul jain
only logical reasoning and verbal reasoning and LRDI question pattern is not
of cat type. they are just calculation type. If you have good calculation
you can crack it easily.they also allowed calculator.

On Mon, Sep 5, 2011 at 8:16 PM, NITISH SHARMA cooln...@gmail.com wrote:

 What all comes in the written test??

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c question

2011-09-03 Thread rajul jain
foo(char *s){
printf(%d, sizeof(s));   // correction
}

in this function foo s is a pointer so it print size of pointer which is 4 .

On Sat, Sep 3, 2011 at 6:22 PM, priya ramesh love.for.programm...@gmail.com
 wrote:

 In any C program,
 int main(){
 char a[100];
 foo(a);
 printf(%d, sizeof(a));
 }
 foo(char *s){
 printf(%d, sizeof(a));
 }

 In main sizeof a is 100, in foo it is 4. why??

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c question

2011-09-03 Thread rajul jain
As declaration of a[100] is defined in main function so main function print
100 , but foo() only know a pointer to a char data type that is why it print
4 in function foo()

correct me if i am wrong!

On Sat, Sep 3, 2011 at 6:52 PM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:

 char  *p,char [] are both same they  both have size 4


 On Sat, Sep 3, 2011 at 6:18 AM, himanshu kansal 
 himanshukansal...@gmail.com wrote:

 array is always given a special treatment...its nt a constant
 ptrits an array means 100 bytes r resrvd for it
 for this i think u mst go thru pointers in c and ritchi books.


 On Sat, Sep 3, 2011 at 6:41 PM, priya ramesh 
 love.for.programm...@gmail.com wrote:

 foo(char []s){
 printf(%d, sizeof(s));
 }

 even now it prints 4.
 My point is s pointer in foo and a is also a constant pointer in main. (a
 is passed to foo)
 However, in main a is treated as an rvalue and in s the same pointer is
 an lvalue. why??

 Someone plz reply. It's urgent

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

Regards
  Himanshu Kansal
Msc Comp. sc.
 (University of Delhi)


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *UTKARSH SRIVASTAV
 CSE-3
 B-Tech 3rd Year
 @MNNIT ALLAHABAD*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] character count in array

2011-09-03 Thread rajul jain
use hashing but you dont get space O(1) in hashing

On Sat, Sep 3, 2011 at 6:54 PM, Aman Kumar amanas...@gmail.com wrote:

 Hiii
 if array is given like this

 arr[]=aabcabbcdeadef

 convert this array into like

 arr[]=a4b3c2d2e2f1

 how can we do this

 can we do it with space complexity O(1).

 reply asap

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: character count in array

2011-09-03 Thread rajul jain
@ankuj  just want to clarify that in hashing method we require array of
fixed size let say arr[26] , so is it considered as constant space or not?

On Sat, Sep 3, 2011 at 8:02 PM, siddharam suresh siddharam@gmail.comwrote:

 sol already posted please search old thread
 Thank you,
 Sid.



 On Sat, Sep 3, 2011 at 8:01 PM, Ankuj Gupta ankuj2...@gmail.com wrote:

 If we take our input to be characters a-z ans A-Z then we require
 fixed space which can be treated as O(1).
 On Sep 3, 7:10 pm, teja bala pawanjalsa.t...@gmail.com wrote:
  this 'll work if u i/p the string in dis manner
  aaabbcc(consecutive same)
  a3b2c2
 
  #includestdio.h
  #includeconio.h
  main()
  {
  int x=1,i=0;
  char a[100];
  gets(a);
  while(a[i]!='\0')
  {
   while(a[i]==a[i+1])
   {
  x++;
  i++;
   }
   printf(%c%d,a[i],x);
   x=1;
   i++;
   }
  getchar();
 
 
 
 
 
 
 
  }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find the Max from each sub-array of size k

2011-09-02 Thread rajul jain
I think Dave has already given a good solution in earlier post.

first make a max heap of first k elements and then print max value which is
root .
now add next element in heap and again print max value  follow this
procedure till you reach end of an array.

On Fri, Sep 2, 2011 at 9:04 AM, Anup Ghatage ghat...@gmail.com wrote:

 Given an unsorted Array A and any integer k where k = size of A

 Print the maximum of each sub-array of size k of A.

 eg:  A = [ 3, 5, 1, 9, 0, 4, -1, 7 ]   k = 4
 Max: 9 9 9 9 7

 --
 Anup Ghatage

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Closest ancestor of two nodes

2011-09-02 Thread rajul jain
@anika this solution only works for BST

On Mon, Aug 15, 2011 at 4:20 PM, Anika Jain anika.jai...@gmail.com wrote:

 node *common_ancestor(node *root, node **prev, int x,int y)
 {
 if(root-a==x || root-a==y)
 return *prev;
 else if(root-a  x  root-a  y)
 {
 prev=root;
 return common_ancestor(root-l,prev, x,y);
 }
 else if(root-a  x  root-a  y)
 {
 prev=root;
 return common_ancestor(root-r,prev, x,y);
 }
 else
 {
 prev=root;
 return *prev;
 }
 }

 with call as
 node *prev=NULL;
  common_ancestor(root,prev,x,y);


 On Sun, Aug 14, 2011 at 10:08 PM, Yasir yasir@gmail.com wrote:

 Guys, How about the below mentioned implementation?
 The only assumptions is that nodes should exist  in the tree. (will fail
 if one node exists and another doesn't)

 static Node LCA(Node root, int d1, int d2){
  if(root==null)
 return root;
  if(root.left!=null  ( root.left.data == d1 || root.left.data==d2 ) )
// both nodes exists in left sub-tree
 return root;

 if(root.right!=null  ( root.right.data == d1 || root.right.data==d2) )
   // both nodes exists in right sub-tree
 return root;
  Node ltree = LCA(root.left, d1, d2);   //check recursively in left
 subtree
 Node rtree = LCA(root.right, d1, d2);// check recursively in
 right subtree
  if(ltree!=null  rtree!=null)// One node in left  another in right
 return root;
  return (ltree==null)?rtree:ltree;
 }


 Just to mention that, closest ancestor of 54 OR 49 would be 3 in the
 following tree:
  3
\
4
  /\
 5 8
   /
 9

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/24JUUQsBHvIJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find Max Sum Value Pairs

2011-09-01 Thread rajul jain
@bharat  I think pair of your example would be (4,4) , (4,3) ,(3,4),
(3,3)
correct me if am wrong..

On Thu, Sep 1, 2011 at 4:55 PM, bharatkumar bagana 
bagana.bharatku...@gmail.com wrote:

 @Mac: It gives us the first largest pair but need not all n pairs ..
 ex:
 A=1 1 3 4
 B=1 2 3 4
 pairs : (4,4),(4,3),(3,3),(2,4) .


 On Thu, Sep 1, 2011 at 4:57 AM, MAC macatad...@gmail.com wrote:

 since its sorted , cant we just take last (largest if assedning) elements
 of each and  return o(1) .. (since +ve we can do so i guess)



 On Thu, Sep 1, 2011 at 2:15 PM, Navneet Gupta navneetn...@gmail.comwrote:

 Given two sorted positive integer arrays A(n) and B(n), we define a
 set S = {(a,b) | a in A and b in B}. Obviously there are n2 elements
 in S. The value of such a pair is defined as Val(a,b) = a + b. Now we
 want to get the n pairs from S with largest values. need an O(n)
 algorithm.


 --
 Regards,
 Navneet

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 thanks
 --mac

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

 **Please do not print this e-mail until urgent requirement. Go Green!!
 Save Papers = Save Trees
 *BharatKumar Bagana*
 **http://www.google.com/profiles/bagana.bharatkumarhttp://www.google.com/profiles/bagana.bharatkumar
 *
 Mobile +91 8056127652*
 bagana.bharatku...@gmail.com


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C-Question

2011-08-20 Thread rajul jain
 5.375 in normalised form is - 0100  1010  1100   
As we type cast into char
so in little endian system it take 8 bits from last and store into p[0] ,
then it take next 8 bits store it into p[1] so on ...
In printf statement here X is specifier for float so it print hexadecimal
equivalent of binary number.


On Sat, Aug 20, 2011 at 11:21 AM, Vijay Khandar vijaykhand...@gmail.comwrote:

 If the binary equivalent of 5.375 in normalised form is - 0100 
 1010  1100   

 what is the o/p of following code-
 main()
 {
 float a=5.375;
 char *p;
 int i;
 p=(char *)a;
 for(i=0;i=3;i++)
 printf(%02X,(unsigned char)p[i]);
 }

 O/P= 00 00 AC 40
 Plz, Plz  anyone explain me in detail, how this o/p is coming?
 Vijay..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] an amazing amazon question!

2011-08-17 Thread rajul jain
what abou 16 , 61 , 116 so avg 55 m/hr

On Wed, Aug 17, 2011 at 10:35 PM, sagar pareek sagarpar...@gmail.comwrote:

 16, 61, 106  average speed is 45 miles/hour


 On Wed, Aug 17, 2011 at 10:28 PM, priya ramesh 
 love.for.programm...@gmail.com wrote:

 A car is traveling at a uniform speed.The driver sees a milestone showing
 a 2-digit number. After traveling for an hour the driver sees another
 milestone with the same digits in reverse order.After another hour the
 driver sees another milestone containing the same two digits. What is the
 average speed of the driver?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: an amazing amazon question!

2011-08-17 Thread rajul jain
thnx for correcting me

On Wed, Aug 17, 2011 at 11:38 PM, sagar pareek sagarpar...@gmail.comwrote:

 @rajul

 61-16 =45

 its not 55 miles per hour


 On Wed, Aug 17, 2011 at 11:33 PM, Don dondod...@gmail.com wrote:

 Actually you are all wrong. His uniform speed was zero, and he was
 sitting by milestone 44 the whole time.

 On Aug 17, 11:58 am, priya ramesh love.for.programm...@gmail.com
 wrote:
  A car is traveling at a uniform speed.The driver sees a milestone
 showing a
  2-digit number. After traveling for an hour the driver sees another
  milestone with the same digits in reverse order.After another hour the
  driver sees another milestone containing the same two digits. What is
 the
  average speed of the driver?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: an amazing amazon question!

2011-08-17 Thread rajul jain
but its speed is uniform i think Don answer is right

On Wed, Aug 17, 2011 at 11:42 PM, Douglas Diniz dgdi...@gmail.com wrote:

 There are infinite solutions with this logic, because the third
 milestone can have more than 2 digits.

 On Wed, Aug 17, 2011 at 3:08 PM, sagar pareek sagarpar...@gmail.com
 wrote:
  @rajul
 
  61-16 =45
 
  its not 55 miles per hour
 
  On Wed, Aug 17, 2011 at 11:33 PM, Don dondod...@gmail.com wrote:
 
  Actually you are all wrong. His uniform speed was zero, and he was
  sitting by milestone 44 the whole time.
 
  On Aug 17, 11:58 am, priya ramesh love.for.programm...@gmail.com
  wrote:
   A car is traveling at a uniform speed.The driver sees a milestone
   showing a
   2-digit number. After traveling for an hour the driver sees another
   milestone with the same digits in reverse order.After another hour the
   driver sees another milestone containing the same two digits. What is
   the
   average speed of the driver?
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
 
  --
  Regards
  SAGAR PAREEK
  COMPUTER SCIENCE AND ENGINEERING
  NIT ALLAHABAD
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 



 --
 ---
 Douglas Gameiro Diniz
 Engenheiro de Computação - 2003 - UNICAMP

 Mobile: (19) 92158777
 Gtalk: dgdiniz
 Msn: thedougdi...@hotmail.com

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: TRee question...

2011-08-13 Thread rajul jain
see WgpShashank second point carefully
it say successor  is parent of left node
so solution of you BST is parent of 2 which is 4

On Sat, Aug 13, 2011 at 7:50 PM, Anika Jain anika.jai...@gmail.com wrote:

 @ashmantak: the figure of dipankar is incorrect but his point is correct..
 for a tree like

 4
   /\
  2 10
 /   \
13
 successor of 3 shall be 4 not 2..


 On Fri, Aug 12, 2011 at 4:48 PM, ashmantak ashman...@gmail.com wrote:

 @Dipankar Patro -

 The figure u have made isn't a BST.Read the problem.
 His soln. is correct.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] an array question

2011-08-12 Thread rajul jain
I have use bactracking

http://codepad.org/rF4Sr3zk

it works for only 1 and 2digit number



On Fri, Aug 12, 2011 at 6:04 PM, Yasir Imteyaz yasir@gmail.com wrote:

 An array of integers is given and you have to find the largest possible
 integer by concatenating all elements:

 example:
 array:  87  36  52
 answer:  875236

 array: 87 9 52
 answer: 98752

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/_lJJOlRG_ukJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] iocl recruitment process

2011-08-12 Thread rajul jain
If you are in top 5 in your coe branch then dont take stress and if not then
dont worry about process bcoz they take only 2-3 student from top 5 each
year in GEN category .

On Fri, Aug 12, 2011 at 12:34 PM, coder coder
i.code.program...@gmail.comwrote:

 iocl is coming to my college
 please any dceite please tell what they are asking in their interview
 process  and what profile they are offering to the coe candidate

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: what is complexity of func(p)

2011-08-09 Thread rajul jain
thanks to all

On Tue, Aug 9, 2011 at 8:45 PM, shady sinv...@gmail.com wrote:

 he is questioning the complexity and not the algorithm... btw, you are
 right


 On Tue, Aug 9, 2011 at 8:41 PM, Don dondod...@gmail.com wrote:

 I don't think that this function is doing what you want it to do. If
 you ask for a^b, it returns a^1 in most cases.

 Try this instead.

 int power(int a, int b)
 {
  int result = 1;
  if (b == 1) result = a;
  else if (b1)
  {
result = power(a,b/2);
result *= result;
if (b%2) result *= a;
  }
  return result;
 }

 On Aug 8, 10:37 pm, rohit rajuljain...@gmail.com wrote:
   int get_power(int a, int b)
  {
  if(!b)
  return 1;
  if(b%2)
   return a * get_power(a, b/2);
   return get_power(a, b/2);
   }
 
  int func(int p)
  { int sum = 0;
   for(int i = 1; i = p; ++i)
  {
  sum += get_power(i, 5);}
 
  return sum;
 
  }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon test question!!!

2011-08-08 Thread rajul jain
got it thanks


On Mon, Aug 8, 2011 at 10:30 PM, Akash Mukherjee akash...@gmail.com wrote:

 i think its 1 though ...


 On Mon, Aug 8, 2011 at 10:21 PM, rohit rajuljain...@gmail.com wrote:

 What will the following code snippet do, when is it passed the root of
 a binary tree ?
 func( Node *node){

  if(node-right != NULL)

   func( node-right);

  if(node-left != NULL)

func( node-left);

  if( node-left == NULL  node-right == NULL )

 delete(node);

 }

 Pick choice
 Delete the tree from bottom to top

 Delete the tree from top to bottom

 Delete the leaf nodes from right to left

 Delete the leaf nodes from left to right

 I think it is 3

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon test question!!!

2011-08-08 Thread rajul jain
I have also made same answer on first look but read 3rd  option correctly it
say deletion of leaves from right to left not internal nodes.

On Mon, Aug 8, 2011 at 10:36 PM, Debabrata Das 
debabrata.barunhal...@gmail.com wrote:

 i think 3

 On Mon, Aug 8, 2011 at 10:32 PM, rajul jain rajuljain...@gmail.com
 wrote:
  got it thanks
 
  On Mon, Aug 8, 2011 at 10:30 PM, Akash Mukherjee akash...@gmail.com
 wrote:
 
  i think its 1 though ...
 
  On Mon, Aug 8, 2011 at 10:21 PM, rohit rajuljain...@gmail.com wrote:
 
  What will the following code snippet do, when is it passed the root of
  a binary tree ?
  func( Node *node){
 
   if(node-right != NULL)
 
func( node-right);
 
   if(node-left != NULL)
 
 func( node-left);
 
   if( node-left == NULL  node-right == NULL )
 
  delete(node);
 
  }
 
  Pick choice
  Delete the tree from bottom to top
 
  Delete the tree from top to bottom
 
  Delete the leaf nodes from right to left
 
  Delete the leaf nodes from left to right
 
  I think it is 3
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon test question!!!

2011-08-08 Thread rajul jain
after deletion of leaf parent become leaf of parent's parent. so parent of
leaf would also delete I think

On Mon, Aug 8, 2011 at 10:49 PM, Debabrata Das 
debabrata.barunhal...@gmail.com wrote:

 check this condition
 if( node-left == NULL  node-right == NULL )
 it is true only for leaves node

 On Mon, Aug 8, 2011 at 10:46 PM, rajul jain rajuljain...@gmail.com
 wrote:
  I have also made same answer on first look but read 3rd  option correctly
 it
  say deletion of leaves from right to left not internal nodes.
 
  On Mon, Aug 8, 2011 at 10:36 PM, Debabrata Das
  debabrata.barunhal...@gmail.com wrote:
 
  i think 3
 
  On Mon, Aug 8, 2011 at 10:32 PM, rajul jain rajuljain...@gmail.com
  wrote:
   got it thanks
  
   On Mon, Aug 8, 2011 at 10:30 PM, Akash Mukherjee akash...@gmail.com
   wrote:
  
   i think its 1 though ...
  
   On Mon, Aug 8, 2011 at 10:21 PM, rohit rajuljain...@gmail.com
 wrote:
  
   What will the following code snippet do, when is it passed the root
 of
   a binary tree ?
   func( Node *node){
  
if(node-right != NULL)
  
 func( node-right);
  
if(node-left != NULL)
  
  func( node-left);
  
if( node-left == NULL  node-right == NULL )
  
   delete(node);
  
   }
  
   Pick choice
   Delete the tree from bottom to top
  
   Delete the tree from top to bottom
  
   Delete the leaf nodes from right to left
  
   Delete the leaf nodes from left to right
  
   I think it is 3
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon test question!!!

2011-08-08 Thread rajul jain
This is what i am trying to say to debabrata

On Mon, Aug 8, 2011 at 10:56 PM, aditi garg aditi.garg.6...@gmail.comwrote:

 @debrata : bt remember its a recursive function...once the leaf node gets
 deleted thn it will move bak to the node and thn to the left of it
 fr eg
   a
/\
   b c
 /  \/  \
d   e  f   g
 frst g will be deleted...then f thn it wil delete c and so on...i think the
 ans shud be 1...correct me if i am wrong...
 On Mon, Aug 8, 2011 at 10:49 PM, Debabrata Das 
 debabrata.barunhal...@gmail.com wrote:

 check this condition
 if( node-left == NULL  node-right == NULL )
 it is true only for leaves node

 On Mon, Aug 8, 2011 at 10:46 PM, rajul jain rajuljain...@gmail.com
 wrote:
  I have also made same answer on first look but read 3rd  option
 correctly it
  say deletion of leaves from right to left not internal nodes.
 
  On Mon, Aug 8, 2011 at 10:36 PM, Debabrata Das
  debabrata.barunhal...@gmail.com wrote:
 
  i think 3
 
  On Mon, Aug 8, 2011 at 10:32 PM, rajul jain rajuljain...@gmail.com
  wrote:
   got it thanks
  
   On Mon, Aug 8, 2011 at 10:30 PM, Akash Mukherjee akash...@gmail.com
 
   wrote:
  
   i think its 1 though ...
  
   On Mon, Aug 8, 2011 at 10:21 PM, rohit rajuljain...@gmail.com
 wrote:
  
   What will the following code snippet do, when is it passed the root
 of
   a binary tree ?
   func( Node *node){
  
if(node-right != NULL)
  
 func( node-right);
  
if(node-left != NULL)
  
  func( node-left);
  
if( node-left == NULL  node-right == NULL )
  
   delete(node);
  
   }
  
   Pick choice
   Delete the tree from bottom to top
  
   Delete the tree from top to bottom
  
   Delete the leaf nodes from right to left
  
   Delete the leaf nodes from left to right
  
   I think it is 3
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
  
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Aditi Garg
 Undergraduate Student
 Electronics  Communication Divison
 NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
 Sector 3, Dwarka
 New Delhi


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon question

2011-08-08 Thread rajul jain
How many Children process following program produce
*
void main() {

int p1= fork();

if (p1 == 0) {

 int p2 = fork();

 if (p2 != 0) {

  fork();

 }

}

}


*
On Mon, Aug 8, 2011 at 11:11 AM, Kamakshii Aggarwal
kamakshi...@gmail.comwrote:

 what will be the o/p of the following program:

 main()
 {
 int ret;
 ret=fork();
 ret=fork();
 ret=fork();
 ret=fork();

 if(!ret)
 printf(one);
 else
 printf(two);
 }








 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Directi Question

2011-08-07 Thread rajul jain
If we get even number (probability 1/2) in first throw , so the expected
 run is 1
If first throw give ODD (probability 1/2) ,the run needed become 1 + run
needed until second odd number .This last waiting time is 2 .
Thus expected run become  (1/2) (1) + (1/2)(1+2) = 2

On Sat, Aug 6, 2011 at 8:04 PM, shady sinv...@gmail.com wrote:

 Hi,

 A fair dice is rolled. Each time the value is noted and running sum is
 maintained. What is the expected number of runs needed so that the sum is
 even ?
 Can anyone tell how to solve this problem ? as well as other related
 problems of such sort

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Directi Question

2011-08-07 Thread rajul jain
let expected time is T  , if we get even(probability 1/2) on first throw so
T become 1 If dont then you are at same place where you started so T =
 (1/2) (1) + (1/2) ( 1+T)
  = T =2

On Sun, Aug 7, 2011 at 6:05 PM, rajul jain rajuljain...@gmail.com wrote:

 If we get even number (probability 1/2) in first throw , so the expected
  run is 1
 If first throw give ODD (probability 1/2) ,the run needed become 1 + run
 needed until second odd number .This last waiting time is 2 .
 Thus expected run become  (1/2) (1) + (1/2)(1+2) = 2

 On Sat, Aug 6, 2011 at 8:04 PM, shady sinv...@gmail.com wrote:

 Hi,

 A fair dice is rolled. Each time the value is noted and running sum is
 maintained. What is the expected number of runs needed so that the sum is
 even ?
 Can anyone tell how to solve this problem ? as well as other related
 problems of such sort

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Duplicates in a string

2011-08-05 Thread rajul jain
Can You please explain this bit manipualtion

On Fri, Aug 5, 2011 at 10:31 PM, hary rathor harry.rat...@gmail.com wrote:

 #includestring.h
 int main ()
 {
 char str[]=hello world;
 int i,j=0,checker=0;

 for(i=0;istrlen(str);i++)
 {
 int  val=str[i]-'a';
if ((checker(1val))=0)
str[j++]=str[i];
checker|=(1val);
 }

 str[j]='\0';

 printf(%s,str);
 return 0;

 }

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Sort array with two subparts sorted

2011-04-12 Thread rajul jain
use merge sort

On Tue, Apr 12, 2011 at 3:07 PM, Akash Agrawal akash.agrawa...@gmail.comwrote:

 Given an array with two subparts sorted. How will you make a final sorted
 array.

 i/p:  1, 5, 7, 9, 11, 23, 2, 3, 8, 9, 21

 o/p:
 1, 2, 3, 5, 7, 8, 9, 9, 11, 21, 23


 Regards,
 Akash Agrawal
 http://tech-queries.blogspot.com/

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] 3march

2011-03-03 Thread rajul jain
2500 gold
5 pirates

Set the initial 2 pirates gold equal as follows:
x = total gold

100 + [(x-100)/6] = 200 + [(x - 200 - 100 - ((x-100)/6)/6]

Rearranging and solving:
x - 100 = 300 + x - [(x-100)/6]

And again:
0 = 400 - [(x-100)/6]

And again:
0 = 2400 - x + 100

Therefore x = 2500

Substitue this value into the equation for Pirate 1

On Thu, Mar 3, 2011 at 1:32 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote:

 *Split the Booty Problem Solution*
 *
 *
 A pirate crew at the end of the day split the booty. The first pirate got
 100 gold pieces, and 1/6 of the remaining booty. The second one got 200 gold
 pieces, and 1/6 of the remaining booty. The third one got 300 gold pieces,
 and 1/6 of the remaining booty. Ect. The last one only got, what if left
 from the booty.
 At the end, every pirate had the same ammount of gold pieces (from the
 booty).
 How many pirates were there, and how much was the booty.

 Update Your Answers at : Click 
 Herehttp://dailybrainteaser.blogspot.com/2011/03/3march.html

 Solution:
 Will be updated after 1 day


 --

 Never explain yourself. Your friends don’t need it and
 your enemies won’t believe it .

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] brain teaser

2011-03-03 Thread rajul jain
@naveen
but in this question don't know numbers of black and red hats like prison
and hat puzzle

On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar naveenkumarve...@gmail.comwrote:

 http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle

 On Thu, Mar 3, 2011 at 3:01 PM, amit kumar amitthecoo...@gmail.comwrote:

 ya at least 10 can be easily freed


 On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak pathak@gmail.comwrote:

 I think that the last person will tell the color of next front person of
 him, that means next person will sure that his hat color will be color
 ,telling by back person.
 thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest
 amy or may not be...

 if i am wrong ,tell me



 On Thu, Mar 3, 2011 at 1:48 PM, freecoder rajuljain...@gmail.comwrote:

 You are one of 20 prisoners on death row with the execution date set
 for tomorrow.

 Your king is a ruthless man who likes to toy with his people's
 miseries. He comes to your cell today and tells you:

 “I’m gonna give you prisoners a chance to go free tomorrow. You will
 all stand in a row (queue) before the executioner and we will put a
 hat on your head, either a red or a black one. Of course you will not
 be able to see the color of your own hat; you will only be able to see
 the prisoners in front of you with their hats on; you will not be
 allowed to look back or communicate together in any way (talking,
 touching.)

 (The prisoner in the back will be able to see the 19 prisoners in
 front of him
 The one in front of him will be able to see 18…)

 Starting with the last person in the row, the one who can see
 everybody in front of him, he will be asked a simple question: WHAT IS
 THE COLOR OF YOUR HAT?

 He will be only allowed to answer “BLACK” or “RED”. If he says
 anything else you will ALL be executed immediately.

 If he guesses the right color of the hat on his head he is set free,
 otherwise he is put to death. And we move on to the one in front of
 him and ask him the same question and so on…

 Well, good luck tomorrow, HA HA HA HA HA HA!”

 Now since you all can communicate freely during the night, can you
 find a way to guarantee the freedom of some prisoners tomorrow? How
 many?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

 Thanks and Regards,

 Manish Pathak **
 TimesJobs.com
  manish.pat...@timesgroup.com
 Mo.  9015687266


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Cheers
 Naveen Kumar

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] brain teaser

2011-03-03 Thread rajul jain
@naveen you are right there is a variant similar to this problem but here
come to discuss solution to this problem.

On Thu, Mar 3, 2011 at 3:38 PM, Naveen Kumar naveenkumarve...@gmail.comwrote:

 There are many variants of this puzzle listed there.

 checkout for Ten-Hat Variant


 On Thu, Mar 3, 2011 at 3:32 PM, rajul jain rajuljain...@gmail.com wrote:

 @naveen
 but in this question don't know numbers of black and red hats like prison
 and hat puzzle


 On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar 
 naveenkumarve...@gmail.comwrote:

 http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle

 On Thu, Mar 3, 2011 at 3:01 PM, amit kumar amitthecoo...@gmail.comwrote:

 ya at least 10 can be easily freed


 On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak pathak@gmail.comwrote:

 I think that the last person will tell the color of next front person
 of him, that means next person will sure that his hat color will be color
 ,telling by back person.
 thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and
 rest amy or may not be...

 if i am wrong ,tell me



 On Thu, Mar 3, 2011 at 1:48 PM, freecoder rajuljain...@gmail.comwrote:

 You are one of 20 prisoners on death row with the execution date set
 for tomorrow.

 Your king is a ruthless man who likes to toy with his people's
 miseries. He comes to your cell today and tells you:

 “I’m gonna give you prisoners a chance to go free tomorrow. You will
 all stand in a row (queue) before the executioner and we will put a
 hat on your head, either a red or a black one. Of course you will not
 be able to see the color of your own hat; you will only be able to see
 the prisoners in front of you with their hats on; you will not be
 allowed to look back or communicate together in any way (talking,
 touching.)

 (The prisoner in the back will be able to see the 19 prisoners in
 front of him
 The one in front of him will be able to see 18…)

 Starting with the last person in the row, the one who can see
 everybody in front of him, he will be asked a simple question: WHAT IS
 THE COLOR OF YOUR HAT?

 He will be only allowed to answer “BLACK” or “RED”. If he says
 anything else you will ALL be executed immediately.

 If he guesses the right color of the hat on his head he is set free,
 otherwise he is put to death. And we move on to the one in front of
 him and ask him the same question and so on…

 Well, good luck tomorrow, HA HA HA HA HA HA!”

 Now since you all can communicate freely during the night, can you
 find a way to guarantee the freedom of some prisoners tomorrow? How
 many?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

 Thanks and Regards,

 Manish Pathak **
 TimesJobs.com
  manish.pat...@timesgroup.com
 Mo.  9015687266


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Cheers
 Naveen Kumar

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Cheers
 Naveen Kumar

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks

Re: [algogeeks] Amazon Question

2011-03-03 Thread rajul jain
i think he is wrong bcoz this array in not sorted one.
so solution of Ankit is right.

On Thu, Mar 3, 2011 at 7:33 PM, nishaanth nishaant...@gmail.com wrote:

 Ignore the previous post..there is a small error in the code..
 @Ankit..your algm is O(n)...you should split the problem size to n/2 at
 every stage...rather you are again computing both the subarrays..

 Here is the correct code...

 int BsearchElemEqualIndex (int *a, int start, int end)
 {
int mid = (((end - start)  1) + start);
if (a[mid] == mid)
return a[mid];
else if (a[mid] != mid)
{
if (mid == start || mid == end)
{
return -1;
}
else
{
   if(a[mid]  mid )
BsearchElemEqualIndex (a, start, mid);
else
BsearchElemEqualIndex (a, mid + 1, end);
}
}
 }

 int _tmain(int argc, _TCHAR* argv[])
 {
int a[SIZE] = {5,9,3,8,1,2,6,7};
int x = BsearchElemEqualIndex (a, 0, SIZE);
printf (%d, x);
system (PAUSE);
return 0;
 }
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Amazon Question

2011-03-03 Thread rajul jain
@ankit  they both(gunjan  nishanth) are right in term of complexity but
their solution is not correct ...
tell me if i am wrong

On Thu, Mar 3, 2011 at 8:15 PM, Ankit Sinha akki12...@gmail.com wrote:

 @Gunjan  Nishanth, yes, you both are right. I just missed the basics
 in dividing it in n/2 logically for each call.

 Thanks,
 Ankit!!

 On Thu, Mar 3, 2011 at 7:39 PM, Gunjan Sharma gunjan.khan...@gmail.com
 wrote:
  Still there is an error it should be
   if(a[mid]  mid )
 BsearchElemEqualIndex (a, start, mid);
 else
 BsearchElemEqualIndex (a, mid + 1, end);
  correct me if I am wrong
  On Thu, Mar 3, 2011 at 7:33 PM, nishaanth nishaant...@gmail.com wrote:
 
  Ignore the previous post..there is a small error in the code..
  @Ankit..your algm is O(n)...you should split the problem size to n/2 at
  every stage...rather you are again computing both the subarrays..
  Here is the correct code...
  int BsearchElemEqualIndex (int *a, int start, int end)
  {
 int mid = (((end - start)  1) + start);
 if (a[mid] == mid)
 return a[mid];
 else if (a[mid] != mid)
 {
 if (mid == start || mid == end)
 {
 return -1;
 }
 else
 {
if(a[mid]  mid )
 BsearchElemEqualIndex (a, start, mid);
 else
 BsearchElemEqualIndex (a, mid + 1, end);
 }
 }
  }
 
  int _tmain(int argc, _TCHAR* argv[])
  {
 int a[SIZE] = {5,9,3,8,1,2,6,7};
 int x = BsearchElemEqualIndex (a, 0, SIZE);
 printf (%d, x);
 system (PAUSE);
 return 0;
  }
  S.Nishaanth,
  Computer Science and engineering,
  IIT Madras.
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  Regards
  Gunjan Sharma
  Chairman IEEE Students Chapter IIT Roorkee
  B.Tech IV year CSE
  Contact No- +91 9997767077
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: brain teaser

2011-03-03 Thread rajul jain
@param But how can u prove that.

On Thu, Mar 3, 2011 at 5:16 PM, Param10k paramesh...@gmail.com wrote:

 At d Max 1 person 'll die


 -Param
 http://teknotron-param.blogspot.com/

 On Mar 3, 3:20 pm, rajul jain rajuljain...@gmail.com wrote:
  @naveen you are right there is a variant similar to this problem but here
  come to discuss solution to this problem.
 
  On Thu, Mar 3, 2011 at 3:38 PM, Naveen Kumar naveenkumarve...@gmail.com
 wrote:
 
 
 
 
 
 
 
   There are many variants of this puzzle listed there.
 
   checkout for Ten-Hat Variant
 
   On Thu, Mar 3, 2011 at 3:32 PM, rajul jain rajuljain...@gmail.com
 wrote:
 
   @naveen
   but in this question don't know numbers of black and red hats like
 prison
   and hat puzzle
 
   On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar 
 naveenkumarve...@gmail.comwrote:
 
  http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
 
   On Thu, Mar 3, 2011 at 3:01 PM, amit kumar amitthecoo...@gmail.com
 wrote:
 
   ya at least 10 can be easily freed
 
   On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak pathak@gmail.com
 wrote:
 
   I think that the last person will tell the color of next front
 person
   of him, that means next person will sure that his hat color will be
 color
   ,telling by back person.
   thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and
   rest amy or may not be...
 
   if i am wrong ,tell me
 
   On Thu, Mar 3, 2011 at 1:48 PM, freecoder rajuljain...@gmail.com
 wrote:
 
   You are one of 20 prisoners on death row with the execution date
 set
   for tomorrow.
 
   Your king is a ruthless man who likes to toy with his people's
   miseries. He comes to your cell today and tells you:
 
   “I’m gonna give you prisoners a chance to go free tomorrow. You
 will
   all stand in a row (queue) before the executioner and we will put
 a
   hat on your head, either a red or a black one. Of course you will
 not
   be able to see the color of your own hat; you will only be able to
 see
   the prisoners in front of you with their hats on; you will not be
   allowed to look back or communicate together in any way (talking,
   touching.)
 
   (The prisoner in the back will be able to see the 19 prisoners in
   front of him
   The one in front of him will be able to see 18…)
 
   Starting with the last person in the row, the one who can see
   everybody in front of him, he will be asked a simple question:
 WHAT IS
   THE COLOR OF YOUR HAT?
 
   He will be only allowed to answer “BLACK” or “RED”. If he says
   anything else you will ALL be executed immediately.
 
   If he guesses the right color of the hat on his head he is set
 free,
   otherwise he is put to death. And we move on to the one in front
 of
   him and ask him the same question and so on…
 
   Well, good luck tomorrow, HA HA HA HA HA HA!”
 
   Now since you all can communicate freely during the night, can you
   find a way to guarantee the freedom of some prisoners tomorrow?
 How
   many?
 
   --
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
 
   Thanks and Regards,
 
   Manish Pathak **
   TimesJobs.com
manish.pat...@timesgroup.com
   Mo.  9015687266
 
--
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Cheers
   Naveen Kumar
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Cheers
   Naveen Kumar
 
   --
   You

Re: [algogeeks] Re: brain teaser

2011-03-03 Thread rajul jain
but they cannot communicate with each other (neither talking not hearing)
they just see person stand in front of him.

On Thu, Mar 3, 2011 at 11:04 PM, Dave dave_and_da...@juno.com wrote:

 I have a way to save 19. Let each prisoner have his own private
 variable C, which he initializes to RED if he sees an odd number of
 red hats, or to BLACK if he sees an even number of red hats. The last
 man in the row announces his C. Every time someone announces the color
 RED, everyone ahead of him flips his C to the other color. In turn,
 each remaining man announces his C.

 Dave

 On Mar 3, 2:18 am, freecoder rajuljain...@gmail.com wrote:
  You are one of 20 prisoners on death row with the execution date set
  for tomorrow.
 
  Your king is a ruthless man who likes to toy with his people's
  miseries. He comes to your cell today and tells you:
 
  “I’m gonna give you prisoners a chance to go free tomorrow. You will
  all stand in a row (queue) before the executioner and we will put a
  hat on your head, either a red or a black one. Of course you will not
  be able to see the color of your own hat; you will only be able to see
  the prisoners in front of you with their hats on; you will not be
  allowed to look back or communicate together in any way (talking,
  touching.)
 
  (The prisoner in the back will be able to see the 19 prisoners in
  front of him
  The one in front of him will be able to see 18…)
 
  Starting with the last person in the row, the one who can see
  everybody in front of him, he will be asked a simple question: WHAT IS
  THE COLOR OF YOUR HAT?
 
  He will be only allowed to answer “BLACK” or “RED”. If he says
  anything else you will ALL be executed immediately.
 
  If he guesses the right color of the hat on his head he is set free,
  otherwise he is put to death. And we move on to the one in front of
  him and ask him the same question and so on…
 
  Well, good luck tomorrow, HA HA HA HA HA HA!”
 
  Now since you all can communicate freely during the night, can you
  find a way to guarantee the freedom of some prisoners tomorrow? How
  many?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.