[algogeeks] Acces violation problem

2015-09-03 Thread Puneet Gautam
HI, I am running the following peice of code on Dev-cpp compiler

#include
#include
#include
struct bst
{
   int info;
   struct bst *leftnode;
   struct bst *rightnode;
};
void insert(struct bst *node,int val1)
{
 struct bst *newnode=malloc(sizeof(struct bst));
 struct bst *temp=malloc(sizeof(struct bst));
 newnode->info=val1;
 temp=node;
 while(temp)
 {printf("\n Inside while loop");
*  if(val1<=temp->info)*
  if(temp->leftnode!=NULL)
  {temp=temp->leftnode;
   printf("\n IN if of left");
   }
  else
  break;
  else
  if((temp->rightnode)!=NULL)
  {   temp=temp->rightnode;
   printf("\n IN if of right");
   }
  else
  break;
 }
 if(!temp)
 {free(temp);
  return;
 }
  else if(val1<=temp->info)
  {temp->leftnode=newnode;
   printf("\n Inserted to the left");
  }
  else
   {   temp->rightnode=newnode;
printf("\n Inserted to the right");
   }
  newnode->leftnode=NULL;
  newnode->rightnode=NULL;
  free(temp);
}
int main()
{
struct bst *start=malloc(sizeof(struct bst));
   // struct bst *newnode=malloc(sizeof(struct bst));
start->info=10;
start->leftnode=NULL;
start->rightnode=NULL;
printf("Data is :%d",start->info);
getchar();
insert(start,20);
  * insert(start,5);*
getchar();
free(start);
return 0;
}

The compiler reports *Access violation* at the highlighted lines i.e.
*insert(start,5);*
But at the run of insert(start,20); , there is no problem as such.
Please help !!

Regards
Puneet

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] maximum length subarray with sum=0

2012-09-03 Thread Puneet Gautam
@atul: i didnt get your algo fully..
Can u just tell me how it works on this array.. {-3 2 1 5 -12 6 1 -2}
the aux array would become {-3 -1 0 5 -7 -1 0 -2}
then whats the next step.?

We analyze the aux for the repeated element which sets
subarray start= 2 subarray end=6

then aux contains 0 at two indices 2 and 6.this gives us the correct answer
here..
but that wont be the case everytime, right..?
everytime start of subarray cant be 0..

Can u clarify more on this..?
Coz i dont think it works on every test array..



On Sun, Sep 2, 2012 at 12:32 AM, atul anand atul.87fri...@gmail.com wrote:

 take aux[] array of same size and store cumulative some at
 aux[i]=sum{input[0 to i]}
 now if you find any repeated element at index i and j then,
 subarray start = i + 1;
 subarray end = j

 if array contain 0 at index j then,
 subarray start = 0;
 subarray end = j



 On 9/2/12, Puneet Gautam puneet.nsi...@gmail.com wrote:
  Given an array of positive and negative integers, we need to find the
  MAX length subarray having sum as ZERO...
 
  Is there a solution less than O(n^2)..?
 
  Please help .. i m stuck at this problem..
 
  Thanks
  Puneet
 
  --
  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] use of static

2012-09-03 Thread Puneet Gautam
Thats ok.. but can u tell me its more implementations in C and OOP..?


On Sun, Sep 2, 2012 at 9:59 AM, rahul rahulr...@gmail.com wrote:

 i m talking in contest of question, not explaining overall picture of
 static in c,c++,java.
 On Sep 2, 2012 12:07 AM, Puneet Gautam puneet.nsi...@gmail.com wrote:

 @rahul: There is something more to static than to retain old value.
 Are u sure it is not used anywhere else for any other purpose, bcoz i
 dont think thats the whole purpose of this keyword..



 On 8/30/12, rahul rahulr...@gmail.com wrote:
  static doing nothing, just to make a candidate confuse in interview.
  static comes into picture, when u calling same function again and again
 and
  u need some variable to retain the old value, and another scenario when
 u
  have to define the scope of variable.
 
 
  On Thu, Aug 30, 2012 at 6:02 PM, Puneet Gautam
  puneet.nsi...@gmail.comwrote:
 
  Well, its gives error in every array assignment..ISO forbids this type
  of
  assignment.
  @rahul: But whats with the static here. how  does it affect any string
  declared..? I couldnt get your answer ..pls explain
 
  On Thu, Aug 30, 2012 at 12:54 PM, rahul rahulr...@gmail.com wrote:
 
  old style C, where you can't have auto array. just that.
 
 
  On Thu, Aug 30, 2012 at 12:52 PM, Romil ...
  vamosro...@gmail.comwrote:
 
  It should give an error in the line  names[3] = names[4] 
  These are fixed address values..you cannot change them.
 
 
  On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam
  puneet.nsi...@gmail.com
   wrote:
 
  #includeiostream.h
  int main()
  {static char names[5][20]={pascal,ada,cobol,fortran,perl};
  int i;
  char *t;
  t=names[3];
  names[3]=names[4];
  names[4]=t;
  for (i=0;i=4;i++)
  coutnames[i]endl;
  getchar();
  return 0;
  }
 
 
  Whats the importance of static keyword here..?
 
   --
  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.
 
 
 
 
  --
  Romil
  Software Engineer,
  Winshuttle Softwares India Pvt. Ltd.
  Chandigarh
 
 
   --
  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.



[algogeeks] maximum length subarray with sum=0

2012-09-01 Thread Puneet Gautam
Given an array of positive and negative integers, we need to find the
MAX length subarray having sum as ZERO...

Is there a solution less than O(n^2)..?

Please help .. i m stuck at this problem..

Thanks
Puneet

-- 
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] use of static

2012-09-01 Thread Puneet Gautam
@rahul: There is something more to static than to retain old value.
Are u sure it is not used anywhere else for any other purpose, bcoz i
dont think thats the whole purpose of this keyword..



On 8/30/12, rahul rahulr...@gmail.com wrote:
 static doing nothing, just to make a candidate confuse in interview.
 static comes into picture, when u calling same function again and again and
 u need some variable to retain the old value, and another scenario when u
 have to define the scope of variable.


 On Thu, Aug 30, 2012 at 6:02 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Well, its gives error in every array assignment..ISO forbids this type
 of
 assignment.
 @rahul: But whats with the static here. how  does it affect any string
 declared..? I couldnt get your answer ..pls explain

 On Thu, Aug 30, 2012 at 12:54 PM, rahul rahulr...@gmail.com wrote:

 old style C, where you can't have auto array. just that.


 On Thu, Aug 30, 2012 at 12:52 PM, Romil ...
 vamosro...@gmail.comwrote:

 It should give an error in the line  names[3] = names[4] 
 These are fixed address values..you cannot change them.


 On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam
 puneet.nsi...@gmail.com
  wrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 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.




 --
 Romil
 Software Engineer,
 Winshuttle Softwares India Pvt. Ltd.
 Chandigarh


  --
 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.



[algogeeks] use of static

2012-08-30 Thread Puneet Gautam
#includeiostream.h
int main()
{static char names[5][20]={pascal,ada,cobol,fortran,perl};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i=4;i++)
coutnames[i]endl;
getchar();
return 0;
}


Whats the importance of static keyword here..?

-- 
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] use of static

2012-08-30 Thread Puneet Gautam
Well, its gives error in every array assignment..ISO forbids this type of
assignment.
@rahul: But whats with the static here. how  does it affect any string
declared..? I couldnt get your answer ..pls explain
On Thu, Aug 30, 2012 at 12:54 PM, rahul rahulr...@gmail.com wrote:

 old style C, where you can't have auto array. just that.


 On Thu, Aug 30, 2012 at 12:52 PM, Romil ... vamosro...@gmail.comwrote:

 It should give an error in the line  names[3] = names[4] 
 These are fixed address values..you cannot change them.


 On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam 
 puneet.nsi...@gmail.comwrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 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.




 --
 Romil
 Software Engineer,
 Winshuttle Softwares India Pvt. Ltd.
 Chandigarh


  --
 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]

2012-07-20 Thread Puneet Gautam
@sanjay: what about Bus error..?


On 7/18/12, Sanjay Rajpal sanjay.raj...@live.in wrote:
 Segmentation fault occurs when you try to access a memory which doesn't
 belong to your program.

 You are trying to cast a memory location of one byte to 4 byte(assuming
 size of long int to be 4). It is possible that other three bytes belong to
 some other process.
 That is why you are getting segmentation error.

 Correct me if m wrong.



 * *

 **
 *
 *



 On Wed, Jul 18, 2012 at 4:55 PM, vindhya chhabra
 vindhyachha...@gmail.comwrote:

 is it due to accessing the long at odd address?

 On Wed, Jul 18, 2012 at 4:54 PM, vindhya chhabra
 vindhyachha...@gmail.com wrote:
  #include  stdlib.h
  #include  stdio.h
  int main(void)
  {
  char *c;
  long int *i;
  c = (char *) malloc(sizeof(char));
  c++;
  i = (long int *)c;
  printf(%ld, *i);
  return 0;
  }
  please explain how bus error occurs  here..i am not clear about bus
  error and segmentation fault..plz help.
 
 
  --
  Vindhya Chhabra
 
  --
  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.
 



 --
 Vindhya Chhabra

 --
 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 error

2011-09-14 Thread Puneet Gautam
I think there is no problem with the while statement, even if file is
not present , it will create a new file...
The problem is with f.get()but dunno what...?


On 9/14/11, sandeep kumar sandeep.crazyguy2...@gmail.com wrote:
 if file.txt is not present it gives a seg fault
 and if the file is present then the problem is with f.get(), use fgetc or
 fgets etc the program runs without any error


 *..*
 *
 **Regards

 Sandeep Kumar
 MTech Computer Science
 **IIT Madras*



 Music washes away from the soul the dust of everyday life
 -

 --
 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 array question

2011-08-15 Thread Puneet Gautam
I think this may work..!!

Sort the input array first, extract each no.s first digit and put them
in another array..
Then compare each element of new array  with fist digit of main
array.. and then concatenate the found ones to a string...

eg:if input a[]=34,567,87,98,33,1, new array b[]={3,5,8,9,3,1}

after sorting both arrays..
we get a[]={567,87,98,34,23,1} and b[]={9,8,5,3,3,1}

Take each element in b and compare ith first digit of array a , then
put that no. in a new no...
hence largest no=new no proceeds as:

98
9887
9887567
988756734
98875673433
988756734331
hence the result is found..

the algo takes O(n^2) time ..

what say guys..?







On 8/15/11, Ankur Khurana ankur.kkhur...@gmail.com wrote:
 Just a qestion, how do you sort lexographically ? that is tha approach that
 we will apply here.. .and yes the approach is flawed. will come with a
 solution soon..

 On Mon, Aug 15, 2011 at 8:42 AM, Dipankar Patro dip10c...@gmail.com wrote:

 @ Kunal:
 oh. zero is making some nice test cases. I will have to reconsider the
 solution that I provided.


 On 15 August 2011 01:53, Yasir yasir@gmail.com wrote:

 Not Sure! Me too looking for a solution.. :D

 So far,  Kunal's approach (Convert each string to length max_size where
 you append it circularly) seems to be working fine.  :-)

 ..and Chengjie's approach should also work, but the interviewer rejected
 this idea saying, he wants a good logic for this.  :)

  --
 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/-/sRTcLi6r_IYJ.

 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

 --
 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.




 --
 Ankur Khurana
 Computer Science
 Netaji Subhas Institute Of Technology
 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] Re: an array question

2011-08-15 Thread Puneet Gautam
sorry, concatenate the found no in the new no rather than putting it
in the new no...



On 8/15/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 I think this may work..!!

 Sort the input array first, extract each no.s first digit and put them
 in another array..
 Then compare each element of new array  with fist digit of main
 array.. and then concatenate the found ones to a string...

 eg:if input a[]=34,567,87,98,33,1, new array b[]={3,5,8,9,3,1}

 after sorting both arrays..
 we get a[]={567,87,98,34,23,1} and b[]={9,8,5,3,3,1}

 Take each element in b and compare ith first digit of array a , then
 put that no. in a new no...
 hence largest no=new no proceeds as:

 98
 9887
 9887567
 988756734
 98875673433
 988756734331
 hence the result is found..

 the algo takes O(n^2) time ..

 what say guys..?







 On 8/15/11, Ankur Khurana ankur.kkhur...@gmail.com wrote:
 Just a qestion, how do you sort lexographically ? that is tha approach
 that
 we will apply here.. .and yes the approach is flawed. will come with a
 solution soon..

 On Mon, Aug 15, 2011 at 8:42 AM, Dipankar Patro dip10c...@gmail.com
 wrote:

 @ Kunal:
 oh. zero is making some nice test cases. I will have to reconsider the
 solution that I provided.


 On 15 August 2011 01:53, Yasir yasir@gmail.com wrote:

 Not Sure! Me too looking for a solution.. :D

 So far,  Kunal's approach (Convert each string to length max_size where
 you append it circularly) seems to be working fine.  :-)

 ..and Chengjie's approach should also work, but the interviewer
 rejected
 this idea saying, he wants a good logic for this.  :)

  --
 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/-/sRTcLi6r_IYJ.

 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

 --
 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.




 --
 Ankur Khurana
 Computer Science
 Netaji Subhas Institute Of Technology
 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.



[algogeeks] MORGAN CAMPUS VISIT

2011-08-14 Thread Puneet Gautam
Hi everyone, does anyone know how to crack the MORGAN STANLEY written..
Pls helpThanks in advance!!!

-- 
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 array question

2011-08-14 Thread Puneet Gautam
@ankur: No its not radix sort...radix sort would give wrong answer
when the input contains heterogeneous numbered digits in the
array(even when going 4m msd to lsd)...
eg:
32,583,678,1,45,9

Radix sort would give:
9,583,678,45,32,1

whereas the answer has to be:

9,678,543,45,32,1
and hence largest no created is 967854345321

I think thats the way radix sort will work...

Correct me if i m wrong...!


On 8/14/11, Ankur Khurana ankur.kkhur...@gmail.com wrote:
 isn't it a simple question of applying radix sort from most significant to
 least signigicant digit and concatenating all the sorted numbers to get the
 largest number..

 On Sat, Aug 13, 2011 at 11:13 PM, Kunal Patil kp101...@gmail.com wrote:

 Let me clarify.

 Lets take example
 53
 147
 1471470

 As per algo:
 sort 5353535 , 1471471 and 1471470 lexicographically to get answer.
 But You are not going to compare all these simultaneously.
 Might be you will first compare 53 and 147 for lexicographical order. In
 this case you are not required  to calculate till max length.
 In fact while comparing two strings you will require only till (max(len1,
 len2)).
 (verify it !!)
 Comparing 53 and 1471470 doesn't even require till max length.
 Comparing 147 and 1471470 (co-incidentally) requires till max length.
 (worst case !)


 Consider you have only 2 strings.
 Then above code gives lexicographically largest of these two
 (This comparison is considering circular appending).
 You can now use this comparator function as parameter for sort() function
 in c++.
 So given set of strings as the input and this comparator function it will
 sort as per given criteria.

 I mentioned you have to append circularly till largest of all string
 length only for illustration purpose and to make understanding easier.
 Had I mentioned go on comparing each of 2 strings till max(len1,len2), It
 might not be grasped quickly.
 As you can see you will not always require string upto largest length to
 determine lexicographical order of 2 strings.

 I am bad at explaining things. So let me know whether this solved your
 doubt.



 On Sat, Aug 13, 2011 at 10:35 PM, aditi garg
 aditi.garg.6...@gmail.comwrote:

 @ kunal : arent we supposed to construct the string fr each number equal
 to the max length of any number...
 whr r v doing dat chking in dis algo?


 On Sat, Aug 13, 2011 at 10:25 PM, Kunal Patil kp101...@gmail.com wrote:

 I dont know whether this is best approach to do step 2 or not. But it's
 certainly good.


 //I will show for two strings s1 and s2

 len1 = s1.length();
 len2 = s2.length();
 ind1 = 0; //Index in the first string
 ind2 = 0; //Index in the second string

 while( ind1len1 ||  ind2  len2 ) //Match until both strings exhaust or
 function returns
 {
 if(ind1 == len1)  // String s1 has exhausted, so start over it
 ind1 = 0;

 if(ind2 == len2)  // String s2 has exhausted, so start over it
 ind2 = 0;

 for(; ind1  len1  ind2 len2; ind1++,ind2++ )
 // Go on comparing until any of the string exhausts or function returns
 {
 if( s1[ind1] == s2[ind2] ) //Same current char in both string so we need
 to match more char
 continue;
 else // mismatch
 return (s1[ind1]  s2 [ind2] );
 }
 }

 if (ind1==len1  ind2==len2) // same strings
 return true;

 //If I missed anything in the code, let me know


 On Sat, Aug 13, 2011 at 9:29 PM, aditi garg
 aditi.garg.6...@gmail.comwrote:

 @kunal: what is the best way to implement step 2?


 On Sat, Aug 13, 2011 at 7:33 PM, Ashish Sachdeva 
 ashish.asachd...@gmail.com wrote:

 @kunal: seems fine.. tried it on some cases...


 On Sat, Aug 13, 2011 at 5:17 PM, Kunal Patil
 kp101...@gmail.comwrote:

 Following approach should work:

 1)  Count max number of digit in any integer of input. Let it be m.
 (Thanks to dave..)

 2) For each int having less than m digits:
   Convert it to string of length m where you append circularly.
   For e.g. if m=5
53 -- 53535
100 -- 10010
34343 -- 34343
8 -- 8

 3) Now lexicographically sort all those strings. Apply same
 permutations to first array of integers. (again, thanx to Dave)

 4) Concatenate integers of first array.

 For e.g.
 8   53   147  159  1471470   71
 m=7
 corresponding string array becomes:
 888
 5353535
 1471471
 1591591
 1471470
 7171717

 Apply step 3. This gives int array as 8  71  53  15  147  1471470

 Thus, solution is 87153151471471470.

 Let me know about any counter-examples...

 You can apply tricks in programming language that will allow you to
 save actually calculating these strings.
 For e.g. while comparing two unequal length strings char by char if
 you find chars of str1 have exhausted but not of str2, you can set
 index in
 str1 to start of the str1 and continue comparison.


 On Sat, Aug 13, 2011 at 2:06 PM, Ashish Sachdeva 
 ashish.asachd...@gmail.com wrote:

 @ $: how ll you manage something like this:
 2,3,100,90,10

 2nd array becomes: 200,300,100,900,100
 descendng order: 900,300,200,100,100

 how to 

Re: [algogeeks] Random number

2011-08-07 Thread Puneet Gautam
Hey avoiding collisions using hash table can be real easy :
eg:
if 192 is the no generated let it hash to say index 7 of hash
table...so when it is again generated, it hashes to the same 7th index
of hash table, but we have a non zero value already present at that
index , 192 so we can reject this generated no. and proceed to the
next one..

Whereas in an array , avoiding collision is a really hectic way...u
need to scan all the previously generated no.s for duplicacy...well
that aint gonna run in O(1) time..

So implementing hash table reduces that overhead and runs it in O(1)
time..(it just has to check one if condition)with a bigger
constant.

And moreover, we may even dont want an ordered sequence...just put the
generated no.s in hash table as soon as they are generated...dats it..

then afterwards display that hash table..

Did u get me...?


On 8/7/11, Gaurav Menghani gaurav.mengh...@gmail.com wrote:
 We can have a sorted sequence and display them in random order, but
 that is the same problem. How do we display them in random order? We
 need to have a sequence of random indices, that is the same problem as
 having random numbers, isn't it.

 Moreover, I don't think collisions can be avoided in less than O(n).
 We can have an efficient hash-table, but I am not sure how it can be
 done in O(1) or better.

 On Sat, Aug 6, 2011 at 12:37 PM, Puneet Gautam puneet.nsi...@gmail.com
 wrote:
 I rhink to avoid collisions altogether we should generate an ordered
 sequence , in a dec. or inc. order and
 display them randomly, i mean:

 Let say a[10] contains all the random no.s , map all the 10 indexes to
 a hash table and then display the arrays with the hashed index...

 I think it may work...

 what say..?


 On 8/5/11, Gaurav Menghani gaurav.mengh...@gmail.com wrote:
 1. Get a good seed.
 2. Increase the degree of the polynomial.

 This is no fixed algorithm, if you find that more than T steps have
 passed and a new number has not been generated, you can always change
 the polynomial. And, please remember it is a 'pseudo-random number
 generator'. You can read the theory about PRNGs and LFSRs, all of them
 repeat.

 On Fri, Aug 5, 2011 at 7:14 PM, payel roy smithpa...@gmail.com wrote:
 How do you guarantee termination of your algorithm if duplication occurs
 ??

 On 5 August 2011 18:25, Gaurav Menghani gaurav.mengh...@gmail.com
 wrote:

 You might want to read the theory on Pseudo-Random Number Generators
 [0] and Linear Feedback Shift Register [1]

 The basic way of generating a random number is taking up a polynomial,
 f(x) = ax^n + bx^(n-1) + .. + yx + z, and finding f(i + seed) % N,
 where i is the ith random number you want, and seed can be anything
 random available, for example, you can find the current millisecond
 using time.h functions.

 A simple implementation, without the time thing is below:

 #includeiostream
 using namespace std;

 int poly[10],pn,N,M;
 int get(int seed)
 {
        int t=0;
        for(int i=0;ipn;i++)
        {
                int res=poly[i];
                for(int j=1;j=(i+1);j++) { res = (res*seed); if(res=N)
 res%=N; }
                t+=res;
                if(t=N) t%=N;
        }
        t=(t+seed);
        t%=N;
        return t;
 }

 void setup_prng()
 {
        pn=5;
        poly[0]=2; poly[1]=3; poly[2]=5; poly[3]=7; poly[4]=11;
        N=200; M=100;
 }

 int main()
 {
        setup_prng();
        for(int i=1;i=M;i++)
                coutget(i)endl;
        return 0;
 }

 Whenever there is a collision, you can increment the value passed to
 the random number generator and continue. However, I am not sure how
 to check for collisions in O(1) space.

 [0] http://en.wikipedia.org/wiki/Pseudorandom_number_generator
 [1] http://en.wikipedia.org/wiki/Linear_feedback_shift_register

 On Fri, Aug 5, 2011 at 5:19 PM, payel roy smithpa...@gmail.com wrote:
  Given a range 0-N, generate 'M' random numbers from the range without
  any
  duplication. The space complexity is O(1).
 
  --
  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.
 



 --
 Gaurav Menghani

 --
 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

Re: [algogeeks] Random number

2011-08-07 Thread Puneet Gautam
You may be right..we cant remove collisions in O(1) time...

But hey, hash table is still an effective way..


On 8/8/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 Hey avoiding collisions using hash table can be real easy :
 eg:
 if 192 is the no generated let it hash to say index 7 of hash
 table...so when it is again generated, it hashes to the same 7th index
 of hash table, but we have a non zero value already present at that
 index , 192 so we can reject this generated no. and proceed to the
 next one..

 Whereas in an array , avoiding collision is a really hectic way...u
 need to scan all the previously generated no.s for duplicacy...well
 that aint gonna run in O(1) time..

 So implementing hash table reduces that overhead and runs it in O(1)
 time..(it just has to check one if condition)with a bigger
 constant.

 And moreover, we may even dont want an ordered sequence...just put the
 generated no.s in hash table as soon as they are generated...dats it..

 then afterwards display that hash table..

 Did u get me...?


 On 8/7/11, Gaurav Menghani gaurav.mengh...@gmail.com wrote:
 We can have a sorted sequence and display them in random order, but
 that is the same problem. How do we display them in random order? We
 need to have a sequence of random indices, that is the same problem as
 having random numbers, isn't it.

 Moreover, I don't think collisions can be avoided in less than O(n).
 We can have an efficient hash-table, but I am not sure how it can be
 done in O(1) or better.

 On Sat, Aug 6, 2011 at 12:37 PM, Puneet Gautam puneet.nsi...@gmail.com
 wrote:
 I rhink to avoid collisions altogether we should generate an ordered
 sequence , in a dec. or inc. order and
 display them randomly, i mean:

 Let say a[10] contains all the random no.s , map all the 10 indexes to
 a hash table and then display the arrays with the hashed index...

 I think it may work...

 what say..?


 On 8/5/11, Gaurav Menghani gaurav.mengh...@gmail.com wrote:
 1. Get a good seed.
 2. Increase the degree of the polynomial.

 This is no fixed algorithm, if you find that more than T steps have
 passed and a new number has not been generated, you can always change
 the polynomial. And, please remember it is a 'pseudo-random number
 generator'. You can read the theory about PRNGs and LFSRs, all of them
 repeat.

 On Fri, Aug 5, 2011 at 7:14 PM, payel roy smithpa...@gmail.com wrote:
 How do you guarantee termination of your algorithm if duplication
 occurs
 ??

 On 5 August 2011 18:25, Gaurav Menghani gaurav.mengh...@gmail.com
 wrote:

 You might want to read the theory on Pseudo-Random Number Generators
 [0] and Linear Feedback Shift Register [1]

 The basic way of generating a random number is taking up a
 polynomial,
 f(x) = ax^n + bx^(n-1) + .. + yx + z, and finding f(i + seed) % N,
 where i is the ith random number you want, and seed can be anything
 random available, for example, you can find the current millisecond
 using time.h functions.

 A simple implementation, without the time thing is below:

 #includeiostream
 using namespace std;

 int poly[10],pn,N,M;
 int get(int seed)
 {
        int t=0;
        for(int i=0;ipn;i++)
        {
                int res=poly[i];
                for(int j=1;j=(i+1);j++) { res = (res*seed);
 if(res=N)
 res%=N; }
                t+=res;
                if(t=N) t%=N;
        }
        t=(t+seed);
        t%=N;
        return t;
 }

 void setup_prng()
 {
        pn=5;
        poly[0]=2; poly[1]=3; poly[2]=5; poly[3]=7; poly[4]=11;
        N=200; M=100;
 }

 int main()
 {
        setup_prng();
        for(int i=1;i=M;i++)
                coutget(i)endl;
        return 0;
 }

 Whenever there is a collision, you can increment the value passed to
 the random number generator and continue. However, I am not sure how
 to check for collisions in O(1) space.

 [0] http://en.wikipedia.org/wiki/Pseudorandom_number_generator
 [1] http://en.wikipedia.org/wiki/Linear_feedback_shift_register

 On Fri, Aug 5, 2011 at 5:19 PM, payel roy smithpa...@gmail.com
 wrote:
  Given a range 0-N, generate 'M' random numbers from the range
  without
  any
  duplication. The space complexity is O(1).
 
  --
  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.
 



 --
 Gaurav Menghani

 --
 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

Re: [algogeeks] Re: C question.. increment decrement operator..

2011-08-07 Thread Puneet Gautam
@ Amit: Well, the link you have posted refers that i++*i++ is not an
invalid expression, it just runs differently on different OS's because
every OS has a different implementation on how to solve such
expressions that use the same address space(Address of the integer i).

As far as i know the value of a variable can be increased multiple
times on most OS's ... i have tried it on TUrbo running on WIN 95 as
well as Dev Cpp on WIN 7 OS.

Though it may give different output on Unix OS's like Linux but:\

 Hey, we can only predict the output as we see is apt as far as we
have learnt in books.

And the output in my first post does the processing the bookish way...

BUT THE CODE WILL NOT GIVE ANY ERROR !!!



On 8/3/11, Arun toarunb...@gmail.com wrote:

 What Amit told is exactly correct. But I would like to know the
 expression evaluation order of this in gcc and turboc


 Arun
 On Aug 3, 6:15 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
 @amit:+1

 On Wed, Aug 3, 2011 at 3:14 PM, amit karmakar
 amit.codenam...@gmail.comwrote:







  You are wrong.
  The above program invokes undefined behavior. Read the standard
  language draft to know about sequence points, side effects and
  undefined behavior.

  Between a previous and next sequence point a variable's value cannot
  be modified twice.
  c-faq should be quite useful
 http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr
   On Aug 3, 5:20 pm, Puneet Gautam puneet.nsi...@gmail.com wrote:
   As we know:
                        In an expression, if pre n post occur
   simultaneously, pre inc the value then n there only n post executes it
   after that expression...and expression evaluates right to left...

    Also, the value of a variable in  an expression can be modified
   multifold times...there is no restriction on dat...

   Here in this code:
   Print statement No.:

   1.  i++*i++ is equivalent to:
            output i*i(7*7)
          followed by
   i=i+1;
   i=i+1;
   prior to 2nd printf statement..that makes i=9

   2. i++*++i
       expn. evaluates right to left: i inc. by one due to pre..
   i is now 10 .
   output i*i(10*10)
   i=i+1 (due to post inc., it inc. the value after the output)
    i is now 11

   3. ++i*i++
        right to left evaluation, but post inc. increases value only
   after
  output..
   coming to ++i in the expn., i inc. to 12
   output: 12*12
   i=i+1(due to postinc.)
    i is now 13

   4. ++i*++i
   both pre inc operators, order of evaluation doesnt ,matter:
   i=i+1
   i=i+1
   output: 15*15

   i finishes at 15

   Hence the output:
   49
   100
   144
   225

   I think i made it clear..
   Feel free to point any loopholes..

   Thanks.

    On 8/3/11, ankit sambyal ankitsamb...@gmail.com wrote:

Its compiler dependent. Acc. to the C standard an object's stored
value
  can
be modified only once in an expression.

--
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: C question.. increment decrement operator..

2011-08-07 Thread Puneet Gautam
Also guys, this link:
http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr

discusses erroneous expns like
a[i]=i++;

But if u run this code..this gives no error on GNU compiler..

So, are we really referring to a reliable document here..?
http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr

I really doubt that...!

Run it on as many different systems as you can...!

Lets c what all results we get...!!

Pls give ur feedback...

On 8/8/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @ Amit: Well, the link you have posted refers that i++*i++ is not an
 invalid expression, it just runs differently on different OS's because
 every OS has a different implementation on how to solve such
 expressions that use the same address space(Address of the integer i).

 As far as i know the value of a variable can be increased multiple
 times on most OS's ... i have tried it on TUrbo running on WIN 95 as
 well as Dev Cpp on WIN 7 OS.

 Though it may give different output on Unix OS's like Linux but:\

  Hey, we can only predict the output as we see is apt as far as we
 have learnt in books.

 And the output in my first post does the processing the bookish way...

 BUT THE CODE WILL NOT GIVE ANY ERROR !!!



 On 8/3/11, Arun toarunb...@gmail.com wrote:

 What Amit told is exactly correct. But I would like to know the
 expression evaluation order of this in gcc and turboc


 Arun
 On Aug 3, 6:15 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
 @amit:+1

 On Wed, Aug 3, 2011 at 3:14 PM, amit karmakar
 amit.codenam...@gmail.comwrote:







  You are wrong.
  The above program invokes undefined behavior. Read the standard
  language draft to know about sequence points, side effects and
  undefined behavior.

  Between a previous and next sequence point a variable's value cannot
  be modified twice.
  c-faq should be quite useful
 http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr
   On Aug 3, 5:20 pm, Puneet Gautam puneet.nsi...@gmail.com wrote:
   As we know:
                        In an expression, if pre n post occur
   simultaneously, pre inc the value then n there only n post executes
   it
   after that expression...and expression evaluates right to left...

    Also, the value of a variable in  an expression can be modified
   multifold times...there is no restriction on dat...

   Here in this code:
   Print statement No.:

   1.  i++*i++ is equivalent to:
            output i*i(7*7)
          followed by
   i=i+1;
   i=i+1;
   prior to 2nd printf statement..that makes i=9

   2. i++*++i
       expn. evaluates right to left: i inc. by one due to pre..
   i is now 10 .
   output i*i(10*10)
   i=i+1 (due to post inc., it inc. the value after the output)
    i is now 11

   3. ++i*i++
        right to left evaluation, but post inc. increases value only
   after
  output..
   coming to ++i in the expn., i inc. to 12
   output: 12*12
   i=i+1(due to postinc.)
    i is now 13

   4. ++i*++i
   both pre inc operators, order of evaluation doesnt ,matter:
   i=i+1
   i=i+1
   output: 15*15

   i finishes at 15

   Hence the output:
   49
   100
   144
   225

   I think i made it clear..
   Feel free to point any loopholes..

   Thanks.

    On 8/3/11, ankit sambyal ankitsamb...@gmail.com wrote:

Its compiler dependent. Acc. to the C standard an object's stored
value
  can
be modified only once in an expression.

--
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] difference between the two

2011-08-07 Thread Puneet Gautam
How do u define size of compiler...?


On 8/6/11, SANDEEP CHUGH sandeep.aa...@gmail.com wrote:
 @ sid : can u please elaborate considering these parameters

 1 size of compiler
 2 size of os and
 3 size of processor

 please explain for any case, considering these three parameters and tell me
 how these parameters do affect..

 ty

 On Sat, Aug 6, 2011 at 9:53 PM, siddharth srivastava
 akssps...@gmail.comwrote:



 On 6 August 2011 21:50, siddharth srivastava akssps...@gmail.com wrote:

 Hi

 On 6 August 2011 20:20, SANDEEP CHUGH sandeep.aa...@gmail.com wrote:

 padding wud be between int  char..(for ur last case)

 now u said if it starts at 4 , still the block will be 8 (size of
 double), that is 7 bytes to be padded..

 so double element of structure would be starting at 4 + char(1) + 7 byte
 padding  ==12

 but 12 is not a multiple of 8..


 the whole concept is about the alignment and word size.
 If word size is 4( 32 bit m/c) then the memory allocation would start at
 a
 multiple of 4 and if it is 8 , then the memory allocation would start at
 a
 multiple of 8.
 Moreover, the explaination I gave above hold for 64 bit architecture.
 For 32 bit architecture a double is 8 bytes aligned

 just a correction:
 on gcc, double is 4 bytes aligned


 but the word size is 4 bytes, so for a structure like this

  struct a
 {
 double d;
 int i;
 }

 the size would be 12 (on 32 bit) and 16 (on 64 bit)


 the result are for linux(gcc) system



 so there is a problem??






 On Sat, Aug 6, 2011 at 8:06 PM, siddharth srivastava 
 akssps...@gmail.com wrote:

  but if the reference is not 0 .. if it wud have been 4 then for tht
 case tell me do we really need that 7 bytes??


 yes, because in any case the block would be of 8 bytes only
 so even if you start at 4, you would have only 7 bytes left in that
 location for the next variable(which in this case is a double of 8
 bytes, so
 the allocation would start at the 8th byte from the first location)

 Look at the following stack: X represents occupied memory, - represents
 the memory to be padded (in bytes)

 X - - - - - - -
 
  - - - -

 So, first char occupies 1 byte, then there are only 7 bytes left at
 that
 index, which are not enough for a double to be stored (got my point)
 Moreover, if you had
 struct a{
 char c;
 int i;
 double d;
 }

 then the size would have been 16

 as after allocating a char, there was enough space for an int to be
 stored. (just not sure if padding would be after int or between int and
 char)





 and yeah it is dependent on compiler size..
 if u compile this snippet

 struct demo
 {
char   c;
double  d;
int s;

 }


 in turbo c , its giving 11,, that means compiler nt doing padding at
 all in turbo c..

 On Sat, Aug 6, 2011 at 7:50 PM, siddharth srivastava 
 akssps...@gmail.com wrote:

 Hi Sandeep

 On 6 August 2011 19:16, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 take this case

 struct demo
 {
char   c;
double  d;
int s;

 }


 what wud be the size??


 solution is 24 according to following:--

 char (1) + 7 byte padding +double(8)+int(4)+ 4 byte padding


 suppose address starts at 4..

  i just wanna ask .. why there is 7 byte padding.. because just
 after 3 bytes padding after char we are getting address that is
 multiple of
 8(size of largest)..



 after 3 bytes of padding i.e. the 4th byte(if reference is 0), is not
 a multiple of 8.
 Moreover, try understanding with this example:
 visualize a stack of memory with each location having the size of the
 largest sized variable in the structure.
 So in your case, each stack element is ought to be 8 bytes (due to
 double)
 Now, when first character is allocated, we have only 7 bytes left at
 that location in the stack, hence double has to be allocated in the
 next
 location.i.e. 2nd stack element and 8th byte (again reference 0)

 So total size is ought to be occupied is 24 in this case


 say if you had this declaration:
 struct a
 {
 char a;
 double d;
 int c;
 int e;
 }

 then too size would have been 24 as after allocation of int c, we
 still have 4 bytes in the same location which are then occupied by e
 (and
 were padded in previous case)

 Let me know, if I am not clear.

 @All
 Is it really architecture dependent (32 bit or 64 bit) ?




 can u please tell me??



 --
 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
 Siddharth Srivastava


  --
 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 

Re: [algogeeks] Re: Probability Puzzle

2011-08-07 Thread Puneet Gautam
Sixth toss is independent of previous tosses and dependent only on
coin selection...!

1/5 + 4/5(1/2)= 3/5

is the correct answer

we want to calc. probability of getting heads the sixth time only
even if it would have been 100 th time...3/5 would be the answer
only..


On 8/8/11, Prakash D cegprak...@gmail.com wrote:
 1.) coin is fair
 2.) coin is unfair

 P(head) for unfair coin= 1/5 * 1= 1/5
 P(head) for fair coin= 4/5* 1/2 = 2/5


 the probability at any instant that the tossed coin is a head is 3/5

 17/80 is the probability to get head at all the six times.

 the soln. for this problem will be 3/5

 On Mon, Aug 8, 2011 at 12:45 AM, aseem garg ase.as...@gmail.com wrote:

 If the coin is unbiased then probability of heads: 1/2 irrespective of
 whether it is first time or nth time. So answer should be 3/5.
 Aseem



 On Mon, Aug 8, 2011 at 12:39 AM, saurabh chhabra
 saurabh131...@gmail.comwrote:

 Even u dont get why u people are gettin 17/80...the probability that
 it will be a head 6th time will be same as the frst time...so it shud
 be 3/5...

 On Aug 7, 11:05 pm, Kunal Yadav kunalyada...@gmail.com wrote:
  @algo: We can get head in two cases:-
 
  1.) coin is biases
  2.) coin is not biased
 
  P(head) for biased= 1/5 *1*1*1*1*1*1= 1/5
  P(head) for unbiased= 4/5*(1/2)^6
  hence combined probability is what nitish has already mentioned. Hope
 you
  get the point.
 
 
 
 
 
 
 
 
 
  On Sun, Aug 7, 2011 at 11:29 PM, Algo Lover algolear...@gmail.com
 wrote:
   Can anyone explain the approach how to solve this .
   I think all tosses are independent so it should be 3/5. why is this
 in-
   correct
 
   On Aug 7, 10:55 pm, saurabh chhabra saurabh131...@gmail.com wrote:
sry...its wrong
 
On Aug 7, 10:34 pm, Algo Lover algolear...@gmail.com wrote:
 
 A bag contains 5 coins. Four of them are fair and one has heads
 on
 both sides. You randomly pulled one coin from the bag and tossed
 it 5
 times, heads turned up all five times. What is the probability
 that
 you toss next time, heads turns up. (All this time you don't know
 you
 were tossing a fair coin or not).
 
   --
   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
  Kunal Yadav
  (http://algoritmus.in/)

 --
 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: Probability Puzzle

2011-08-07 Thread Puneet Gautam
abe yaar kya farak padta hai... 3/5=0.6 , other one may be 0.4 ya 0.3,

 0.3 ke difference ke liye lad rahe ho...

Chill guys...

On 8/8/11, Shuaib Khan aries.shu...@gmail.com wrote:
 On Mon, Aug 8, 2011 at 12:51 AM, aseem garg ase.as...@gmail.com wrote:

 @Shuaib:  **What is the probability that you toss *next time, heads turns
 up***.


 Well if you interpret it your way, then you are right. Otherwise, not.


 Aseem



 On Mon, Aug 8, 2011 at 1:19 AM, Shuaib Khan aries.shu...@gmail.comwrote:



 On Mon, Aug 8, 2011 at 12:47 AM, aseem garg ase.as...@gmail.com wrote:

 Think it like this. I have tossed a coin 5 times and it showed heads all
 the times. What is the probabilty of it shoing a HEADS now?
 Aseem


 Well you are thinking about it the wrong way. Question asks that what is
 the probability that heads will show up the first five times, plus a
 sixth
 time. Not just the sixth time. The first five times head showing up is
 part
 of the question.






 On Mon, Aug 8, 2011 at 1:12 AM, Shuaib Khan
 aries.shu...@gmail.comwrote:



 On Mon, Aug 8, 2011 at 12:40 AM, Puneet Gautam puneet.nsi...@gmail.com
  wrote:

 Sixth toss is independent of previous tosses and dependent only on
 coin selection...!

 1/5 + 4/5(1/2)= 3/5

 is the correct answer

 we want to calc. probability of getting heads the sixth time only
 even if it would have been 100 th time...3/5 would be the answer
 only..


 It is not independent. Re read the question. The first five times, it
 HAS to be heads.


 On 8/8/11, Prakash D cegprak...@gmail.com wrote:
  1.) coin is fair
  2.) coin is unfair
 
  P(head) for unfair coin= 1/5 * 1= 1/5
  P(head) for fair coin= 4/5* 1/2 = 2/5
 
 
  the probability at any instant that the tossed coin is a head is 3/5
 
  17/80 is the probability to get head at all the six times.
 
  the soln. for this problem will be 3/5
 
  On Mon, Aug 8, 2011 at 12:45 AM, aseem garg ase.as...@gmail.com
 wrote:
 
  If the coin is unbiased then probability of heads: 1/2 irrespective
 of
  whether it is first time or nth time. So answer should be 3/5.
  Aseem
 
 
 
  On Mon, Aug 8, 2011 at 12:39 AM, saurabh chhabra
  saurabh131...@gmail.comwrote:
 
  Even u dont get why u people are gettin 17/80...the probability
 that
  it will be a head 6th time will be same as the frst time...so it
 shud
  be 3/5...
 
  On Aug 7, 11:05 pm, Kunal Yadav kunalyada...@gmail.com wrote:
   @algo: We can get head in two cases:-
  
   1.) coin is biases
   2.) coin is not biased
  
   P(head) for biased= 1/5 *1*1*1*1*1*1= 1/5
   P(head) for unbiased= 4/5*(1/2)^6
   hence combined probability is what nitish has already mentioned.
 Hope
  you
   get the point.
  
  
  
  
  
  
  
  
  
   On Sun, Aug 7, 2011 at 11:29 PM, Algo Lover 
 algolear...@gmail.com
  wrote:
Can anyone explain the approach how to solve this .
I think all tosses are independent so it should be 3/5. why is
 this
  in-
correct
  
On Aug 7, 10:55 pm, saurabh chhabra saurabh131...@gmail.com
 wrote:
 sry...its wrong
  
 On Aug 7, 10:34 pm, Algo Lover algolear...@gmail.com
 wrote:
  
  A bag contains 5 coins. Four of them are fair and one has
 heads
  on
  both sides. You randomly pulled one coin from the bag and
 tossed
  it 5
  times, heads turned up all five times. What is the
 probability
  that
  you toss next time, heads turns up. (All this time you
 don't know
  you
  were tossing a fair coin or not).
  
--
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
   Kunal Yadav
   (http://algoritmus.in/)
 
  --
  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

[algogeeks] Time complexity

2011-08-06 Thread Puneet Gautam
Its quite long... but its simple...
pls tell me its worst case time complexity..!!!

#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
int check(char *p,int n)// this function checks for pallindromicity of
the string passed.
{
   char a[100],b[100];
   int k;
   for(k=0;k=n;k++)
   b[k]=(p[k]);
   b[k]=NULL;
   for(k=0;k=n;k++)
   a[k]=(b[n-k]);
   a[k]=NULL;
   k=strcmp(a,b);
   printf(\n%s %s,%d,b,a,k);
   return k;
   }

main()
{
 char str[100];
 scanf(%s,str);
 int N,cuts=0,i=0,j,r,index,pall[10],k=0;
 N=strlen(str);
 while(iN)
 {   printf(\nHere);
 for(j=N-1;ji;)
 {
   if(str[i]==str[j])
   {
   if((r=check((str[i]),(j-i)))==0)
{if(j==N-1)
   { cuts=-1;j=N;
printf(Cuts=0);.//string itself is pallindrome
 getch();   exit(0);
}
   else{
 cuts++;
pall[k]=i;
 pall[k+1]=j;
 i=j+1;
 j=N-1;
   k+=2;   continue;}
  }
}
 j--;
 }
 i++;
 }
 if(cuts==0)
printf(\nMinimum cuts=%d,N-1);
 else
 {
 for(i=0;ik;i++)
printf(\n%d,pall[i]);
 cuts+=(pall[0]-0);
 for(i=0;ik;i+=2)
cuts+=(pall[i+2]-pall[i+1]);
 cuts+=(N-pall[k]-2);
 printf(\n Cuts=%d,cuts);
 }
 getch();
 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.



Re: [algogeeks] difference between the two

2011-08-06 Thread Puneet Gautam
There is no difference between the two...

On 32 bit system, both structures need every address location where
int and pointer are stored to be a multiple of 4(highest size is 4)..

On 64 bit,
even if pointer is 4bytes(say, in 64 bit system), and p1, p2 be
structure variables, then p2 should start at address which is multiple
of 8 as int data is 8bytes. So, if p1 starts at 0, it should end at 16
not 12 so that p2 starts at 8's multiple.

This is done by padding pointer by 4bytes in both I and II struct. declarations.


Hope i made it clear...!

Thanks.




On 8/6/11, Tushar Bindal tushicom...@gmail.com wrote:
 http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/xlf/html/xlfug/ug35.htm
 this says int is always 4 bytes and pointer is 8 bytes on 64 bit compiler.

 so how does padding affect these structures because of the difference in
 size of int and pointer?


 I tried this program
 https://ideone.com/CRU6x#view_edit_box
 char always gets 4 bytes whenever it has int or double in the same struct
 irrrespctive of the order of the declaration of variables.
 I thought char should get size 8 when there is a double in the ame struct
 whereas it gets size 4 only.
 what is the problem here?

 On Sat, Aug 6, 2011 at 4:40 AM, Shashank Jain shashan...@gmail.com wrote:

 i dont understand the diff btw dem, could u plz elaborate?

 Shashank Jain
 IIIrd year
 Computer Engineering
 Delhi College of Engineering



 On Sat, Aug 6, 2011 at 12:32 AM, Kamakshii Aggarwal kamakshi...@gmail.com
  wrote:

 in case of 64 bit,
 size of second structure will also be 16 not 8


 On Fri, Aug 5, 2011 at 11:40 PM, UTKARSH SRIVASTAV 
 usrivastav...@gmail.com wrote:

 I think voth are just same..


 On Fri, Aug 5, 2011 at 10:57 AM, priya v pria@gmail.com wrote:

 in case of 64 bit machine y doesn't padding happen in the 2nd
 structure?


 On Fri, Aug 5, 2011 at 11:21 PM, hary rathor
 harry.rat...@gmail.comwrote:

 no ,if u r using 32 bit machine . that will use 4 byte pointer size ,
 but   in 64 machine that enforce to be size of 8 . where padding will
 take int your given first structure

 so for 32 bit- size will 8 8 for both structure
 for 64 bit - size will 16 and 12 respectively cause of 4 bit padding
 in
 one structure

 hence 2nd structure is good for use

 --
 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.




 --
 *UTKARSH SRIVASTAV
 CSE-3
 B-Tech 2nd 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.




 --
 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.




 --
 Tushar Bindal
 Computer Engineering
 Delhi College of Engineering
 Mob: +919818442705
 E-Mail : tushicom...@gmail.com
 Website: www.jugadengg.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 

Re: [algogeeks] difference between the two

2011-08-06 Thread Puneet Gautam
Sorry guys, int is 4 bytes on 64 bit and 2 bytes on 32 bit system..

But padding rule remains same for both structures as mentioned above...




On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 There is no difference between the two...

 On 32 bit system, both structures need every address location where
 int and pointer are stored to be a multiple of 4(highest size is 4)..

 On 64 bit,
 even if pointer is 4bytes(say, in 64 bit system), and p1, p2 be
 structure variables, then p2 should start at address which is multiple
 of 8 as int data is 8bytes. So, if p1 starts at 0, it should end at 16
 not 12 so that p2 starts at 8's multiple.

 This is done by padding pointer by 4bytes in both I and II struct.
 declarations.


 Hope i made it clear...!

 Thanks.




 On 8/6/11, Tushar Bindal tushicom...@gmail.com wrote:
 http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/xlf/html/xlfug/ug35.htm
 this says int is always 4 bytes and pointer is 8 bytes on 64 bit
 compiler.

 so how does padding affect these structures because of the difference in
 size of int and pointer?


 I tried this program
 https://ideone.com/CRU6x#view_edit_box
 char always gets 4 bytes whenever it has int or double in the same struct
 irrrespctive of the order of the declaration of variables.
 I thought char should get size 8 when there is a double in the ame struct
 whereas it gets size 4 only.
 what is the problem here?

 On Sat, Aug 6, 2011 at 4:40 AM, Shashank Jain shashan...@gmail.com
 wrote:

 i dont understand the diff btw dem, could u plz elaborate?

 Shashank Jain
 IIIrd year
 Computer Engineering
 Delhi College of Engineering



 On Sat, Aug 6, 2011 at 12:32 AM, Kamakshii Aggarwal
 kamakshi...@gmail.com
  wrote:

 in case of 64 bit,
 size of second structure will also be 16 not 8


 On Fri, Aug 5, 2011 at 11:40 PM, UTKARSH SRIVASTAV 
 usrivastav...@gmail.com wrote:

 I think voth are just same..


 On Fri, Aug 5, 2011 at 10:57 AM, priya v pria@gmail.com wrote:

 in case of 64 bit machine y doesn't padding happen in the 2nd
 structure?


 On Fri, Aug 5, 2011 at 11:21 PM, hary rathor
 harry.rat...@gmail.comwrote:

 no ,if u r using 32 bit machine . that will use 4 byte pointer size
 ,
 but   in 64 machine that enforce to be size of 8 . where padding
 will
 take int your given first structure

 so for 32 bit- size will 8 8 for both structure
 for 64 bit - size will 16 and 12 respectively cause of 4 bit padding
 in
 one structure

 hence 2nd structure is good for use

 --
 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.




 --
 *UTKARSH SRIVASTAV
 CSE-3
 B-Tech 2nd 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.




 --
 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.




 --
 Tushar Bindal
 Computer Engineering
 Delhi College of Engineering
 Mob: +919818442705
 E-Mail : tushicom...@gmail.com
 Website: www.jugadengg.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

Re: [algogeeks] difference between the two

2011-08-06 Thread Puneet Gautam
See guys.. the order is important but the size of whole structure
needs to be a multiple of its largest sized variable...
eg:

struct p
{
double data;
char a;
char b;
char c;
char d;
}t;


struct q
{char c;
char d;
double data;
char a;
char b;
}t1;

sizeof(t)=16
sizeof(t1)=24

This can be explained:Lets say address starts at 0

In q structure, c and d take one byte each so data starts at 3 but it
cant start at 3 (not its size multiple)...
so double data starts at 8, leaving all 3-7 positions padded to char c and d

double ends at 16 so char a and b occupy 17 and 18 addresses.

But if next structure variable starts, it wud have to start at 19
which is not 8's multiple..

So , char a and b are padded till address 23 and hence next structure
variable can start at 24..(8 * 3)

Hence t1's size =24, neither 19 nor 12...

Similarly, we can account for structure p's variable t..t=16
bytes(char a,b,c,d occupy 4bytes, get padded upto 7 and double then
starts at 8 upto 15, next variable starts at 16..)

Am i clear...???



On 8/6/11, Nitish Garg nitishgarg1...@gmail.com wrote:
 I think that the order is important. Because when we consider an array of
 structures the order becomes extremely important just as shown in the above
 example.

 On Sat, Aug 6, 2011 at 6:18 PM, Prashant Gupta
 prashantatn...@gmail.comwrote:

 Interesting :
 #includeiostream
 using namespace std;
 int main()
 {
 struct p{
 int i;
 char j;
 char k;
 };
 struct q{
 char j;
 int i;
 char k;
 };
 printf(p=%u q=%u,sizeof(p),sizeof(q));
 return 0;
 }
 o/p : p=8 q=12

 On Sat, Aug 6, 2011 at 2:55 PM, Tushar Bindal
 tushicom...@gmail.comwrote:

 that means the order is immaterial.
 the sizeof the struct always remains same irrespective of the order and
 just depends on the type of variables???
 why char with double does not get size in multiples of 8??


 On Sat, Aug 6, 2011 at 12:54 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Sorry guys, int is 4 bytes on 64 bit and 2 bytes on 32 bit system..

 But padding rule remains same for both structures as mentioned above...




 On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
  There is no difference between the two...
 
  On 32 bit system, both structures need every address location where
  int and pointer are stored to be a multiple of 4(highest size is 4)..
 
  On 64 bit,
  even if pointer is 4bytes(say, in 64 bit system), and p1, p2 be
  structure variables, then p2 should start at address which is multiple
  of 8 as int data is 8bytes. So, if p1 starts at 0, it should end at 16
  not 12 so that p2 starts at 8's multiple.
 
  This is done by padding pointer by 4bytes in both I and II struct.
  declarations.
 
 
  Hope i made it clear...!
 
  Thanks.
 
 
 
 
  On 8/6/11, Tushar Bindal tushicom...@gmail.com wrote:
 
 http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/xlf/html/xlfug/ug35.htm
  this says int is always 4 bytes and pointer is 8 bytes on 64 bit
  compiler.
 
  so how does padding affect these structures because of the difference
 in
  size of int and pointer?
 
 
  I tried this program
  https://ideone.com/CRU6x#view_edit_box
  char always gets 4 bytes whenever it has int or double in the same
 struct
  irrrespctive of the order of the declaration of variables.
  I thought char should get size 8 when there is a double in the ame
 struct
  whereas it gets size 4 only.
  what is the problem here?
 
  On Sat, Aug 6, 2011 at 4:40 AM, Shashank Jain shashan...@gmail.com
  wrote:
 
  i dont understand the diff btw dem, could u plz elaborate?
 
  Shashank Jain
  IIIrd year
  Computer Engineering
  Delhi College of Engineering
 
 
 
  On Sat, Aug 6, 2011 at 12:32 AM, Kamakshii Aggarwal
  kamakshi...@gmail.com
   wrote:
 
  in case of 64 bit,
  size of second structure will also be 16 not 8
 
 
  On Fri, Aug 5, 2011 at 11:40 PM, UTKARSH SRIVASTAV 
  usrivastav...@gmail.com wrote:
 
  I think voth are just same..
 
 
  On Fri, Aug 5, 2011 at 10:57 AM, priya v pria@gmail.com
 wrote:
 
  in case of 64 bit machine y doesn't padding happen in the 2nd
  structure?
 
 
  On Fri, Aug 5, 2011 at 11:21 PM, hary rathor
  harry.rat...@gmail.comwrote:
 
  no ,if u r using 32 bit machine . that will use 4 byte pointer
 size
  ,
  but   in 64 machine that enforce to be size of 8 . where padding
  will
  take int your given first structure
 
  so for 32 bit- size will 8 8 for both structure
  for 64 bit - size will 16 and 12 respectively cause of 4 bit
 padding
  in
  one structure
 
  hence 2nd structure is good for use
 
  --
  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

Re: [algogeeks] difference between the two

2011-08-06 Thread Puneet Gautam
Order is important ... but in the main case here which is

 1) struct list
{
   int data;
   list *next;
   }
and
2) struct list
{
   list *next;
   int data;
   }
order is not affecting its size...!!

On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 See guys.. the order is important but the size of whole structure
 needs to be a multiple of its largest sized variable...
 eg:

 struct p
 {
 double data;
 char a;
 char b;
 char c;
 char d;
 }t;


 struct q
 {char c;
 char d;
 double data;
 char a;
 char b;
 }t1;

 sizeof(t)=16
 sizeof(t1)=24

 This can be explained:Lets say address starts at 0

 In q structure, c and d take one byte each so data starts at 3 but it
 cant start at 3 (not its size multiple)...
 so double data starts at 8, leaving all 3-7 positions padded to char c and
 d

 double ends at 16 so char a and b occupy 17 and 18 addresses.

 But if next structure variable starts, it wud have to start at 19
 which is not 8's multiple..

 So , char a and b are padded till address 23 and hence next structure
 variable can start at 24..(8 * 3)

 Hence t1's size =24, neither 19 nor 12...

 Similarly, we can account for structure p's variable t..t=16
 bytes(char a,b,c,d occupy 4bytes, get padded upto 7 and double then
 starts at 8 upto 15, next variable starts at 16..)

 Am i clear...???



 On 8/6/11, Nitish Garg nitishgarg1...@gmail.com wrote:
 I think that the order is important. Because when we consider an array of
 structures the order becomes extremely important just as shown in the
 above
 example.

 On Sat, Aug 6, 2011 at 6:18 PM, Prashant Gupta
 prashantatn...@gmail.comwrote:

 Interesting :
 #includeiostream
 using namespace std;
 int main()
 {
 struct p{
 int i;
 char j;
 char k;
 };
 struct q{
 char j;
 int i;
 char k;
 };
 printf(p=%u q=%u,sizeof(p),sizeof(q));
 return 0;
 }
 o/p : p=8 q=12

 On Sat, Aug 6, 2011 at 2:55 PM, Tushar Bindal
 tushicom...@gmail.comwrote:

 that means the order is immaterial.
 the sizeof the struct always remains same irrespective of the order and
 just depends on the type of variables???
 why char with double does not get size in multiples of 8??


 On Sat, Aug 6, 2011 at 12:54 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Sorry guys, int is 4 bytes on 64 bit and 2 bytes on 32 bit system..

 But padding rule remains same for both structures as mentioned
 above...




 On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
  There is no difference between the two...
 
  On 32 bit system, both structures need every address location where
  int and pointer are stored to be a multiple of 4(highest size is
  4)..
 
  On 64 bit,
  even if pointer is 4bytes(say, in 64 bit system), and p1, p2 be
  structure variables, then p2 should start at address which is
  multiple
  of 8 as int data is 8bytes. So, if p1 starts at 0, it should end at
  16
  not 12 so that p2 starts at 8's multiple.
 
  This is done by padding pointer by 4bytes in both I and II struct.
  declarations.
 
 
  Hope i made it clear...!
 
  Thanks.
 
 
 
 
  On 8/6/11, Tushar Bindal tushicom...@gmail.com wrote:
 
 http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/xlf/html/xlfug/ug35.htm
  this says int is always 4 bytes and pointer is 8 bytes on 64 bit
  compiler.
 
  so how does padding affect these structures because of the
  difference
 in
  size of int and pointer?
 
 
  I tried this program
  https://ideone.com/CRU6x#view_edit_box
  char always gets 4 bytes whenever it has int or double in the same
 struct
  irrrespctive of the order of the declaration of variables.
  I thought char should get size 8 when there is a double in the ame
 struct
  whereas it gets size 4 only.
  what is the problem here?
 
  On Sat, Aug 6, 2011 at 4:40 AM, Shashank Jain
  shashan...@gmail.com
  wrote:
 
  i dont understand the diff btw dem, could u plz elaborate?
 
  Shashank Jain
  IIIrd year
  Computer Engineering
  Delhi College of Engineering
 
 
 
  On Sat, Aug 6, 2011 at 12:32 AM, Kamakshii Aggarwal
  kamakshi...@gmail.com
   wrote:
 
  in case of 64 bit,
  size of second structure will also be 16 not 8
 
 
  On Fri, Aug 5, 2011 at 11:40 PM, UTKARSH SRIVASTAV 
  usrivastav...@gmail.com wrote:
 
  I think voth are just same..
 
 
  On Fri, Aug 5, 2011 at 10:57 AM, priya v pria@gmail.com
 wrote:
 
  in case of 64 bit machine y doesn't padding happen in the 2nd
  structure?
 
 
  On Fri, Aug 5, 2011 at 11:21 PM, hary rathor
  harry.rat...@gmail.comwrote:
 
  no ,if u r using 32 bit machine . that will use 4 byte pointer
 size
  ,
  but   in 64 machine that enforce to be size of 8 . where
  padding
  will
  take int your given first structure
 
  so for 32 bit- size will 8 8 for both structure
  for 64 bit - size will 16 and 12 respectively cause of 4 bit
 padding
  in
  one

Re: [algogeeks] difference between the two

2011-08-06 Thread Puneet Gautam
Well, even in dat case no difference occurs
As far as i know, because we cant predict where its address is going
to start from, in real time i.e. in memory, it will always give u the
same size as output..if u run the code..

So the whole point is that the size comes down to the highest sized
variable in the struct declaration and the order in which the
variables are declared...

The rerference 0 was only for explanation...!

Thanks..

On 8/6/11, SANDEEP CHUGH sandeep.aa...@gmail.com wrote:
 @ puneet :
 tell me the case if u take the address to be starting from 4 not 0..

 On Sat, Aug 6, 2011 at 6:55 PM, SANDEEP CHUGH
 sandeep.aa...@gmail.comwrote:

 @ puneet :  ryt !!  gud explanation.


 On Sat, Aug 6, 2011 at 6:53 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Order is important ... but in the main case here which is

  1) struct list
{
   int data;
   list *next;
   }
 and
 2) struct list
{
   list *next;
   int data;
   }
 order is not affecting its size...!!

 On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
  See guys.. the order is important but the size of whole structure
  needs to be a multiple of its largest sized variable...
  eg:
 
  struct p
  {
  double data;
  char a;
  char b;
  char c;
  char d;
  }t;
 
 
  struct q
  {char c;
  char d;
  double data;
  char a;
  char b;
  }t1;
 
  sizeof(t)=16
  sizeof(t1)=24
 
  This can be explained:Lets say address starts at 0
 
  In q structure, c and d take one byte each so data starts at 3 but it
  cant start at 3 (not its size multiple)...
  so double data starts at 8, leaving all 3-7 positions padded to char c
 and
  d
 
  double ends at 16 so char a and b occupy 17 and 18 addresses.
 
  But if next structure variable starts, it wud have to start at 19
  which is not 8's multiple..
 
  So , char a and b are padded till address 23 and hence next structure
  variable can start at 24..(8 * 3)
 
  Hence t1's size =24, neither 19 nor 12...
 
  Similarly, we can account for structure p's variable t..t=16
  bytes(char a,b,c,d occupy 4bytes, get padded upto 7 and double then
  starts at 8 upto 15, next variable starts at 16..)
 
  Am i clear...???
 
 
 
  On 8/6/11, Nitish Garg nitishgarg1...@gmail.com wrote:
  I think that the order is important. Because when we consider an array
 of
  structures the order becomes extremely important just as shown in the
  above
  example.
 
  On Sat, Aug 6, 2011 at 6:18 PM, Prashant Gupta
  prashantatn...@gmail.comwrote:
 
  Interesting :
  #includeiostream
  using namespace std;
  int main()
  {
  struct p{
  int i;
  char j;
  char k;
  };
  struct q{
  char j;
  int i;
  char k;
  };
  printf(p=%u q=%u,sizeof(p),sizeof(q));
  return 0;
  }
  o/p : p=8 q=12
 
  On Sat, Aug 6, 2011 at 2:55 PM, Tushar Bindal
  tushicom...@gmail.comwrote:
 
  that means the order is immaterial.
  the sizeof the struct always remains same irrespective of the order
 and
  just depends on the type of variables???
  why char with double does not get size in multiples of 8??
 
 
  On Sat, Aug 6, 2011 at 12:54 PM, Puneet Gautam
  puneet.nsi...@gmail.comwrote:
 
  Sorry guys, int is 4 bytes on 64 bit and 2 bytes on 32 bit system..
 
  But padding rule remains same for both structures as mentioned
  above...
 
 
 
 
  On 8/6/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
   There is no difference between the two...
  
   On 32 bit system, both structures need every address location
 where
   int and pointer are stored to be a multiple of 4(highest size is
   4)..
  
   On 64 bit,
   even if pointer is 4bytes(say, in 64 bit system), and p1, p2 be
   structure variables, then p2 should start at address which is
   multiple
   of 8 as int data is 8bytes. So, if p1 starts at 0, it should end
 at
   16
   not 12 so that p2 starts at 8's multiple.
  
   This is done by padding pointer by 4bytes in both I and II
   struct.
   declarations.
  
  
   Hope i made it clear...!
  
   Thanks.
  
  
  
  
   On 8/6/11, Tushar Bindal tushicom...@gmail.com wrote:
  
 
 http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/xlf/html/xlfug/ug35.htm
   this says int is always 4 bytes and pointer is 8 bytes on 64 bit
   compiler.
  
   so how does padding affect these structures because of the
   difference
  in
   size of int and pointer?
  
  
   I tried this program
   https://ideone.com/CRU6x#view_edit_box
   char always gets 4 bytes whenever it has int or double in the
 same
  struct
   irrrespctive of the order of the declaration of variables.
   I thought char should get size 8 when there is a double in the
 ame
  struct
   whereas it gets size 4 only.
   what is the problem here?
  
   On Sat, Aug 6, 2011 at 4:40 AM, Shashank Jain
   shashan...@gmail.com
   wrote:
  
   i dont understand the diff btw dem, could u plz elaborate

Re: [algogeeks] C question.. increment decrement operator..

2011-08-03 Thread Puneet Gautam
As we know:
 In an expression, if pre n post occur
simultaneously, pre inc the value then n there only n post executes it
after that expression...and expression evaluates right to left...

 Also, the value of a variable in  an expression can be modified
multifold times...there is no restriction on dat...

Here in this code:
Print statement No.:

1.  i++*i++ is equivalent to:
 output i*i(7*7)
   followed by
i=i+1;
i=i+1;
prior to 2nd printf statement..that makes i=9

2. i++*++i
expn. evaluates right to left: i inc. by one due to pre..
i is now 10 .
output i*i(10*10)
i=i+1 (due to post inc., it inc. the value after the output)
 i is now 11

3. ++i*i++
 right to left evaluation, but post inc. increases value only after output..
coming to ++i in the expn., i inc. to 12
output: 12*12
i=i+1(due to postinc.)
 i is now 13

4. ++i*++i
both pre inc operators, order of evaluation doesnt ,matter:
i=i+1
i=i+1
output: 15*15

i finishes at 15

Hence the output:
49
100
144
225

I think i made it clear..
Feel free to point any loopholes..

Thanks.



On 8/3/11, ankit sambyal ankitsamb...@gmail.com wrote:
 Its compiler dependent. Acc. to the C standard an object's stored value can
 be modified only once in an expression.

 --
 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: latest google interview questions

2011-08-03 Thread Puneet Gautam
@Utkarsh:
How did u get the intern...?
it cant be ...!!!
Who is the moderator of this group..?
I want this thread be removed immediately from this group...!!! pls do it...


On 8/3/11, kaustubh kaustubh.c...@gmail.com wrote:
 You've got to be kiddin' me...

 On Aug 3, 12:55 am, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote:
 hi I got intern in google ...but i was not able to do some question of
 written paper
 1.
 main()
 {
          printf(hello);}

 OUTPUT-  hello

 Why the output is coming hello?
 2.  Who developed  C language ?
 I gave the answer Yashwant Kanetkarbut the interviewer said it
 was Dennis Ritchie...can anyone please tell me who is Dennis
 Ritchie

 --
 *
 *

 --
 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: random generation

2011-08-01 Thread Puneet Gautam
@Don: How about this below...?

#includestdio.h
int main(int argc,char *argv[])
{
int a;
a=(argv[0]);
printf(%d,a%10);
getchar();
}

To get  a random value b/w 0 to 100,
we can use a%100
and soon for 0-1000.


What say guys..?


On 8/1/11, Don dondod...@gmail.com wrote:
 That's actually a big question, because computers are deterministic,
 so it is hard to see how they could act randomly.

 There are all sorts of pseudo-random generators which will produce a
 stream of output which appear more or less random. The larger and more
 sophisticated ones produce much better results than the poorly
 designed ones. Decades ago there was a random generator called randu
 which was notoriously bad, but before people figured out how flawed it
 was, hundreds of simulation studies had been performed with it, and
 most ended up being rejected as invalid based on the poor statistical
 qualities of randu.

 Today there are several high-quality generators, such as the Mersenne
 Twister. George Marsaglia has designed several excellent generators,
 as well as the Diehard battery of tests to measure the statistical
 quality of any generator.

 However, you seem to be wanting a single number which will be
 different each time you run a program.

 You could do something as simple as

 int random_value = 2 + (time() % 9);

 Or you could pick any well-known random generator, seed it, and use it
 to produce what you need.

 To get you started, this function will produce a pseudo-random stream
 of output in the range 0..65535 using Marsaglia's multiply with
 carry algorithm.


 unsigned int mwc()
 {
   static unsigned int x = time(0);
   x = 63663 * (x65535) + (x16);
   return x65535;
 }

 Don

 On Jul 31, 4:39 am, Puneet Gautam puneet.nsi...@gmail.com wrote:
 Can we write a code to generate random numbers without using rand
 function..?

 Pls help me on this!!

 --
 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: adobe written round que

2011-08-01 Thread Puneet Gautam
@ankit: not the last digit..!!
it will be (last digit -3) or (last digit -3-3) whichever is positive..

:)

On 7/31/11, Ankit Minglani ankit.mingl...@gmail.com wrote:
 yeah if it was a divisibility test then the question would have been too
 trivial ..
 the last digit after doing itoa will be the remainder .

 On Sat, Jul 30, 2011 at 11:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:

 i think solution of ankit is right !
 sorry even i forgot tht que ws not divisibility test ..but to get
 quotient :-|

 On Jul 30, 10:03 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote:
  @roopam : i got the question all wrong. . .
 
  On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   The objective is to divide the number by 3 and not just check for it's
   divisibility.
   Adding the digits using itoa() and then repeated subtraction will
   check
 for
   it's divisibility by 3 and not give us the quotient.
   To get that you will have to carry out repeated subtraction on the
 number
   anyway.
   So whats the point?
 
   --
   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/-/BWTzYtcBhIgJ.
 
   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.
 
  --
  Ankur Khurana
  Computer Science
  Netaji Subhas Institute Of Technology
  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.




 --
 The more you sweat in the field, the less you bleed in war.

 Ankit Minglani
 NITK Surathkal

 --
 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.



[algogeeks] Bugs in a program

2011-07-31 Thread Puneet Gautam
What is meant by 'priority' and  'severity' of a bug..?

-- 
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.



[algogeeks] Termination

2011-07-31 Thread Puneet Gautam
Is it possible to terminate this code(except break) while it is
executing..? For what eof will this terminate..?


#includestdio.h
main(int argc,char *argv[])
{int c;
 while((c=getchar())!=EOF)
 {
  putchar(c);
  }
  }

Reply fast...

-- 
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.



[algogeeks] pointers

2011-07-31 Thread Puneet Gautam
What are smart pointers and what is the concept of pointer to void..?

-- 
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.



[algogeeks] random generation

2011-07-31 Thread Puneet Gautam
Can we write a code to generate random numbers without using rand function..?

Pls help me on this!!

-- 
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] Termination

2011-07-31 Thread Puneet Gautam
Is the eof different for different OS's..?

On 7/31/11, Abhishek Gupta gupta.abh...@gmail.com wrote:
 compiler : gcc, OS : Fedora 15

 I use ctrl + d to put EOF in files.

 you can verify it through this code

 #includestdio.h
 int main(int argc,char *argv[])
 {int c;
 while((c=getchar())!=EOF)
 {
  putchar(c);
  }
  if(c==EOF)
  printf(EOF Break);
  return 0;
  }



 On Sun, Jul 31, 2011 at 3:05 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Is it possible to terminate this code(except break) while it is
 executing..? For what eof will this terminate..?


 #includestdio.h
 main(int argc,char *argv[])
 {int c;
 while((c=getchar())!=EOF)
 {
  putchar(c);
  }
  }

 Reply fast...

 --
 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.




 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

 --
 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] random generation

2011-07-31 Thread Puneet Gautam
@rajeev: Well, i meant a code which generates a random no. between say
2 and 10 at every run of program...not the random code generator...!

eg:

if a=2 b=10
on first run of program, it produces
3
2nd run:
5
3rd run:
4
4th run:
9

all these values dont follow any sequence between program runs..



On 7/31/11, rajeev bharshetty rajeevr...@gmail.com wrote:
 *#includestdio.h*
 *
 *
 *int main()*
 *{*
 *
 *
 *int x,a,b,i,n;*
 *printf(\n Enter the value of n);*
 *scanf(%d,n);*
 *printf(\n Enter Psoitive integer a);*
 *scanf(%d,a);*
 *printf(\n Enter the positisve integer b);*
 *scanf(%d,b);*
 *for(i=1;i=15;i++)*
 *{*
 * n= (a*n + b);*
 * printf(%d\n,n);*
 *}*
 *return 0;*
 * *
 * }*

 Random code generator ...
 Correct me if i am wrong 
 thanks

 On Sun, Jul 31, 2011 at 3:19 PM, Someshwar Chandrasekaran 
 somseka...@gmail.com wrote:

 On Sun, Jul 31, 2011 at 3:09 PM, Puneet Gautam puneet.nsi...@gmail.com
 wrote:
  Can we write a code to generate random numbers without using rand
 function..?
 
  Pls help me on this!!

 How about operating on some garbage value?

 Regards,
 B.C.Someshwar


 --
 'Talk sense to a fool and he calls you foolish.' - Euripides

 My Blog:  somsekaran.wordpress.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.




 --
 Regards
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

 --
 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] Termination

2011-07-31 Thread Puneet Gautam
@Shashank Nayar:
Thanks maan...! it worked..


On 7/31/11, Shashank Nayak link4shash...@gmail.com wrote:
 ctrl+z for win

 On Sun, Jul 31, 2011 at 3:18 PM, Abhishek Gupta
 gupta.abh...@gmail.comwrote:

 I am only using linux. google it. it must be some ctrl + any key sequence


 On Sun, Jul 31, 2011 at 3:12 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 ctrl+D doesnt work on dev , os windows 7...

 On 7/31/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
  Is the eof different for different OS's..?
 
  On 7/31/11, Abhishek Gupta gupta.abh...@gmail.com wrote:
  compiler : gcc, OS : Fedora 15
 
  I use ctrl + d to put EOF in files.
 
  you can verify it through this code
 
  #includestdio.h
  int main(int argc,char *argv[])
  {int c;
  while((c=getchar())!=EOF)
  {
   putchar(c);
   }
   if(c==EOF)
   printf(EOF Break);
   return 0;
   }
 
 
 
  On Sun, Jul 31, 2011 at 3:05 PM, Puneet Gautam
  puneet.nsi...@gmail.comwrote:
 
  Is it possible to terminate this code(except break) while it is
  executing..? For what eof will this terminate..?
 
 
  #includestdio.h
  main(int argc,char *argv[])
  {int c;
  while((c=getchar())!=EOF)
  {
   putchar(c);
   }
   }
 
  Reply fast...
 
  --
  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.
 
 
 
 
  --
  Abhishek Gupta
  MCA
  NIT Calicut
  Kerela
 
  --
  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.




 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

  --
 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,
 Shashank Nayak

 --
 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] random generation

2011-07-31 Thread Puneet Gautam
Yes...yes...yes...Guys..i got it...!!!
Thanks Someshwar.. ur idea clicked it well...

Will post the code tomorrow...!!



On 7/31/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @rajeev: Well, i meant a code which generates a random no. between say
 2 and 10 at every run of program...not the random code generator...!

 eg:

 if a=2 b=10
 on first run of program, it produces
 3
 2nd run:
 5
 3rd run:
 4
 4th run:
 9

 all these values dont follow any sequence between program runs..



 On 7/31/11, rajeev bharshetty rajeevr...@gmail.com wrote:
 *#includestdio.h*
 *
 *
 *int main()*
 *{*
 *
 *
 *int x,a,b,i,n;*
 *printf(\n Enter the value of n);*
 *scanf(%d,n);*
 *printf(\n Enter Psoitive integer a);*
 *scanf(%d,a);*
 *printf(\n Enter the positisve integer b);*
 *scanf(%d,b);*
 *for(i=1;i=15;i++)*
 *{*
 * n= (a*n + b);*
 * printf(%d\n,n);*
 *}*
 *return 0;*
 * *
 * }*

 Random code generator ...
 Correct me if i am wrong 
 thanks

 On Sun, Jul 31, 2011 at 3:19 PM, Someshwar Chandrasekaran 
 somseka...@gmail.com wrote:

 On Sun, Jul 31, 2011 at 3:09 PM, Puneet Gautam puneet.nsi...@gmail.com
 wrote:
  Can we write a code to generate random numbers without using rand
 function..?
 
  Pls help me on this!!

 How about operating on some garbage value?

 Regards,
 B.C.Someshwar


 --
 'Talk sense to a fool and he calls you foolish.' - Euripides

 My Blog:  somsekaran.wordpress.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.




 --
 Regards
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

 --
 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] Bugs in a program

2011-07-31 Thread Puneet Gautam
Thanks...!

On 7/31/11, rajeev bharshetty rajeevr...@gmail.com wrote:
 http://www.softwaretestinghelp.com/priority-and-severity/


 On Sun, Jul 31, 2011 at 3:02 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 What is meant by 'priority' and  'severity' of a bug..?

 --
 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
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

 --
 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] pointers

2011-07-31 Thread Puneet Gautam
Thanks..


On 7/31/11, aditi garg aditi.garg.6...@gmail.com wrote:
 http://ootips.org/yonat/4dev/smart-pointers.html
 Dis cud be helpful fr smart pointers

 On Sun, Jul 31, 2011 at 3:06 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 What are smart pointers and what is the concept of pointer to void..?

 --
 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] Re: Testcases

2011-07-30 Thread Puneet Gautam
Guys, what are the technical terms used while writing testcases..i
mean if its a 10 marks question...,how wud u answer it..?



On 7/30/11, hary rathor harry.rat...@gmail.com wrote:
 oh! sorry :

 if(c^2 a^2+b^2) acute angle
 if(c^2 =a^2+b^2) right angle
 if(c^2 a^2+b^2)  obtuse angle

 --
 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: self referential struct. Contd.

2011-07-30 Thread Puneet Gautam
@everyone: What happens to those padded byte addresses.. do they
remain empty or what..?
Can we utilize those padded bytes in any way ..?


On 7/30/11, tech rascal techrascal...@gmail.com wrote:
 can anyone explain in detail .how structure padding is advantageous???

 On Fri, Jul 29, 2011 at 10:28 PM, Rohit Srivastava
 access2ro...@gmail.comwrote:

 padding based on the bit interleaving(low order) which is basically
 hardware dependent.


 On Fri, Jul 29, 2011 at 10:10 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Thanks guys...so much...!!

 On 7/29/11, nullpointer nullpointer...@gmail.com wrote:
  #includestdio.h
  #includeconio.h
  struc MyStructA {
 
   char a;
   char b;
   int c;
  };
 
  struct MyStructB {
   char a;
   int c;
   char b;
  };
 
  int main(void) {
 
   struct MyStructA A;
   struct MyStructB B;
 
  int sizeA = sizeof(struct MyStructA);
   int sizeB = sizeof(struct MyStructB);
   return 0;
 
  }
 
  OUTPUT IS
  A = 8
  B = 12
  Structure padding is done to try and make sure that variables start in
  memory at addresses that are a multiple of their size.
  This is more efficient at hardware level (needs less cpu ticks to read
  or write variables) and in some platforms this is mandatory, though
  not on i386. There are CPU's that can only handle double precision
  floats if they are aligned on addresses that are a multiople of 8.
 
 
  In this struct:
  struct MyStructA {
 
   char a;
   char b;
  int c;
  };
  the beginning of the struct is to be assumed at 0 (I'l explain later)
  a is 1 byte so it needs no padding in front of it.
  the same goes for b.
  but c is 4 bytes. it should be placed at an address boundary that is a
  multiple of 4, so the compiler adds 2 dummy bytes in front of it.
  These 2 bytes change the size from 6 to 8.
  Now in this struct:
  struct MyStructB {
   char a;
   int c;
   char b;
  };
 
  a starts on 0, so no need for padding.
  c needs 3 bytes in front of it, and b needs no padding.
  this would bring the struct size to 9. HOWEVER, suppose that you place
  2 of those structs in an array, the address rules for the second
  struct in the array are the same as for the first struct.
  If that second struct would start at byte 10, this would not be true
  so the compiler also inserts some padding at the end of the structure
  so that the next struct after it starts at a multiple of the size of
  its largest member.
 
 
 
 
  On Jul 29, 3:36 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
  @puneet : no , in this case since 4 bytes will be used for int a and
 int c
  and then 1 byte for char b with 3 padded bytes next..it wud be the
  same
  here
 
  On Fri, Jul 29, 2011 at 12:11 PM, Puneet Gautam
  puneet.nsi...@gmail.comwrote:
 
 
 
   @nikhil: If i declare Char b after int c.., would there be any
   difference...?
 
   On 7/28/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
Here's another example.
 
struct example
{
int a;
char b;
int c;
}
 
Now if a variable of type example is declared then
(considering base address as 2000)
a gets : 2000 to 2003
b gets : 2004
c gets : 2005 to 2008 ? NO
 
It gets 2008 to 2011. The bytes from 2005 to 2007 (3 bytes) are
 padded
in
this case.
 
On Thu, Jul 28, 2011 at 12:18 AM, Aman Goyal 
 aman.goya...@gmail.com
   wrote:
 
yes this will be the case.
 
On Wed, Jul 27, 2011 at 11:35 PM, Puneet Gautam
puneet.nsi...@gmail.comwrote:
 
@nikhil:So what u mean is that if i have:
 
struct{
int a;
char b[5];
};
 
the size of this struct's node will be 12 not 9.., to make it a
   multiple
of 4??
 
On 7/26/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
 Padding is not a topic of self referential structure.
 
 Padding means that extra spaces of memory are used by the
 compiler
 to
 allocate memory. This is done to have the memory address as a
   multiple
of
 the size of the variable. This speeds up the processing of
 these
variables
 by the compiler.
 
 On Tue, Jul 26, 2011 at 8:09 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:
 
 what is meant by padding in self_referenced structure?
 Is it always necessary?
 
 --
 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.
 
 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India
 
 --
 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

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
I think the whole point and advantage of using itoa is to make the
code suitable for larger integer inputs..

eg: if i/p is: 32765 , itoa gives 32765, we take each sum=3+2+7+6+5=
23 and then use repeated subtraction...

Repeated subtraction on 2 digit no. is much faster than on 5 digit one..!!

Hence, itoa becomes useful..!

Thanks..

On 7/30/11, Ankit Minglani ankit.mingl...@gmail.com wrote:
 #includestdio.h
 #includestdlib.h
 #includeconio.h
 #includestring.h
 #includemath.h

 int multiply(int a,int b)
 {

 int i;
 int temp=a;
 printf(\na=%d b=%d\n,a,b);
 for(i=1;ib;i++)
 a+=temp;
 printf(\nfinal a = %d,a);
 return(a);

 }

 void main ()
 {
 int x,rem,quo=0,i,j;
 char p[20];
 clrscr();
 scanf(%d,x);
 itoa(x,p,3);

 rem=(int)p[strlen(p)-1]-48;
 printf(%dRemainder\n,rem);

 for(i=strlen(p)-2,j=0;i=0;i--,j++)
 {
 printf(p[j] = %d,p[j]-48);
  //quo+=(p[j]-48)*pow(3,i);
 quo+=multiply(p[j]-48,pow(3,i));
 printf(\nquo=%d,quo);

 }

 printf(\nQuotient=%d,quo);

 printf(\n%s,p);
 getch();

 }

 taking base 3 will convert the number into the base 3 form ..
 for example let x=100 the number to be divided by three.

 so 100 in base 10 = 10201 in base 3 .
 we get base 3 by consecutive divisions by 3 so the last number will always
 be the remainder ie 1 .

 rest   1 0 2 0 will be the quotient.
   |  |  |  |
 index:3 2 1 0
 so p[j]-48 will convert the char to integer and mutiply it wil 3 ^ power (
 index )
 the answer will be the quotient.


 On Sat, Jul 30, 2011 at 12:15 AM, aditi garg
 aditi.garg.6...@gmail.comwrote:

 @Samm : Im not able to understand ur logic...im not getting the correct
 ans...can u explain the working taking n as 7?


 On Sat, Jul 30, 2011 at 12:25 PM, SAMM somnath.nit...@gmail.com wrote:

 Single bit shift...

 int divide(int n)
 {
 n-=1;
 n=1;
 return n;
 }

 On 7/30/11, tech rascal techrascal...@gmail.com wrote:
  hw will u get the ans on repeated subtraction from the sum of the
 digits??
  I mean if I hv 2 divide 27 by 3 thn first I'll find sum of the
 digits
  i.e, 2+7=9
  then I'll apply repeated subtraction on 9, so hw will i reach to the
 ans??
 
 
  On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:
 
 
  @brijesh-
  itoa basically converts integer to string ..we are using the fact tht
  a number is multiple of 3 if its sum is multiple of 3
  . we have int as string and we can traverse it ..for each character
  apply
   int sum+=*c-'0' (ankur missed the star :P)
  then on sum we use repeated subtraction...i hope its clear .
 
  we are using all this just coz we have to use itoa ..otherwise there
  are more methods (check my frst post )
 
 
  On Jul 30, 4:34 am, brijesh brijeshupadhyay...@gmail.com wrote:
   @ankur I didnt get this... could u or anyone please elaborate!
  
   On Jul 30, 12:43 am, Ankur Khurana ankur.kkhur...@gmail.com wrote:
  
  
  
  
  
  
  
when you use itoa , what you get is a string. get the sum of all
 the
  digits
, using c-'0' and then use repeated subtraction . . .
  
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
  sukhmeet2...@gmail.comwrote:
  
 repeated subtraction !!
  
 On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:
  
 Without using /,% and * operators. write a function to divide a
  number
 by 3. itoa() function is available.
  
 all i cn thnk of is to use shift operator and addition ,
   x/3=e^(logx-
 log3) or repetitive subtraction
  
 but none of them uses itoa() ..ne idea how its done?
 thnks !
  
 --
 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.
  
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
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 

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
@roopam: Thats what i am saying... the function itoa only gives you
the remainder, it doesnt provide quotient..we need to do repeated
subtraction for that...




On 7/30/11, Ankur Khurana ankur.kkhur...@gmail.com wrote:
 @roopam : i got the question all wrong. . .

 On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.comwrote:

 The objective is to divide the number by 3 and not just check for it's
 divisibility.
 Adding the digits using itoa() and then repeated subtraction will check
 for
 it's divisibility by 3 and not give us the quotient.
 To get that you will have to carry out repeated subtraction on the number
 anyway.
 So whats the point?

 --
 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/-/BWTzYtcBhIgJ.

 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.




 --
 Ankur Khurana
 Computer Science
 Netaji Subhas Institute Of Technology
 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.



[algogeeks]

2011-07-29 Thread Puneet Gautam
If u have to sort a large amount of data,but the memory space is
insufficient for the same...How would u sort the data..?

Reply asap everyone..

Thanks in advance...!

-- 
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.



[algogeeks] Testcases

2011-07-29 Thread Puneet Gautam
Hey everyone , pls tell me how testcases of following:

1. 3 sides of a triangle are taken, output whether its obstuse,
scalene,isosceles..?
2. testcases of a duster...

I know nothing about testcases, so pls reply accordingly..!!

-- 
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.



[algogeeks] DS representation.

2011-07-29 Thread Puneet Gautam
Hi,

pls tell me which data structure has following representation::

A+Bx+Cx(^2)+Dx(^3)+...+Nx(^n-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.



Re: [algogeeks] self referential struct. Contd.

2011-07-29 Thread Puneet Gautam
@nikhil: If i declare Char b after int c.., would there be any
difference...?

On 7/28/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
 Here's another example.

 struct example
 {
 int a;
 char b;
 int c;
 }

 Now if a variable of type example is declared then
 (considering base address as 2000)
 a gets : 2000 to 2003
 b gets : 2004
 c gets : 2005 to 2008 ? NO

 It gets 2008 to 2011. The bytes from 2005 to 2007 (3 bytes) are padded in
 this case.

 On Thu, Jul 28, 2011 at 12:18 AM, Aman Goyal aman.goya...@gmail.com wrote:

 yes this will be the case.


 On Wed, Jul 27, 2011 at 11:35 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 @nikhil:So what u mean is that if i have:

 struct{
 int a;
 char b[5];
 };

 the size of this struct's node will be 12 not 9.., to make it a multiple
 of 4??



 On 7/26/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
  Padding is not a topic of self referential structure.
 
  Padding means that extra spaces of memory are used by the compiler to
  allocate memory. This is done to have the memory address as a multiple
 of
  the size of the variable. This speeds up the processing of these
 variables
  by the compiler.
 
  On Tue, Jul 26, 2011 at 8:09 PM, Puneet Gautam
  puneet.nsi...@gmail.comwrote:
 
  what is meant by padding in self_referenced structure?
  Is it always necessary?
 
  --
  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.
 
 
 
 
  --
  Nikhil Gupta
  Senior Co-ordinator, Publicity
  CSI, NSIT Students' Branch
  NSIT, New Delhi, India
 
  --
  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.




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India

 --
 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]

2011-07-29 Thread Puneet Gautam
@Anand: What is external merge sort...?

On 7/29/11, Anand Saha anands...@gmail.com wrote:
 You have to use External Merge Sort.

 --


 On Fri, Jul 29, 2011 at 2:58 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 If u have to sort a large amount of data,but the memory space is
 insufficient for the same...How would u sort the data..?

 Reply asap everyone..

 Thanks in advance...!

 --
 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]

2011-07-29 Thread Puneet Gautam
But in B-trees also we need to store large no of pointers in the main
memory. Wont that outrun memory space..?

Can we use B+ trees ..?Would that be any good..?

On 7/29/11, rajeev bharshetty rajeevr...@gmail.com wrote:
 B Trees data structures are optimal for such problems.
 These algorithms help to access large amount of data which we cannot fit
 into main memory .

 On Fri, Jul 29, 2011 at 2:58 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 If u have to sort a large amount of data,but the memory space is
 insufficient for the same...How would u sort the data..?

 Reply asap everyone..

 Thanks in advance...!

 --
 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
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

 --
 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] DS representation.

2011-07-29 Thread Puneet Gautam
@sunny: well not really in an interview ..
its that adobe is coming 1st august to our college..

I found this question in its placement papers..!!!

I thought there might be a predefined ds for such representation...

What is an SLL..?

On 7/29/11, rajeev bharshetty rajeevr...@gmail.com wrote:
 You can use a Hash map which maps the coefficients of the equation and their
 exponents.
 Is this feasible ??

 On Fri, Jul 29, 2011 at 3:10 PM, sunny agrawal
 sunny816.i...@gmail.comwrote:

 Array that that stores A,B,C,D,E.

 it looks like u r on some telephonic interview :P

 On Fri, Jul 29, 2011 at 3:06 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 Hi,

 pls tell me which data structure has following representation::

 A+Bx+Cx(^2)+Dx(^3)+...+Nx(^n-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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee


  --
 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
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

 --
 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]

2011-07-29 Thread Puneet Gautam
@vaibhav :Cool ...!!
thanks buddy..!

On 7/29/11, vaibhav shukla vaibhav200...@gmail.com wrote:
 If u have 2GB of data file which has one string per line and u have to sort
 it, and X MB of memory is available.then divide the file into 'K' chunks of
 X MB each. Bring each chunk into memory and sort lines by any usual O(nlgn)
 algorithm \. Save the lines back to files.
 D this for all chunks and once u'v finished.merge them all.
 External sort and N-way merge example!!

 On Fri, Jul 29, 2011 at 3:24 PM, rajeev bharshetty
 rajeevr...@gmail.comwrote:

 B Trees data structures are optimal for such problems.
 These algorithms help to access large amount of data which we cannot fit
 into main memory .


 On Fri, Jul 29, 2011 at 2:58 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 If u have to sort a large amount of data,but the memory space is
 insufficient for the same...How would u sort the data..?

 Reply asap everyone..

 Thanks in advance...!

 --
 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
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

  --
 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.




 --
   best wishes!!
 Vaibhav
  DU-MCA

 --
 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: self referential struct. Contd.

2011-07-29 Thread Puneet Gautam
Thanks guys...so much...!!

On 7/29/11, nullpointer nullpointer...@gmail.com wrote:
 #includestdio.h
 #includeconio.h
 struc MyStructA {

  char a;
  char b;
  int c;
 };

 struct MyStructB {
  char a;
  int c;
  char b;
 };

 int main(void) {

  struct MyStructA A;
  struct MyStructB B;

 int sizeA = sizeof(struct MyStructA);
  int sizeB = sizeof(struct MyStructB);
  return 0;

 }

 OUTPUT IS
 A = 8
 B = 12
 Structure padding is done to try and make sure that variables start in
 memory at addresses that are a multiple of their size.
 This is more efficient at hardware level (needs less cpu ticks to read
 or write variables) and in some platforms this is mandatory, though
 not on i386. There are CPU's that can only handle double precision
 floats if they are aligned on addresses that are a multiople of 8.


 In this struct:
 struct MyStructA {

  char a;
  char b;
 int c;
 };
 the beginning of the struct is to be assumed at 0 (I'l explain later)
 a is 1 byte so it needs no padding in front of it.
 the same goes for b.
 but c is 4 bytes. it should be placed at an address boundary that is a
 multiple of 4, so the compiler adds 2 dummy bytes in front of it.
 These 2 bytes change the size from 6 to 8.
 Now in this struct:
 struct MyStructB {
  char a;
  int c;
  char b;
 };

 a starts on 0, so no need for padding.
 c needs 3 bytes in front of it, and b needs no padding.
 this would bring the struct size to 9. HOWEVER, suppose that you place
 2 of those structs in an array, the address rules for the second
 struct in the array are the same as for the first struct.
 If that second struct would start at byte 10, this would not be true
 so the compiler also inserts some padding at the end of the structure
 so that the next struct after it starts at a multiple of the size of
 its largest member.




 On Jul 29, 3:36 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
 @puneet : no , in this case since 4 bytes will be used for int a and int c
 and then 1 byte for char b with 3 padded bytes next..it wud be the same
 here

 On Fri, Jul 29, 2011 at 12:11 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:



  @nikhil: If i declare Char b after int c.., would there be any
  difference...?

  On 7/28/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
   Here's another example.

   struct example
   {
   int a;
   char b;
   int c;
   }

   Now if a variable of type example is declared then
   (considering base address as 2000)
   a gets : 2000 to 2003
   b gets : 2004
   c gets : 2005 to 2008 ? NO

   It gets 2008 to 2011. The bytes from 2005 to 2007 (3 bytes) are padded
   in
   this case.

   On Thu, Jul 28, 2011 at 12:18 AM, Aman Goyal aman.goya...@gmail.com
  wrote:

   yes this will be the case.

   On Wed, Jul 27, 2011 at 11:35 PM, Puneet Gautam
   puneet.nsi...@gmail.comwrote:

   @nikhil:So what u mean is that if i have:

   struct{
   int a;
   char b[5];
   };

   the size of this struct's node will be 12 not 9.., to make it a
  multiple
   of 4??

   On 7/26/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
Padding is not a topic of self referential structure.

Padding means that extra spaces of memory are used by the compiler
to
allocate memory. This is done to have the memory address as a
  multiple
   of
the size of the variable. This speeds up the processing of these
   variables
by the compiler.

On Tue, Jul 26, 2011 at 8:09 PM, Puneet Gautam
puneet.nsi...@gmail.comwrote:

what is meant by padding in self_referenced structure?
Is it always necessary?

--
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.

--
Nikhil Gupta
Senior Co-ordinator, Publicity
CSI, NSIT Students' Branch
NSIT, New Delhi, India

--
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

Re: [algogeeks] complexity

2011-07-28 Thread Puneet Gautam
@sachin: Explain pls...!!?


On 7/28/11, sachin sharma sachin.bles...@gmail.com wrote:
 it is O(plg5)


 Best Wishes
 Sachin Sharma

 --
 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: interview ques

2011-07-28 Thread Puneet Gautam
@bharath: To store the bunch of records together also, we gonna need
another useful ds like linked list or array which again points to
the problem of excessive storage or excessive pointers...
correct me if am not..!



On 7/28/11, bharath bharath.sri...@gmail.com wrote:
 @Dumanshu: A B+ tree is a multi-level index. It indexes the index
 until the final level is small enough to fit into a data block that
 can fit in memory.

 On Jul 27, 10:11 pm, Dumanshu duman...@gmail.com wrote:
 Use multilevel indexing

 On Jul 27, 11:07 pm, himanshu kansal himanshukansal...@gmail.com
 wrote:







  if u hv say 20 million records and u have to create a b+ tree then you
  might be storing 20 million pointers at the leaf levelhow can u
  optimize this(using b+ tree only)???

 --
 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] complexity

2011-07-28 Thread Puneet Gautam
k...thanks...


On 7/28/11, Rajeev Kumar rajeevprasa...@gmail.com wrote:
 @Puneet,
  get_power(int a, int b) works in O(logb) as you keep on dividing b with
 2...
 you are calling that method *P *times in *func(int p) *method.
 So it is *plogb...*u r passing 5 as b valueit will be *plog5*

 On Thu, Jul 28, 2011 at 11:45 AM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 @sachin: Explain pls...!!?


 On 7/28/11, sachin sharma sachin.bles...@gmail.com wrote:
  it is O(plg5)
 
 
  Best Wishes
  Sachin Sharma
 
  --
  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.




 --
 Thank You
 Rajeev 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] how to calculate the complexity

2011-07-28 Thread Puneet Gautam
Time complexity:

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;
}

O(plgp) or O(plg5)..? or anything else..?


On 7/28/11, sunny agrawal sunny816.i...@gmail.com wrote:
 Master theorem can be used when we know the recurrence relation.

 You can read the 2nd Chapter of CLRS..

 On Thu, Jul 28, 2011 at 1:16 AM, rajeev bharshetty
 rajeevr...@gmail.comwrote:

 Masters Theorem
 http://en.wikipedia.org/wiki/Master_theorem


 On Thu, Jul 28, 2011 at 1:14 AM, NITIN SHARMA
 coolguyinat...@gmail.comwrote:

 Can anybody explain the basic steps that how to calculate the
 complexity of an algo so that i would be able to find complexity of
 any program

 --
 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
 Rajeev N B http://www.opensourcemania.co.cc

 *Winners Don't do Different things , they do things Differently*

  --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

 --
 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 -Written Test

2011-07-28 Thread Puneet Gautam
Well, they do ask questions mainly from Linked list, tree traversals
and yes, automata
Also questions on time complexity and algos ..

Every question is given a specified time limit which bases your
scoring on how fast u do it..

Thats all i know..

On 7/28/11, radha krishnan radhakrishnance...@gmail.com wrote:
 Anyone have an idea about DirectI Written test ?
 Thanks in Advance !

 Radhakrishnan,
 CEG,AU,
 Chennai

 --
 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: rotate a matrix NVIDIA question

2011-07-27 Thread Puneet Gautam
Can anyone give an O(n) solution pls...??
I think the above code is an O(n^2) solution..
if i am not wrong...!!!



On 7/27/11, amit amit.codenam...@gmail.com wrote:
 #include cstdio
 #include algorithm
 using namespace std;

 const int MX = 1000;
 int n, m;
 int a[MX][MX];

 int main() {
 scanf(%d%d, n, m);
 for(int i = 0; i  n; i++)
 for(int j = 0; j  m; j++)
 scanf(%d, a[i][j]);

 for(int i = 0; i  n/2; i++)
 for(int j = 0; j  m; j++)
 swap(a[i][j], a[n-i-1][m-j-1]);
 if(n1)
 for(int j = 0; j  m/2; j++)
 swap(a[n/2][j], a[n/2][m-j-1]);

 for(int i = 0; i  n; i++) {
 for(int j = 0; j  m; j++)
 printf(%d , a[i][j]);
 printf(\n);
 }
 }


 On Jul 27, 7:54 pm, Anika Jain anika.jai...@gmail.com wrote:
 is it lyk for {1,2,3
                    4,5,6,
                    7,8,9}
 to be {3,2,1,
          6,5,4,
          9,8,7}    ??



 On Wed, Jul 27, 2011 at 9:37 AM, Deoki Nandan deok...@gmail.com wrote:
  rotate a 2D matrix by angle 180

  --
  **With Regards
  Deoki Nandan Vishwakarma

  *
  *

   --
  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] self referential struct. Contd.

2011-07-27 Thread Puneet Gautam
@nikhil:So what u mean is that if i have:

struct{
int a;
char b[5];
};

the size of this struct's node will be 12 not 9.., to make it a multiple of 4??



On 7/26/11, Nikhil Gupta nikhilgupta2...@gmail.com wrote:
 Padding is not a topic of self referential structure.

 Padding means that extra spaces of memory are used by the compiler to
 allocate memory. This is done to have the memory address as a multiple of
 the size of the variable. This speeds up the processing of these variables
 by the compiler.

 On Tue, Jul 26, 2011 at 8:09 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 what is meant by padding in self_referenced structure?
 Is it always necessary?

 --
 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.




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India

 --
 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.



[algogeeks] complexity

2011-07-27 Thread Puneet Gautam
Time complexity..?

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;
}

Is it O(plgp) or O(plg5)

-- 
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.



[algogeeks] size of self referential structure

2011-07-26 Thread Puneet Gautam
#includestdio.h
#includestddef.h
struct node{
   int a;
   char *b[5];
   struct node *link;
   };
main()
{
  int a;
  a=sizeof(struct node);
  printf(%d,a);
  getchar();
  return 0;
  }

Whats the output..?

-- 
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] Closest as Possible

2011-07-26 Thread Puneet Gautam
@rshetty: do u mean the sum of any no of elements separately in the
two partitions be equal to each other..? is that what u mean..?

On 7/26/11, rShetty rajeevr...@gmail.com wrote:
 Problem statement goes as :

 Consider square root of integers form 1 to 100. Now partition the
 square roots of integers as being from 1 to 50 and 51 to 100.
 Now find the sum in the two partitions which is as close as possible
 or minimum?
 Give the algorithm ?? and das structures to be used??

 --
 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: Hashing with strings

2011-07-26 Thread Puneet Gautam
Doing such a complex thing reduces collisions and makes hashing effective..
Well, I didnt get you fully on dat 4 bytes of string together ...

I think u should refer to Article 6.6, Chapter 6(Structures) in The
C programming Language by Dennis Rtchie book..

Its very well explained there...!!

The book can be googled ...its easily available..

Good luck..!!

On 7/26/11, syl abeygau...@gmail.com wrote:
 thanks for the info...i saw a method of using 4 bytes of string
 together and then add them and finally take a modulusdoing such a
 complex thing ...is thr any way to recover the string back using the
 key only.can you give an example where you have seen using hashing
 with strings...that would clarify my doubt to more extent...

 On Jul 26, 6:07 pm, Don dondod...@gmail.com wrote:
 A string hash function typically takes a string as an argument and
 returns an integer which can be used as an index into a hash table
 which allows it to be found quickly. The purpose is to relate a string
 to something else in an efficient way. For instance, a symbol table
 which stores variable names and needs to quickly find the type and the
 value (or the address of the value) could use a hash table to avoid
 having to search through the whole table. There are many theories on
 the best hash functions for hashing strings. While two different
 strings may produce the same hash index, a good hash function should
 produce a reasonably uniform distribution of results, and should
 produce different results for similar strings. Any hashing method
 needs to deal with collisions or how to handle the case where two
 strings are hashed to the same index. Some schemes use a linked list
 or binary tree withing the hash bucket, and some use a rehash which
 stores one of the strings somewhere else. If a hash table becomes too
 full, it can become much less efficient, particularly if the method of
 resolving collisions is not well designed.

 Don

 On Jul 26, 7:49 am, syl abeygau...@gmail.com wrote:







  can anyone please tell me how to do hashing with strings..just
  wanna confirm...and most importantly what is the use of it...i have
  never used 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] Re: size of self referential structure

2011-07-26 Thread Puneet Gautam
@everyone:
I have this mind strangling doubt..!!!

Why is char *s[5] of 20 bytes...?

yes the output is 28...

On 7/26/11, Don dondod...@gmail.com wrote:
 A reasonable guess would be 28 bytes. But the size of a structure is
 implementation dependent, and therefore, some other result could be
 correct as well.
 Don

 On Jul 26, 7:40 am, Puneet Gautam puneet.nsi...@gmail.com wrote:
 #includestdio.h
 #includestddef.h
 struct node{
        int a;
        char *b[5];
        struct node *link;
        };
 main()
 {
       int a;
       a=sizeof(struct node);
       printf(%d,a);
       getchar();
       return 0;
       }

 Whats the output..?

 --
 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: size of self referential structure

2011-07-26 Thread Puneet Gautam
ok...!

#includestdio.h
#includestddef.h
struct node{
   int a;
   char b[5];
   struct node *link;
   };
main()
{
  int a;
  a=sizeof(struct node);
  printf(%d,a);
  getchar();
  return 0;
  }

why is its output : 16?
Sudnt it be 4(int a) +5(char b[5] string) +9(link)= 18..?


On 7/26/11, Akshata Sharma akshatasharm...@gmail.com wrote:
 char *s[5] is an array of 5 char pointers. A pointer is an int, of size 4
 bytes. So, 5*4 = 20 bytes

 On Tue, Jul 26, 2011 at 7:11 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 @everyone:
 I have this mind strangling doubt..!!!

 Why is char *s[5] of 20 bytes...?

 yes the output is 28...

 On 7/26/11, Don dondod...@gmail.com wrote:
  A reasonable guess would be 28 bytes. But the size of a structure is
  implementation dependent, and therefore, some other result could be
  correct as well.
  Don
 
  On Jul 26, 7:40 am, Puneet Gautam puneet.nsi...@gmail.com wrote:
  #includestdio.h
  #includestddef.h
  struct node{
 int a;
 char *b[5];
 struct node *link;
 };
  main()
  {
int a;
a=sizeof(struct node);
printf(%d,a);
getchar();
return 0;
}
 
  Whats the output..?
 
  --
  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: size of self referential structure

2011-07-26 Thread Puneet Gautam
for the above mentioned code, in previous post,: shudnt the output be 4+5+4=13?

On 7/26/11, Prem Krishna Chettri hprem...@gmail.com wrote:
 Its Cos that is pointer and all pointers is 4 bytes address..

 On Tue, Jul 26, 2011 at 7:11 PM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 @everyone:
 I have this mind strangling doubt..!!!

 Why is char *s[5] of 20 bytes...?

 yes the output is 28...

 On 7/26/11, Don dondod...@gmail.com wrote:
  A reasonable guess would be 28 bytes. But the size of a structure is
  implementation dependent, and therefore, some other result could be
  correct as well.
  Don
 
  On Jul 26, 7:40 am, Puneet Gautam puneet.nsi...@gmail.com wrote:
  #includestdio.h
  #includestddef.h
  struct node{
 int a;
 char *b[5];
 struct node *link;
 };
  main()
  {
int a;
a=sizeof(struct node);
printf(%d,a);
getchar();
return 0;
}
 
  Whats the output..?
 
  --
  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.



[algogeeks] self referential struct. Contd.

2011-07-26 Thread Puneet Gautam
what is meant by padding in self_referenced structure?
Is it always necessary?

-- 
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.



[algogeeks] self referential struct. Contd.

2011-07-26 Thread Puneet Gautam
what is meant by padding in self_referenced structure?
Is it always necessary?

-- 
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]

2011-07-26 Thread Puneet Gautam
yup .. I know... I missed dat out...!
But say , the array is random sorted, then is there an O(N) solution?

On 7/26/11, Dipankar Patro dip10c...@gmail.com wrote:
 Puneet,
 you missed out the 'sorted' part of array. Your code works fine for
 randomized array.

 +1 to Manish's solution. I had the same algo :)

 On 26 July 2011 00:33, Puneet Gautam puneet.nsi...@gmail.com wrote:

 let k=a+b

 run in two loops

 for(i=0;((in)  (a[i]k));i++)
  for(j=i+1;a[j]=(k-a[i]);j++)
 if(a[j]==k-a[i])
do break from both outer n inner loops;
 diplay a[i] n a[j]

 Time complexity:O(n^2) worst case
 shud take O(nlgn) on an average

 --
 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

 --
 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] rotate a matrix NVIDIA question

2011-07-26 Thread Puneet Gautam
Let k=no. of rows

If k=odd
mirror the matrix about the ((k/2)+1) th row..

else start from k/2 and (k/2 +1 )th row, swap the two rows.. then
k/2-1 and k/2 +2 and swap and soon...

OR

maintain array as a pointer table.. keep on changing the base address
to which a[i points to..

Let *a[]={{1,1,0},{2,3,4},{4,57,8},{1,2,5}};

Take pointer a[0] and swap it with the a[3] address.. lly for a[2]and a[1]...
This should run in O(n) time ,n=no of rows of matrix
I think i made it clear...

This might not be the best solution... i wud love to see better
solutions from anyone..!

Thanks..

On 7/27/11, Deoki Nandan deok...@gmail.com wrote:
 rotate a 2D matrix by angle 180


 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

 --
 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] OUTPUT

2011-07-25 Thread Puneet Gautam
@aditi: the %2 in each of these printf statements is redundant coz
it is 1%2...and % has higher precedence over left or right
shifts..thats y output of say :

#includestdio.h
main()
{
int i=1;
printf(\n%d%d ,i=2,i=1%2);
return 0;
}

is 8 8

1 gets left shifted twice in i=2, becomes 4
then i1%2 concludes to i1 as 1%2 is 1 only..
i1 ,makes i=8 and hence

8 8 is printed.

On 7/25/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @rajeev: hey...does printf evaluate an expression right to left
 without considering any priority of operators..?
 Pls reply asap..



 On 7/25/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @aditi: y dont u try it out urself considering the priorities of
 different operators used here...!!
 that would help...

 On 7/25/11, aditi garg aditi.garg.6...@gmail.com wrote:
 Can u plz elaborate...im not able to understand...

 On Mon, Jul 25, 2011 at 11:04 PM, rajeev bharshetty
 rajeevr...@gmail.comwrote:

 @sameer I think that is right


 On Mon, Jul 25, 2011 at 11:02 PM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 its because of side effect where value of i is getting changed twice
 in
 a
 single line.
 correct me if i am wrong :)

 *Muthuraj R.
 4TH Year BE.**
 Information Science Dept*
 *PESIT, Bengaluru .
 *




 On Mon, Jul 25, 2011 at 11:01 PM, geek forgeek
 geekhori...@gmail.comwrote:

 y not the output is 3 2  coz on right to left evaluation  of printf i
 shud be left shifted by 1 bit wgich shud make it 2 ??


 On Mon, Jul 25, 2011 at 10:28 AM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 yeah output
  0
 1 1
 *is dis because of side effect? *
 * *
 *
 *
 *Muthuraj R.
 4TH Year BE.**
 Information Science Dept*
 *PESIT, Bengaluru .
 *





 On Mon, Jul 25, 2011 at 10:49 PM, Deoki Nandan
 deok...@gmail.comwrote:

 run on gcc compiler it would be
 0
 1 1


 On Mon, Jul 25, 2011 at 10:35 PM, geek forgeek
 geekhori...@gmail.comwrote:

 1.
 #includestdio.h
 main()
 {
 int i=1;
  printf(\n%d,i^=1%2);
  printf(\n%d %d,i^=1%2,i=1%2);
 return 0;
 }

 output 3 3
 hey shudnt the output be 3 2


  --
 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.




 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

  --
 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.




 --
 Regards
 Rajeev N B http://www.opensourcemania.co.cc


  --
 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

 9718388816

 --
 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

Re: [algogeeks] OUTPUT

2011-07-25 Thread Puneet Gautam
@rajeev: hey...does printf evaluate an expression right to left
without considering any priority of operators..?
Pls reply asap..



On 7/25/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @aditi: y dont u try it out urself considering the priorities of
 different operators used here...!!
 that would help...

 On 7/25/11, aditi garg aditi.garg.6...@gmail.com wrote:
 Can u plz elaborate...im not able to understand...

 On Mon, Jul 25, 2011 at 11:04 PM, rajeev bharshetty
 rajeevr...@gmail.comwrote:

 @sameer I think that is right


 On Mon, Jul 25, 2011 at 11:02 PM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 its because of side effect where value of i is getting changed twice in
 a
 single line.
 correct me if i am wrong :)

 *Muthuraj R.
 4TH Year BE.**
 Information Science Dept*
 *PESIT, Bengaluru .
 *




 On Mon, Jul 25, 2011 at 11:01 PM, geek forgeek
 geekhori...@gmail.comwrote:

 y not the output is 3 2  coz on right to left evaluation  of printf i
 shud be left shifted by 1 bit wgich shud make it 2 ??


 On Mon, Jul 25, 2011 at 10:28 AM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 yeah output
  0
 1 1
 *is dis because of side effect? *
 * *
 *
 *
 *Muthuraj R.
 4TH Year BE.**
 Information Science Dept*
 *PESIT, Bengaluru .
 *





 On Mon, Jul 25, 2011 at 10:49 PM, Deoki Nandan
 deok...@gmail.comwrote:

 run on gcc compiler it would be
 0
 1 1


 On Mon, Jul 25, 2011 at 10:35 PM, geek forgeek
 geekhori...@gmail.comwrote:

 1.
 #includestdio.h
 main()
 {
 int i=1;
  printf(\n%d,i^=1%2);
  printf(\n%d %d,i^=1%2,i=1%2);
 return 0;
 }

 output 3 3
 hey shudnt the output be 3 2


  --
 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.




 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

  --
 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.




 --
 Regards
 Rajeev N B http://www.opensourcemania.co.cc


  --
 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

 9718388816

 --
 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]

2011-07-25 Thread Puneet Gautam
let k=a+b

run in two loops

for(i=0;((in)  (a[i]k));i++)
  for(j=i+1;a[j]=(k-a[i]);j++)
 if(a[j]==k-a[i])
do break from both outer n inner loops;
diplay a[i] n a[j]

Time complexity:O(n^2) worst case
shud take O(nlgn) on an average

-- 
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] Coding..........

2011-07-22 Thread Puneet Gautam
@atul: can u pls explain ur code...?


On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 @atul: thanks..!


 On 7/22/11, atul purohit gonewiththe...@gmail.com wrote:
 @puuneet
 http://en.wikipedia.org/wiki/Sorting_algorithm#Stability

 On Fri, Jul 22, 2011 at 10:57 AM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 What is meant by maintaining the stability...?
 pls tell me...!!
 Thanks.

 On 7/22/11, atul purohit gonewiththe...@gmail.com wrote:
  here in O(n) and stable
 
 
  void swap (int *a,int *b) {
  int t;
  t=*a;
  *a=*b;
  *b=t;
  }
 
  int main(void) {
 int a[] = {12, 34, 45, 9, 8, 90, 3},odd=0,even=0,n=7;
 while(oddn  even  n) {
  if(a[even]%2==0){
  if(odd==even)
  odd++;
  even++;
  }
  else if(a[even]%2==1) {
  while(a[odd]%2 != 0  odd  n+1) {
  odd++;
  }
  if(odd  n){
  swap(a[even],a[odd]);
  even++;
  }
  }
  }
  for(int i=0;in;i++)
  couta[i] ;
  getchar();
  }
 
 
 
  On Thu, Jul 21, 2011 at 11:55 PM, muruga vel
  murugavidya1...@gmail.comwrote:
 
 
  left=0;right=n-1;
  while(leftright)
  {
   while(leftright  a[left]%2==0)
left++;
  while(leftright  a[right]%2==1)
right--;
  if(leftright)
   {
swap(a[l],a[r]);
 l++;
 r--;
  }
  O(n)
 
 
  On Thu, Jul 21, 2011 at 11:49 PM, Abhishek Sharma
  jkabhishe...@gmail.comwrote:
 
  small change in the pseudocode..
 
 
  for (i=0 until i+ a[].length){
 
  if (*leftptr % 2 == 0)
   A2[i] = *leftptr ;
 
  else if (*rtptr % 2 == 0)
 
   A2[i+a[].length-1] = *rtptr ;
 
  leftptr++;
  rtptr--;
 
 
  }
 
   --
  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.
 
 
 
 
  --
 
  Atul Purohit
 
  --
  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.




 --

 Atul Purohit

 --
 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] Coding..........

2011-07-22 Thread Puneet Gautam
@atul: can u pls tell me how did u go about solving this in ur mind..?


On 7/22/11, Abhi abhi123khat...@gmail.com wrote:
 @atul: can you please elaborate the algorithm you are using.

 --
 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/-/mLtfUz77JMIJ.
 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] Adove Question.........

2011-07-22 Thread Puneet Gautam
@umesh: can R take any value from 1 to 3..?

On 7/22/11, UMESH KUMAR kumar.umesh...@gmail.com wrote:
 Hi

 Given an array of size N that contain some elements, Write a program for
 finding all possible subset of size R .

  n
 i.e.   P
   r

 Array :[1,2,3,4]

 n=4,r=3;

 Output should be:
 {1,2,3},(1,2,4).{2,3,4},{...} possible 24 sets.

 Thanks

 --
 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] Coding..........

2011-07-22 Thread Puneet Gautam
@sunny: how do u do it by Divide n conquer ...can u provide the algo...?


On 7/22/11, UMESH KUMAR kumar.umesh...@gmail.com wrote:
 Anybody try for maintain the stable of elements in O(n) as like

 Input is :{1,2,3,4,5,6,7}
 then Output should be
(2,4,6,1,3,5,7)
 not..

 {2,4,6,1,5,3,7} base on above discussion ..

 --
 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: Microsoft Question!

2011-07-22 Thread Puneet Gautam
check this out: Considering all 4 bytes of int with no left or right shifts..!!
;)

main()
{ unsigned int i,j,k,no=1;
  j=4;
  for(k=0;k32;k++)
   no*=2;
  no=no-j;
  cout\n The reverse isno;
  getch();
  return 0;
  }

On 7/22/11, nicks crazy.logic.k...@gmail.com wrote:
 see this

 http://geeksforgeeks.org/?p=726

 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote:

 reverse(int n)
 {
int i, result = 0;

for(i = 0; i  32; i++)
   result |= ((n  i)  1)  (31 - i);
 }


  assuming 32 bit integer to be reversed and assuming all 32 bits
 to be reversed.. i.e 100101 reverses to
 10100100

 --
 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: Microsoft Question!

2011-07-22 Thread Puneet Gautam
sorry guys.. dont check the above siolution.. its wrong...!!!
misread it..


On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote:
 check this out: Considering all 4 bytes of int with no left or right
 shifts..!!
 ;)

 main()
 { unsigned int i,j,k,no=1;
   j=4;
   for(k=0;k32;k++)
no*=2;
   no=no-j;
   cout\n The reverse isno;
   getch();
   return 0;
   }

 On 7/22/11, nicks crazy.logic.k...@gmail.com wrote:
 see this

 http://geeksforgeeks.org/?p=726

 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com
 wrote:

 reverse(int n)
 {
int i, result = 0;

for(i = 0; i  32; i++)
   result |= ((n  i)  1)  (31 - i);
 }


  assuming 32 bit integer to be reversed and assuming all 32 bits
 to be reversed.. i.e 100101 reverses to
 10100100

 --
 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] Coding..........

2011-07-22 Thread Puneet Gautam
@sunny: got dat...


On 7/22/11, saurabh singh saurab...@gmail.com wrote:
 So many why's..:)
 I was just trying to explain the queries about the divide and conquer asked
 above.+1 to u sunny.

 On Fri, Jul 22, 2011 at 1:26 PM, sunny agrawal
 sunny816.i...@gmail.comwrote:

 Yes thats true,
 but that will take O(n) extra space in merging step, isn't it ?
 and if we have to use O(n) space why dont just use O(n) algorithm !!

 On Fri, Jul 22, 2011 at 1:18 PM, saurabh singh saurab...@gmail.comwrote:

 For people who like the generic way,its merge sort only difference is
 where comp(a,b) returns true when a%2=1a%2=0.
 Rest its same.

 On Fri, Jul 22, 2011 at 1:12 PM, sunny agrawal
 sunny816.i...@gmail.comwrote:

 Divide and Conquer Algorithm : Just like merge Sort of Quick
 sort...we just need to modify the merge step of merge sort or
 Partition
 step of Quick sort

 lets call our this method Arrange();
 //just as merge step takes two sorted arrays and make one completely
 sorted one
 it takes 2 arrays which are already in the required form (first even nos
 then odds)

 then these two arrays will look like
 EVEN1 ODD1 EVEN2 ODD2
 and we need to arrange them as
 EVEN1 EVEN2 ODD1 ODD2

 so we just need to swap middle part or rotate middle part that will take
 O(n) time in worst case and depth of recursion will be O(lgn) hence
 O(nlgn)

 recursive calls will end when size of subarray is less than or equal to
 2
 i leave it to you how to handle base cases of recursion :) :D

 Ex. 1,2,3,4

 will call to (1,2), (3,4)
 after solving both the basecases
 arrays will be (2,1) (4,3)
 now arrange function will just swap the ODD1 and EVEN2
 result will be (2,4,1,3)

 On Fri, Jul 22, 2011 at 12:36 PM, Puneet Gautam puneet.nsi...@gmail.com
  wrote:

 @sunny: how do u do it by Divide n conquer ...can u provide the
 algo...?


 On 7/22/11, UMESH KUMAR kumar.umesh...@gmail.com wrote:
  Anybody try for maintain the stable of elements in O(n) as like
 
  Input is :{1,2,3,4,5,6,7}
  then Output should be
 (2,4,6,1,3,5,7)
  not..
 
  {2,4,6,1,5,3,7} base on above discussion ..
 
  --
  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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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.




 --
 Saurabh Singh
 B.Tech (Computer Science)
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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.




 --
 Saurabh Singh
 B.Tech (Computer Science)
 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] Re: How can we find size of system stack in C

2011-07-21 Thread Puneet Gautam
@rshetty: how do we find the size of one recursive call to main() ?

On 7/21/11, poised dip10c...@gmail.com wrote:
 I was asked the same question related to array size. [you can't use
 sizeof()]
 The question checked the awareness of try and catch (exception handling) in
 any language.

 I think we need to reach till the point of buffer overflow for the question
 asked here.

 But any other clean trick also welcome :)

 --
 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/-/GyUSeQ6djIAJ.
 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] Coding..........

2011-07-21 Thread Puneet Gautam
What is meant by maintaining the stability...?
pls tell me...!!
Thanks.

On 7/22/11, atul purohit gonewiththe...@gmail.com wrote:
 here in O(n) and stable


 void swap (int *a,int *b) {
 int t;
 t=*a;
 *a=*b;
 *b=t;
 }

 int main(void) {
int a[] = {12, 34, 45, 9, 8, 90, 3},odd=0,even=0,n=7;
while(oddn  even  n) {
 if(a[even]%2==0){
 if(odd==even)
 odd++;
 even++;
 }
 else if(a[even]%2==1) {
 while(a[odd]%2 != 0  odd  n+1) {
 odd++;
 }
 if(odd  n){
 swap(a[even],a[odd]);
 even++;
 }
 }
 }
 for(int i=0;in;i++)
 couta[i] ;
 getchar();
 }



 On Thu, Jul 21, 2011 at 11:55 PM, muruga vel
 murugavidya1...@gmail.comwrote:


 left=0;right=n-1;
 while(leftright)
 {
  while(leftright  a[left]%2==0)
   left++;
 while(leftright  a[right]%2==1)
   right--;
 if(leftright)
  {
   swap(a[l],a[r]);
l++;
r--;
 }
 O(n)


 On Thu, Jul 21, 2011 at 11:49 PM, Abhishek Sharma
 jkabhishe...@gmail.comwrote:

 small change in the pseudocode..


 for (i=0 until i+ a[].length){

 if (*leftptr % 2 == 0)
  A2[i] = *leftptr ;

 else if (*rtptr % 2 == 0)

  A2[i+a[].length-1] = *rtptr ;

 leftptr++;
 rtptr--;


 }

  --
 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.




 --

 Atul Purohit

 --
 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] Coding..........

2011-07-21 Thread Puneet Gautam
@atul: thanks..!


On 7/22/11, atul purohit gonewiththe...@gmail.com wrote:
 @puuneet
 http://en.wikipedia.org/wiki/Sorting_algorithm#Stability

 On Fri, Jul 22, 2011 at 10:57 AM, Puneet Gautam
 puneet.nsi...@gmail.comwrote:

 What is meant by maintaining the stability...?
 pls tell me...!!
 Thanks.

 On 7/22/11, atul purohit gonewiththe...@gmail.com wrote:
  here in O(n) and stable
 
 
  void swap (int *a,int *b) {
  int t;
  t=*a;
  *a=*b;
  *b=t;
  }
 
  int main(void) {
 int a[] = {12, 34, 45, 9, 8, 90, 3},odd=0,even=0,n=7;
 while(oddn  even  n) {
  if(a[even]%2==0){
  if(odd==even)
  odd++;
  even++;
  }
  else if(a[even]%2==1) {
  while(a[odd]%2 != 0  odd  n+1) {
  odd++;
  }
  if(odd  n){
  swap(a[even],a[odd]);
  even++;
  }
  }
  }
  for(int i=0;in;i++)
  couta[i] ;
  getchar();
  }
 
 
 
  On Thu, Jul 21, 2011 at 11:55 PM, muruga vel
  murugavidya1...@gmail.comwrote:
 
 
  left=0;right=n-1;
  while(leftright)
  {
   while(leftright  a[left]%2==0)
left++;
  while(leftright  a[right]%2==1)
right--;
  if(leftright)
   {
swap(a[l],a[r]);
 l++;
 r--;
  }
  O(n)
 
 
  On Thu, Jul 21, 2011 at 11:49 PM, Abhishek Sharma
  jkabhishe...@gmail.comwrote:
 
  small change in the pseudocode..
 
 
  for (i=0 until i+ a[].length){
 
  if (*leftptr % 2 == 0)
   A2[i] = *leftptr ;
 
  else if (*rtptr % 2 == 0)
 
   A2[i+a[].length-1] = *rtptr ;
 
  leftptr++;
  rtptr--;
 
 
  }
 
   --
  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.
 
 
 
 
  --
 
  Atul Purohit
 
  --
  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.




 --

 Atul Purohit

 --
 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.



[algogeeks] Starting the journey

2011-07-07 Thread Puneet Gautam
Hi everyone... umm i am a bit new to algo applications in programming..
can anyone pls tell me what all is important in algorithms? ,From
companies point of view...
I have studied upto ch-13 of the book Cormen.

Thanks..

-- 
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.