Re: [algogeeks] Re:

2013-06-21 Thread shubham saini
thanx Don for your algos, bt i m not able to understand your second
approach can you please explain it a liitle


On Fri, Jun 21, 2013 at 9:50 PM, Don  wrote:

> int bitCount(int n)
> {
>if (n < 3) return n;
>int x=31-__builtin_clz(n);
>n -= 1<return x*(1<<(x-1)) + bitCount(n) + n + 1;
>
>  }
>
> On Thursday, June 20, 2013 11:03:35 PM UTC-4, shubham saini wrote:
>
>> How to count no of set bits for all numbers from 1 to n for a given n...
>>
>> i knew brute force any better solution ??
>>
>  --
> 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.
>
>
>

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




[algogeeks]

2013-06-20 Thread shubham saini
How to count no of set bits for all numbers from 1 to n for a given n...

i knew brute force any better solution ??

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




[algogeeks] c++ this pointer

2013-06-05 Thread shubham saini
#include
using namespace std;

class Test
{
private:
  int x;
  int y;
public:
  Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
  void setX(int a) { x = a; }
  void setY(int b) { y = b; }
  void destroy()  { delete this;
cout<<"x="

Re: [algogeeks] What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.

2013-05-27 Thread Shubham Singh
Rope Data Structure is best suited for text editors.


On Sat, May 25, 2013 at 10:24 PM, Nishant Pandey <
nishant.bits.me...@gmail.com> wrote:

> In one of the interview it was asked, can some one suggest good DS for
> this.
>
> Thanks
>
>  --
> 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.
>
>
>

-- 
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] help with o/p why 0 comes???

2013-03-04 Thread Shubham Sandeep
on my system every time o/p is 0
using ubuntu 10.04 ,gcc compiler

On Mon, Mar 4, 2013 at 7:34 AM, rohit jangid  wrote:

> output for me for the previous snippet
>
> localhost:slingshot rohitjangid$ ./a.out
> 1799476872
> 1799474584
> localhost:slingshot rohitjangid$ ./a.out
> 1710327432
> 1710325144
> localhost:slingshot rohitjangid$ ./a.out
> 1856128648
> 1856126360
> localhost:slingshot rohitjangid$ ./a.out
> 1724065416
> 1724063128
>
>
> On Mon, Mar 4, 2013 at 7:33 AM, rohit jangid wrote:
>
>> yeah true . one interesting thing I noticed is that if you run this code
>>
>> #include
>> int main()
>> {
>> int i = 0;
>> do {
>> printf ("%d\n",(float)1);
>> }while(i++ < 1);
>> return 0;
>> }
>>
>> one would expect same output in both the rows but surprisingly it came
>> different for me every time .
>> any clues .. why ?
>>
>>
>>
>>
>> On Fri, Mar 1, 2013 at 12:05 PM, Karthikeyan V.B wrote:
>>
>>> O/p will not be 0.
>>>
>>> 1.00 is the result which when read as %d takes the decimal value of
>>>  stored in memory - it will not be 1.00 or 0.
>>>
>>> Since float is not stored as direct binary in memory as integer is
>>> stored, instead there's a separate procedure for storing float as binary in
>>> memory
>>>
>>> --
>>> 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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Rohit Jangid
>> Graduate
>> Deptt. of Computer Engineering
>> NSIT, Delhi University, India
>>
>>
>
>
> --
> Rohit Jangid
> Graduate
> Deptt. of Computer Engineering
> NSIT, Delhi University, India
>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: separate coins into heaps of similar weights using balance in minimum comparisons

2013-03-01 Thread Shubham Sandeep
@dave you are correct but language of question implies---> out of 8 coins 3
taken together weigh x,again 3 coins taken out of 8 have y as weight . This
shows that one or more coins out of 3 (weight x) may be same as those
considered for weight y as so on for z and w.

On Sat, Mar 2, 2013 at 2:39 AM, Dave  wrote:

> @Maddy: I'm a little confused because there are 8 coins in the bag but 3 +
> 3 + 2 + 2 = 10 coins are grouped by weight.
>
> Dave
>
> On Friday, March 1, 2013 1:15:03 PM UTC-6, maddy wrote:
>
>>
>> There are 8 coins in a bag .
>> 3 coin weights x kg
>> 3 coins weights y kg
>> 2 coins weights z kg
>> 2 coins weights w kg
>> You have to separate them into separate heaps according to
>> their weights in minimum comparisons using weighing balance.
>>
>>
>> --
>> Regards,
>> SHUBHAM SANDEEP
>> IT 3rd yr.
>> NIT ALD.
>>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] separate coins into heaps of similar weights using balance in minimum comparisons

2013-03-01 Thread Shubham Sandeep
There are 8 coins in a bag .
3 coin weights x kg
3 coins weights y kg
2 coins weights z kg
2 coins weights w kg
You have to separate them into separate heaps according to
their weights in minimum comparisons using weighing balance.


-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] help with o/p why 0 comes???

2013-02-28 Thread Shubham Sandeep
thank you for pointing out that format was the key point.

On Fri, Mar 1, 2013 at 1:19 AM, gmagog...@gmail.com wrote:

> I think this is because of type mismatch. You are enforcing your program
> to read a floating point number in the way of reading a integer. And they
> have totally different format. If you have -Wall turned on, you should see
> a warning.
>
> Yanan Cao
>
>
> On Thu, Feb 28, 2013 at 1:41 PM, Shubham Sandeep <
> s.shubhamsand...@gmail.com> wrote:
>
>> code snippet:
>> *int main()
>> {
>> printf ("%d\n",(float)((int)(3.5/2)));
>> return 0;
>> }*
>>
>>
>> --
>> Regards,
>> SHUBHAM SANDEEP
>> IT 3rd yr.
>> NIT ALD.
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] help with o/p why 0 comes???

2013-02-28 Thread Shubham Sandeep
code snippet:
*int main()
{
printf ("%d\n",(float)((int)(3.5/2)));
return 0;
}*

-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] how does this code achieve SIGSEGV

2012-12-22 Thread Shubham Sandeep
thank you sir, very well explained .

On Sat, Dec 22, 2012 at 12:47 PM, saurabh singh  wrote:

> **p; *
> Explanation: By default C thinks everything is an int. So p is a global
> variable of type *pointer to an int.*Now like other global variables it
> is very very very very likely  that the compiler will associate p with an
> address that is *0.*Or in terms of pointers it is  *NULL.* That is
> printf("%d\n",p) should give 0.
> **p=0;*
> *
> *
> What happens when you do **(some_ptr)? *The address stored by some_ptr is
> referred to. So when we try to do **p=0 the address pointed by p is
> referred,which is NULL,and by the law of the land trying to read/write from
> memory with address NULL is sin. *So you get segmentation fault.
>
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
> On Sat, Dec 22, 2012 at 10:52 AM, Saurabh Paliwal <
> saurabh.paliwa...@gmail.com> wrote:
>
>> I am afraid both of you are incorrect..
>> 1. since the code modified by you will compile but give sigsegv anyway.
>> 2. The statement " *p = 0; " has nothing to do with the " random address"
>> you are talking about.
>>
>>
>> On Mon, Dec 17, 2012 at 7:25 PM, Prakhar Jain wrote:
>>
>>> You are initialising random memory address with 0, which OS doesn't
>>> allow.
>>>
>>> On 12/17/12, Shubham Sandeep  wrote:
>>> > how does this code achieve SIGSEGV
>>> > code:
>>> >  *p;main(){*p=0;}
>>> >
>>> > --
>>> > Regards,
>>> > SHUBHAM SANDEEP
>>> > IT 3rd yr.
>>> > NIT ALD.
>>> >
>>> > --
>>> >
>>> >
>>> >
>>>
>>>
>>> --
>>> --
>>> Prakhar Jain
>>> IIIT Allahabad
>>> B.Tech IT 4th Year
>>> Mob no: +91 9454992196
>>> E-mail: rit2009...@iiita.ac.in
>>>   jprakha...@gmail.com
>>>
>>> --
>>>
>>>
>>>
>>
>>
>> --
>>  -Saurabh Paliwal
>>
>>B-Tech. Comp. Science and Engg.
>>
>>IIT ROORKEE
>>
>> --
>>
>>
>>
>
>  --
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 




Re: [algogeeks] Re: adobe apti question

2012-12-17 Thread Shubham Sandeep
agreed

On Mon, Dec 17, 2012 at 10:03 AM, marti  wrote:

> Yes Rahul Sharma. you are right. the ans is 1and3 or 2and3
>
>
> On Sunday, December 16, 2012 11:18:57 PM UTC+5:30, rahul sharma wrote:
>
>> A causes B or C, but not both
>> F occurs only if B occurs
>> D occurs if B or C occurs
>> E occurs only if C occurs
>> J occurs only if E or F occurs
>> D causes G,H or both
>> H occurs if E occurs
>> G occurs if F occurs
>>
>> 6. If A occurs which of the following must occurs
>>
>> I. F and G
>> II. E and H
>> III. D
>>
>> (a) I only
>> (b) II only
>> (c) III only
>> (d) I,II, & III
>> (e) I & II (or) II & III but not both
>>
>> Ans. (e)
>> E option should be 1&111  or 11&3
>> am i ryt???
>> A-> b or c.
>> if A->Bthen B->f&g   and Delse if A->C   ,then   c->e&h and c->d
>>
>> am i ryt
>>
>  --
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 




[algogeeks] how does this code achieve SIGSEGV

2012-12-17 Thread Shubham Sandeep
how does this code achieve SIGSEGV
code:
 *p;main(){*p=0;}

-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 




Re: [algogeeks] Re: Amazon interview Question

2012-12-16 Thread Shubham Sandeep
hello all... anwer to previous example would be "5436827" instead of
"5436872"please correct it :)

On Sun, Dec 16, 2012 at 11:48 PM, marti  wrote:

> Here is what you do
>
> EG: 5436782
>
> ans is 5436872
>
> how did we arrive?
>
> FInd least index i, such that a[i-1] >= a[i] starting from rigthmost
> 5436782
>   (8)
> Now , Find least index j such that a[j-1] <= a[i-1]:
>
> 5436782
>(7)
>
> swap them
>
> => 5436872
>
> Now swap all values between i and j.
>
> Pseudocode in Python:
>
> *def get_next(a):*
> *N = len(a)*
> *i = len(a)-1*
> *
> *
> *while a[i-1] >= a[i]:*
> *i -= 1*
> *
> *
> *j = N*
> *
> *
> *while a[j-1] <= a[i-1]:*
> *j -= 1*
> *
> *
> *a[i-1], a[j-1] = a[j-1], a[i-1]*
> *
> *
> *i += 1*
> *j = N*
> *
> *
> *while i < j:*
> *a[i-1], a[j-1] = a[j-1], a[i-1]*
> *i+=1*
> *j-=1*
> *
> *
> *return a*
>
>
> Source:
> http://nicolas-lara.blogspot.in/2009/01/permutations.html
>
>
> On Friday, December 14, 2012 11:56:16 AM UTC+5:30, tapan rathi wrote:
>>
>> For a given number, find the next greatest number which is just greater
>> than previous one and made up of same digits.
>
>  --
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 




Re: [algogeeks] Re: adobe apti question

2012-12-16 Thread Shubham Sandeep
according to me option c holds
Reason:it is either that F&G or E&H pair occurs but both pairs cannot occur
as one is an oucome of B while other holds if C occurs. since either B or C
(but not both) may follow A... so point prooved. but D will always be there
weather B or C follows after A.
since "must occur" is asked my answer is option C

On Sun, Dec 16, 2012 at 11:39 PM, marti  wrote:

> Yes I feel (e) is the right option.
>
>
> On Sunday, December 16, 2012 11:18:57 PM UTC+5:30, rahul sharma wrote:
>>
>> A causes B or C, but not both
>> F occurs only if B occurs
>> D occurs if B or C occurs
>> E occurs only if C occurs
>> J occurs only if E or F occurs
>> D causes G,H or both
>> H occurs if E occurs
>> G occurs if F occurs
>>
>> 6. If A occurs which of the following must occurs
>>
>> I. F and G
>> II. E and H
>> III. D
>>
>> (a) I only
>> (b) II only
>> (c) III only
>> (d) I,II, & III
>> (e) I & II (or) II & III but not both
>>
>> Ans. (e)
>> E option should be 1&111  or 11&3
>> am i ryt???
>> A-> b or c.
>> if A->Bthen B->f&g   and Delse if A->C   ,then   c->e&h and c->d
>>
>> am i ryt
>>
>  --
>
>
>



-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 




[algogeeks] BST to DLL code: whats wrong with this code........

2012-09-02 Thread shubham jain
Hi 
I am trying to convert the BST to doubly linked list but I  am  getting 
desired output with this code Plz correct this code.

#include
#include
typedef struct tree mytree;
struct tree
{
   int data;
   mytree* left;
   mytree* right;
};

void insert(mytree** root,int data)
{
  if(*root==NULL)
  {
  mytree* node=(mytree*)malloc(sizeof(mytree));
  if(node==NULL)
  return;
  else
  {
node->data=data;
node->left=NULL;
node->right=NULL;
  }
  
  *root=node;
return;
  }
  else
  {
 if((*root)->data >=data)
   insert(&(*root)->left,data);
else
   insert(&(*root)->right,data);
  }
}

void traverse(mytree* ptr)
{
  if(ptr==NULL)  return;
  traverse(ptr->left);
  printf("%d\t",ptr->data);
  traverse(ptr->right);
}

void traversell(mytree* ptr)
{
  if(ptr==NULL)  return;
  while(ptr!=NULL)
  {
  printf("%d\t",ptr->data);
  ptr=ptr->right;
  }

}

void bst22ll(mytree** tree,mytree** head)
{
   static mytree* prev=NULL;
   if(*tree==NULL)  return;
   mytree* ptr=*tree;
   if((*tree)->left!=NULL)
   bst22ll(&(*tree)->left,head);
   *tree=ptr;
   if(*head==NULL)
{
  *head=*tree;
  (*head)->left==NULL;  
}
   else
{
  prev->right=*tree;
  (*tree)->left=prev;
}  
prev=*tree;

   if((*tree)->right!=NULL)
 {
 bst22ll(&(*tree)->right,head);
 }
} 



void bst2ll(mytree** tree)
{
  if(tree==NULL)  return;
  mytree* head=NULL; 
  mytree* prev=NULL;
  bst22ll(tree,&head);
  *tree=head;
}

int main()
{
mytree* tree=NULL;
insert(&tree,50);
insert(&tree,40);
insert(&tree,60);
insert(&tree,30);
insert(&tree,70);
insert(&tree,65);
insert(&tree,45);
insert(&tree,34);
traverse(tree); 
bst2ll(&tree);
printf("\n");
traversell(tree); 
printf("\n");
}


should print : 30  34  40  45  50  60  65 70
but printing:   30  34  40  45  50  60  70


Thank you
Shubham

-- 
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/-/XXMvBSg0t08J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] plz explain output y it is 1212

2012-08-17 Thread Shubham Sandeep
#include

main()

{

printf

(

"\%\d\

"

,

12

)

;

printf

(

"\%\

d\

"

,

12

)

;



}

-- 
Regards,
SHUBHAM SANDEEP
IT 3rd yr.
NIT ALD.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Oracle paper pattern

2012-08-08 Thread shubham jain
Has anyone appeared for oracle recentlyplz tell the pattern of the paper

-- 
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/-/IhEwqKaWLmAJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Explain the output of this code:

2012-06-16 Thread Shubham Sandeep
#include
main()
{
int a[] = {0,1,2,3,4};
int *p[] = {a,a+1,a+2,a+3,a+4};
int **pp= &p;
printf("%d, %d, %d ", *pp-a, pp-p, **pp);
pp++;
pp++;;
++pp;
*++pp;
printf("%d, %d, %d ", pp-p, *pp-a, **pp);
 }

output:0 ,0 ,0 ,4 ,4 ,4

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



Re: [algogeeks] Directi Question

2012-06-15 Thread Shubham Sandeep
wat constraints does dis bring in the question... "Also the books are
arranged in a certain order and this order must never be changed."
does this imply ---> a student gets only consecutivly numbered book

if not then>
sort the array B in decreasing order in Onlogn
take another array S of k elements
traverse B(sorted)
S[i]=B[i]
when first k elemnts traversed then traverse again k elemnts of B and
S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed
completely..

On Sat, Jun 16, 2012 at 2:22 AM, Hemesh Singh wrote:

> At first look it appears to be  a simple problem of discrete binary
> search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then
> apply a simple binary search for the number of pages that can be given to a
> student. Complexity : O(N log( sum( B ) ) )
>
>
>
> On Thu, Jun 14, 2012 at 12:26 PM, algogeek 
> wrote:
>
>> In a library there are N books with the number of pages in i th book
>> given by bi . These books are to be distributed among K  students such that
>> the difference between the largest sum of pages in the books assigned to
>> any student and the smallest sum of number of pages in the books assigned
>> to any student is minimum for the given input. Also the books are arranged
>> in a certain order and this order must never be changed.
>> For eg:
>> suppose B[ ] contains the number of pages in each book.
>> then
>> N=6
>> K=3
>> B={3,7,8,2,6,4}
>>
>> then the output will be 0 as we can give book 1 and 2 to student 1 and
>> book 3 and 4 to student 2 and the remaining to student 3. That makes 10
>> pages for student 1 10 for 2 and 10 for 3 and thus the difference is 0
>>
>> similarly if B={3,6,8,2,6,4} then the minimum difference will be 1 .
>>
>>
>>
>>
>>
>>
>> --
>> 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/-/JjKITS_gN9UJ.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Hemesh singh
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Microsoft Interview Question

2012-06-15 Thread Shubham Sandeep
@guneesh your code fails to keep order b/w 3 and 4 in the above example

On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh wrote:

> void change(int a[],int n)
> {
> int i,j;
> i=0;
> j=1;
>
> while(i {
> if(j j=i+1;
> else if(a[j]<0&&a[i]>0)
> {
> swap(a,j,i);
> }
> else
> {
> if(a[j]>0)
> j++;
> else
> i++;
> }
> }
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Algo for Search in a 2D Matrix

2011-10-09 Thread shubham goyal
im assuming it be a square matrix
then kth smallest element will be in a first k*k sub matrix.
jst look for smallest element in the diagonal of this matrix.
it will give the kth smallest element .


On Mon, Oct 10, 2011 at 4:45 AM, Ankur Garg  wrote:

> Given a 2D matrix which is both row wise and column wise sorted. Propose an
> algorithm for finding the kth smallest element in it in least time
> complexity
>
> A General Max Heap can be used with k space and n+klogk complexity
>
> Any other solution  or even a way by which we dont scan the whole matrix to
> find the solution ?
>
> I
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] help

2011-10-05 Thread SHUBHAM BANSAL
can anybody tell me about INFOEDGE working culture?

--
Shubham bansal
contact no. 7206338328
NIT Kurukshetra
Computer Engineering
(Final year)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] sol

2011-08-20 Thread SHUBHAM BANSAL
((a^b) | ((a&b)<<1))
sorry tht was bitwise or..by mistak i hd wrote logicl or
SHUBHAM BANSAL
COMP DEPT..
NIT KKr


On Sun, Aug 21, 2011 at 9:30 AM, Sanjay Rajpal  wrote:

> Yes if a or b are non zero, the result is always 1.
> Sanju
> :)
>
>
>
> On Sat, Aug 20, 2011 at 8:57 PM, Naman Mahor wrote:
>
>> @sanjay
>> assume that the value of a=0,b=0;
>> so a^b=0
>> and (a&b)<<1 =0
>> so answer will zero.
>> so the result will not always 1. it can be 0 or 1 depends on the value of
>> a n b.
>>
>>
>> On Sun, Aug 21, 2011 at 12:12 AM, Sanjay Rajpal  wrote:
>>
>>>  || is a short-circuit operator(LOGICAL OR).
>>>
>>> if first condition is true, then second is not evaluated, only if first
>>> is false, second is evaluated.
>>>
>>> If a==b, then second condition will evaluate to true, else first
>>> condition will be evaluated, which are true here both.
>>>
>>> So the result is always 1.
>>> Sanju
>>> :)
>>>
>>>
>>>
>>> On Sat, Aug 20, 2011 at 11:37 AM, Atul Modi  wrote:
>>>
>>>> || is not bitwise or...it is logical orso it is basically for the
>>>> two ops (a^b) being succesful n (a&b)<<1 returning 1 on successthus the
>>>> ans. is 1 i think
>>>>
>>>> On Sat, Aug 20, 2011 at 11:59 PM, Aditya Virmani <
>>>> virmanisadi...@gmail.com> wrote:
>>>>
>>>>> @priya..wht if a=b=0 ? or a=b= 1000 
>>>>>
>>>>>  On Sat, Aug 20, 2011 at 11:33 PM, priya ramesh <
>>>>> love.for.programm...@gmail.com> wrote:
>>>>>
>>>>>> the answer is 1
>>>>>> sum=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.
>>>>>>
>>>>>
>>>>>   --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from 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] sol

2011-08-20 Thread SHUBHAM BANSAL
sum=((a^b) || ((a&b)<<1));
 

-- 
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/-/47RmEJcjv6kJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 shubham
Hi,

we can show that

(x/3)  = (x/2) - (x/4) + (x/8) - (x/16) +  infinity

Proof:
let s1 = (x/2)+(x/8)+(x/32)+...infinity = (x/2)/(1-(1/4))   [Geometric 
Progression , common Ratio(r) = 1/4]
& s2 = (x/4)+(x/16)+(x/64)+...infinity = (x/4)/(1-(1/4))   [Geometric 
Progression , common Ratio(r) = 1/4]

now s1-s2 upon simplifying becomes (x/3)

Implementation:

x1=x>>1;
x2=x>>2;
s1=x1;
s2=x2;
while(x1 || x2){
  s1+=x1>>2;
  s2+=x2>>2;
  x1>>=2;
  x2>>=2;
}
return s1-s2;

If the number is not divisible by 3 the answer returned is the least integer 
function of (x/3)
correct me if i am wrong...

-- 
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/-/YZjVTMk5JvEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Direct - i ques

2011-07-31 Thread Shubham Maheshwari
i am givin solution for implementing a queue or a stack ...
in which ...inserting, delelting and finding min element is of O(1).

hope this is clear now ...

On Sun, Jul 31, 2011 at 3:19 PM, Abhishek Gupta wrote:

> Qn is : Create a data structure where inserting, deleting and finding the
>
> minimum element all have O(1) time.
>
> so after deleting the minimum element, where will you point min pointer?
>
> Sorry if i m wrong
>
>
> On Sun, Jul 31, 2011 at 3:11 PM, Shubham Maheshwari  > wrote:
>
>> the operation is nt extract min ... its *find* min ...
>>
>>
>>
>> On Sun, Jul 31, 2011 at 3:02 PM, Abhishek Gupta 
>> wrote:
>>
>>> @shubham maheshawari
>>>
>>> deletion can't be performed in O(1).
>>> after extracting the min element, we need to find the next minimum
>>> element, and worst case will take O(n) time.
>>>
>>> On Sun, Jul 31, 2011 at 3:00 PM, Shubham Maheshwari <
>>> shubham@gmail.com> wrote:
>>>
>>>> hw cn u ensure that the elements are inserted in sorted order ...
>>>> wat if the elements are coming randmly ...
>>>>
>>>> On Sun, Jul 31, 2011 at 2:49 PM, muthu raj wrote:
>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Use a circular linked list with elements being inserted in sorted
>>>>> order.
>>>>>
>>>>> Inserting minimum element :
>>>>>
>>>>> struct node *p;
>>>>> p is a pointer to last node in the circular singly linked list.
>>>>> newmin->next=p->next;
>>>>> p->next=newmin;
>>>>>
>>>>>
>>>>> Deleting minimum element:
>>>>>
>>>>> struct node *temp;
>>>>> temp=p->next;
>>>>> p->next=p->next->next;
>>>>> free(temp);
>>>>>
>>>>>
>>>>> Retrieving minimum element :
>>>>>
>>>>> return (p->next->ele);
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *Muthuraj R
>>>>> IV th Year , ISE
>>>>> PESIT , Bangalore*
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Jul 31, 2011 at 2:08 AM, naveen ms wrote:
>>>>>
>>>>>> @shubham...i have a doubt.can't the same be done with singly linked
>>>>>> list??
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from 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.
>>>>
>>>
>>>
>>>
>>> --
>>> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-31 Thread Shubham Maheshwari
http://ideone.com/IZKyN

could you plzz explain this to me ...!!
anyone ...

On Sun, Jul 31, 2011 at 1:56 AM, Kamakshii Aggarwal
wrote:

> @sanchit:no,not at all :)
>
>
> On Sun, Jul 31, 2011 at 1:55 AM, Sanchit Manchanda 
> wrote:
>
>> @kamakshi- sorry if you felt i was rude. :-\
>>
>>
>> On Sun, Jul 31, 2011 at 1:53 AM, aditi garg wrote:
>>
>>> some garbage value
>>>
>>>
>>> On Sun, Jul 31, 2011 at 1:51 AM, gaurav gupta wrote:
>>>
 then wat sud b the value of *(&a+1) since array is only defind for 5
 elements


 On Sun, Jul 31, 2011 at 1:48 AM, Sanchit Manchanda <
 sanchit...@gmail.com> wrote:

> yes it will print the next address in memory after the last element.
>
>
> On Sun, Jul 31, 2011 at 1:46 AM, gaurav gupta 
> wrote:
>
>> i understand much. thanx fr it. plz tell me if i hv to print &a+1 then
>> it sud print the next address after the last element
>>
>>
>> On Sun, Jul 31, 2011 at 1:40 AM, Sanchit Manchanda <
>> sanchit...@gmail.com> wrote:
>>
>>> @gaurav- &a takes you to the address 1st element of the array.
>>> &a+1 takes you to the next address after the last element. this mean
>>> if int is 4bits. then arrays of 5 int values is 20 bits. so *+1 *in
>>> &a+1 covers 20 bits in memory. similarly &a+2 covers next 20 bits. and 
>>> so
>>> on.
>>>
>>> where as &(*(a+1)) points to 1st element,&(*(a+2)) points to 2nd
>>> element and so on.
>>>
>>> i hope this helps
>>>
>>>
>>> On Sun, Jul 31, 2011 at 1:35 AM, gaurav gupta >> > wrote:
>>>
 so u mean der is difference between a and a[0]


 On Sun, Jul 31, 2011 at 1:30 AM, Kamakshii Aggarwal <
 kamakshi...@gmail.com> wrote:

> &a points to the array.so when u increment it by 1 it will get
> incremented by the size of array.
>
>
> On Sun, Jul 31, 2011 at 1:28 AM, gaurav gupta <
> grvgupta...@gmail.com> wrote:
>
>> &a+1 takes to the last element of the array bt is the logic behind
>> dis
>>
>>
>> On Sun, Jul 31, 2011 at 1:25 AM, Kamakshii Aggarwal <
>> kamakshi...@gmail.com> wrote:
>>
>>> &a+1 will point to the next array(i.e it will skip the whole
>>> array)
>>> where as &(a+1)will print address of element 2.
>>>
>>> On Sun, Jul 31, 2011 at 1:21 AM, Sanchit Manchanda <
>>> sanchit...@gmail.com> wrote:
>>>
 Sorry my bad. I was wrong.

 On Sun, Jul 31, 2011 at 1:15 AM, gaurav gupta <
 grvgupta...@gmail.com> wrote:

> main()
> {
> int a[5]={1,2,3,4,5};
> printf("%d%d",&a+1,&(a+1));
> }
> plz explain me the difference in ans.
> thanx..
>
> --
> You received this message because you are subscribed to the
> Google Groups "Algorithm Geeks" group.
> To post to this group, send email to
> algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 Sanchit Manchanda
 COE(3rd year) , NSIT
 http://iblogmythots.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,
>>> 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.

Re: [algogeeks] Re: Direct - i ques

2011-07-31 Thread Shubham Maheshwari
the operation is nt extract min ... its *find* min ...



On Sun, Jul 31, 2011 at 3:02 PM, Abhishek Gupta wrote:

> @shubham maheshawari
>
> deletion can't be performed in O(1).
> after extracting the min element, we need to find the next minimum element,
> and worst case will take O(n) time.
>
> On Sun, Jul 31, 2011 at 3:00 PM, Shubham Maheshwari  > wrote:
>
>> hw cn u ensure that the elements are inserted in sorted order ...
>> wat if the elements are coming randmly ...
>>
>> On Sun, Jul 31, 2011 at 2:49 PM, muthu raj  wrote:
>>
>>>
>>>
>>>
>>>
>>>
>>> Use a circular linked list with elements being inserted in sorted order.
>>>
>>> Inserting minimum element :
>>>
>>> struct node *p;
>>> p is a pointer to last node in the circular singly linked list.
>>> newmin->next=p->next;
>>> p->next=newmin;
>>>
>>>
>>> Deleting minimum element:
>>>
>>> struct node *temp;
>>> temp=p->next;
>>> p->next=p->next->next;
>>> free(temp);
>>>
>>>
>>> Retrieving minimum element :
>>>
>>> return (p->next->ele);
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *Muthuraj R
>>> IV th Year , ISE
>>> PESIT , Bangalore*
>>>
>>>
>>>
>>>
>>> On Sun, Jul 31, 2011 at 2:08 AM, naveen ms wrote:
>>>
>>>> @shubham...i have a doubt.can't the same be done with singly linked
>>>> list??
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from 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.
>>
>
>
>
> --
> 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] BST

2011-07-31 Thread Shubham Maheshwari
take countr to be a static variable ... that shud do the job ...!!

btw ...if thats nt the case ... thn i m nt pretty sure wat u are asking to
be done ...

On Sun, Jul 31, 2011 at 2:12 AM, Rahul Mittal wrote:

> help me with this
> we need to find out how many times a function is recursively called
> while inserting a node in bst.
>
> insert (number X, node N)
>  increase the counter C by 1
>  if X is less than the number in node N
>   if N has no left child
>   create a new node with the number X and set
> it to be the left child of node N
>   else
>   insert (X, left child of node N)
>  else (X is greater than the number in node N)
>   if N has no right child
>   create a new node with the number X and set
> it to be the right child of node N
>   else
>   insert (X, right child of node N)
> we need value of count
> PS:this algorithm will exceed time limit
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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: Direct - i ques

2011-07-31 Thread Shubham Maheshwari
hw cn u ensure that the elements are inserted in sorted order ...
wat if the elements are coming randmly ...

On Sun, Jul 31, 2011 at 2:49 PM, muthu raj  wrote:

>
>
>
>
>
> Use a circular linked list with elements being inserted in sorted order.
>
> Inserting minimum element :
>
> struct node *p;
> p is a pointer to last node in the circular singly linked list.
> newmin->next=p->next;
> p->next=newmin;
>
>
> Deleting minimum element:
>
> struct node *temp;
> temp=p->next;
> p->next=p->next->next;
> free(temp);
>
>
> Retrieving minimum element :
>
> return (p->next->ele);
>
>
>
>
>
>
>
>
> *Muthuraj R
> IV th Year , ISE
> PESIT , Bangalore*
>
>
>
>
> On Sun, Jul 31, 2011 at 2:08 AM, naveen ms  wrote:
>
>> @shubham...i have a doubt.can't the same be done with singly linked list??
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Morgan stanely interview ques

2011-07-31 Thread Shubham Maheshwari
color and intensity are2 different things ...
do you mean to find pixels with same intensity ...!!

and wat is meant by "can be reached" ...!!

On Sun, Jul 31, 2011 at 2:40 PM, sivaviknesh s wrote:

> *Given an nxn screen, Each pixel is represented by intensity values.
> Given a specific pixel as an input, find the no. of pixels of the same
> colour which can reached from this pixel. Assume any suitable data structure
> for a screen.
>
> ..can this be implemented through BFS ...similar to BITMAP prob in spoj ??
> *
> --
> Regards,
> $iva
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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: Direct - i ques

2011-07-31 Thread Shubham Maheshwari
you mean circular linked list ...!!!
in case of stack ... we cn do it via SSL ...
for a queue implementation ... we will ned circular, or doubly for deletion
in O(1).

On Sun, Jul 31, 2011 at 2:38 PM, naveen ms  wrote:

> @shubham...i have a doubt.can't the same be done with singly linked list??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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: Direct - i ques

2011-07-31 Thread Shubham Maheshwari
its a *doubly* linked list ...
you can easily do the job ...

On Sun, Jul 31, 2011 at 2:23 PM, siva viknesh wrote:

> using LL u cant delete in O(1)  ... u have to traverse from head
>
> On Jul 31, 1:47 pm, Shubham Maheshwari  wrote:
> > use a doubly linked list ... with a field "node *min".
> > weneva you insert an element ... check for the value of min at the head
> ...
> > if the new inserted node has less value ... then set the min field to
> point
> > to itself  else copy the min field of te previous head.
> >
> > insertion and deletion is easy ... and I hope i dont need to expalin that
> > too ...
> >
> > On Sun, Jul 31, 2011 at 12:27 PM, siva viknesh  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Create a data structure where inserting, deleting and finding the
> > > minimum element all have O(1) time.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from 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] Tug of War

2011-07-31 Thread Shubham Maheshwari
wat if you had to divide the array in 'n' groups ...
and the difference in the number of members in any 2 groups should not be
more than '1'.
the difference between their cumulative strengths is to be minimized ...

On Sat, Jul 30, 2011 at 4:50 PM, Prashant Gupta wrote:

> Its NP problem. :-|
>
>
> On Sat, Jul 30, 2011 at 4:14 PM, saurabh singh wrote:
>
>> Its the same as we divide teams.Pick the Largest in one and second largest
>> in other,then putting the remaining best player to the team which is weaker.
>> the weakest get selected last.if the teams are not equal strength not
>> possible else possible.
>>
>> PS:I dont know whethr this algorithm will work.This solution is based
>> completely on my experiences of playing cricket,:)
>>
>>
>> On Sat, Jul 30, 2011 at 3:15 PM, shady  wrote:
>>
>>> equivalent to 2 set partition...
>>>
>>>
>>> On Sat, Jul 30, 2011 at 3:14 PM, sylvester  wrote:
>>>
 input  consists of N integers, separated by a space. The ith integer
 indicates the strength of the ith person.
 For each case, output "YES" if it is possible to pick some people from
 the group and separate into two teams of equal strengths else "NO"

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.
>>>
>>
>>
>>
>> --
>> 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.
>>
>
>
>
> --
> Prashant Gupta
> B.Tech Final Year
> Computer Science and Engineering
> NIT Trichy
> Phone : +91 9894462744
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Direct - i ques

2011-07-31 Thread Shubham Maheshwari
use a doubly linked list ... with a field "node *min".
weneva you insert an element ... check for the value of min at the head ...
if the new inserted node has less value ... then set the min field to point
to itself  else copy the min field of te previous head.

insertion and deletion is easy ... and I hope i dont need to expalin that
too ...

On Sun, Jul 31, 2011 at 12:27 PM, siva viknesh wrote:

> Create a data structure where inserting, deleting and finding the
> minimum element all have O(1) time.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] 32 bit?

2011-07-31 Thread Shubham Maheshwari
if OS installed is of 32 bit ... then compiler will work as working on a 32
bit architecture ... and give the results accordingly ...

@aditi :: i am not so sure abt your stateent regarding the size of pointer
and an int being th same ... could you plzz quote the reference for the same
...

On Sun, Jul 31, 2011 at 12:36 PM, aditi garg wrote:

> @Nikhil the size of pointer is same as int i guess...so it differs on diff
> machines...im not sure abt ur OS and architecture doubt tho...
>
>
> On Sat, Jul 30, 2011 at 8:02 PM, Nikhil Gupta 
> wrote:
>
>> One more query. What if the architecture is 64 bit, but the OS is 32 bit?
>> (Example windows XP)
>>
>> What will be the size of a pointer variable then?
>>
>>
>> On Sat, Jul 30, 2011 at 8:00 PM, Nikhil Gupta 
>> wrote:
>>
>>> @Aditi, Isn't the size of int variable 4 bytes in both the architectures?
>>>
>>> On Sat, Jul 30, 2011 at 12:52 PM, aditi garg 
>>> wrote:
>>>
 it can also be found out by using printf("%d",sizeof(int)*8);
 Correct me if i am wrong...


 On Sat, Jul 30, 2011 at 11:55 AM, rajeev bharshetty <
 rajeevr...@gmail.com> wrote:

> If pointer size is 4bytes then it is 32 bit machine and if 8 bytes it
> is 64 bit
>
>
> On Sat, Jul 30, 2011 at 11:51 AM, Nikhil Gupta <
> nikhilgupta2...@gmail.com> wrote:
>
>> How do you find out if a machine is 32 bit or 64 bit?
>>
>> I was thinking since the size of pointer variable is different in the
>> 2 configurations, we can declare a pointer and use sizeof()
>> Will that work?
>> Any other suggestions?
>>
>> --
>> Nikhil Gupta
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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 
>
> "*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.
>



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

>>>
>>>
>>>
>>> --
>>> Nikhil Gupta
>>> Senior Co-ordinator, Publicity
>>> CSI, NSIT Students' Branch
>>> NSIT, New Delhi, India
>>>
>>>
>>
>>
>> --
>> 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.
>>
>
>
>
> --
> 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: Novell - Puzzle

2011-07-31 Thread Shubham Maheshwari
for the cows ques ... you all are forgetting to add the orginal starting cow
...
thus the answer should be *233*

On Sun, Jul 31, 2011 at 1:30 PM, Nikhil Gupta wrote:

> Oops. My bad. Rabbits produce every month too.
> I overlooked that.
>
> On Sun, Jul 31, 2011 at 1:24 PM, Tushar Bindal wrote:
>
>> Suppose that our rabbits never die and that the female always
>> produces one new pair (one male, one female) *every month from the
>> second month on
>> *
>> @Priyanka
>> You have answer 288
>> I added 178 to it because I got the answer that 89 females would have
>> given birth in the last month.
>> Pls clarify.
>> Are you taking one month less or am I taking 1 more?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Tug of War

2011-07-30 Thread shubham
hey sylvester,
just clarify the problem ..

Is it such that in forming the group some people can be left out
or
the sum of the number of people in both partitions is equal to the total 
number of people

-- 
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/-/gVAGoc_nYhAJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Puzzle

2011-07-29 Thread shubham
Thanks Pareek...

-- 
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/-/QW10bdF2oYMJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Puzzle

2011-07-28 Thread shubham
answer is:

1 hr 20 mins.

But i don't know how to arrive at the solution.

help anyone..

-- 
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/-/-QFXfKOMKfIJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Puzzle

2011-07-28 Thread shubham
That's what i was provided with in the interview. Somehow i know the answer, 
but don't know how?

with the data provided above, you have to calculate the time it takes the 
man to reach the office from his home on car.

-- 
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/-/nkUI5p600nsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Puzzle

2011-07-28 Thread shubham
A man leaves his office daily at 07:00 PM. His driver arrives with the car 
from home to his office at sharp 07:00 PM. So he doesn't need to wait for 
any transport medium as soon he is free from his work. But today he finished 
his work early and left the office at 05:30 PM. As his driver was not there 
so he started moving towards his home on foot. After moving some distance he 
met the driver on the way (As the driver had no idea so he had started at 
the usual time) and took the car. When he reached his home he found that 
today he reached 20 minutes earlier than usual time. Then tell how much time 
it takes the man to reach his office on the normal day (with the car).

-- 
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/-/gn9AJcWvjuoJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: subwords in a given word!

2011-07-22 Thread Shubham Maheshwari
how are you gonna do it if the originl strng contains repeated letters ...

On Fri, Jul 22, 2011 at 3:33 PM, shady  wrote:

> what algorithm, print it subsequently
> is there any ?
>
>
> On Fri, Jul 22, 2011 at 3:24 PM, DeeJJ..! wrote:
>
>> @sunny...yaa..but can u just describe the algorithm..:)
>>
>> On Jul 22, 2:51 am, sunny agrawal  wrote:
>> > n+(n-1) +(n-2)++1 = O(n^2)
>> >
>> >
>> >
>> > On Fri, Jul 22, 2011 at 3:16 PM, DeeJJ..! 
>> wrote:
>> > > Q)complexity to find subwords in a given word?
>> > > ex: abcde
>> > > ans: a b c d e
>> > >   ab bc cd de
>> > >   abc bcd cde
>> > >   abcd bcde
>> > >   abcde
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Algorithm Geeks" group.
>> > > To post to this group, send email to algogeeks@googlegroups.com.
>> > > To unsubscribe from 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Interview Puzzle - 100 Prisoners and Caps

2011-07-22 Thread Shubham Maheshwari
could some1 plz post the xplainations ...

On Fri, Jul 22, 2011 at 8:04 PM, Pankaj  wrote:

> Chetan,
>
> No. How could you relate this problem with that? Do you find something
> similar?
>
> ~
> Pankaj
>
>
> On Fri, Jul 22, 2011 at 8:01 PM, chetan kapoor 
> wrote:
>
>> josehus problem???
>>
>>
>> On Fri, Jul 22, 2011 at 7:57 PM, Pankaj wrote:
>>
>>> Skipp Riddle,
>>> Yes.
>>> 100th prisoner will risk his life. Similar puzzle was discuss recently.
>>> Does anyone remember the name or thread?
>>>
>>>
>>> ~
>>> Pankaj
>>>
>>>
>>> On Fri, Jul 22, 2011 at 7:55 PM, SkRiPt KiDdIe 
>>> wrote:
>>>
 Worst case 99 get released.
 Is that correct..?

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

>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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 Shubham Maheshwari
thnx ...
:D

On Fri, Jul 22, 2011 at 9:19 PM, sagar pareek  wrote:

> gr8 shubham
>
> On Fri, Jul 22, 2011 at 1:42 PM, Shubham Maheshwari  > wrote:
>
>> x = 0;
>> while( n ){
>> x <<= 1;
>> x = x | ( n & 1);
>> n >>= 1;
>> }
>>
>> return x;
>>
>> On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam 
>> wrote:
>>
>>> sorry guys.. dont check the above siolution.. its wrong...!!!
>>> misread it..
>>>
>>>
>>> On 7/22/11, Puneet Gautam  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;k<32;k++)
>>> >no*=2;
>>> >   no=no-j;
>>> >   cout<<"\n The reverse is"<>> >   getch();
>>> >   return 0;
>>> >   }
>>> >
>>> > On 7/22/11, nicks  wrote:
>>> >> see this
>>> >>
>>> >> http://geeksforgeeks.org/?p=726
>>> >>
>>> >> On Fri, Jul 22, 2011 at 4:29 AM, adhyetha 
>>> >> 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.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> **Regards
> SAGAR PAREEK
> COMPUTER SCIENCE AND ENGINEERING
> NIT ALLAHABAD
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] Re: Microsoft Question!

2011-07-22 Thread Shubham Maheshwari
x = 0;
while( n ){
x <<= 1;
x = x | ( n & 1);
n >>= 1;
}

return x;

On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam wrote:

> sorry guys.. dont check the above siolution.. its wrong...!!!
> misread it..
>
>
> On 7/22/11, Puneet Gautam  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;k<32;k++)
> >no*=2;
> >   no=no-j;
> >   cout<<"\n The reverse is"< >   getch();
> >   return 0;
> >   }
> >
> > On 7/22/11, nicks  wrote:
> >> see this
> >>
> >> http://geeksforgeeks.org/?p=726
> >>
> >> On Fri, Jul 22, 2011 at 4:29 AM, adhyetha 
> >> 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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Amazon ques

2011-07-20 Thread Shubham Maheshwari
dats much beter now ...
:D

On Wed, Jul 20, 2011 at 1:53 PM, saurabh singh  wrote:

> Let my code speak for me..:)
> http://www.ideone.com/E2LhU
>
> Try to get what I am doing from the code.Its not hard and believe me it
> will be fun.:)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Amazon ques

2011-07-20 Thread Shubham Maheshwari
@saurabh.
kindly use a lil bit of indentation ... ur algo is illegible.

On Wed, Jul 20, 2011 at 1:28 PM, saurabh singh  wrote:

> Q2 o(1) space o(n) sol.
> traverse through the array.
> do -1*a[abs(a[i])-1] if a[abs(a[i])-1) +ve else do nothing
> traverse again to check for the indexes with +ve values.
>
>
> On Wed, Jul 20, 2011 at 1:01 PM, Shubham Maheshwari <
> shubham.veloc...@gmail.com> wrote:
>
>>  let A:: ((n(n+1)/2) - sum)
>> let B:: ((n(n+1)(2n+1)/6) - (sum of squares of elements))
>>
>> then missing number = ((B/A) + A)/2;
>>
>> complexity O(n).
>> space complexity O(1).
>>
>> On Wed, Jul 20, 2011 at 12:47 PM, saurabh singh wrote:
>>
>>> Q1 can be solved using some simple maths:)
>>> Hint:What is the sum of first n natural numbers?"And what is the sum of
>>> squares of first n natural numbers?
>>>
>>>
>>> On Wed, Jul 20, 2011 at 12:44 PM, siva viknesh 
>>> wrote:
>>>
>>>> gn array - say a
>>>>
>>>> hav extra array - say b - initialise all values to zero
>>>>
>>>> ques 1:
>>>>
>>>> for(i=1;i<=n;i++)
>>>> {
>>>>b[a[i]]++;
>>>>
>>>> }
>>>>
>>>> then traverse b array and print i, for which b[i] = 2
>>>>
>>>> o(n) time & space
>>>>
>>>> same idea for ques 2
>>>>
>>>> better approaches please
>>>>
>>>> On Jul 20, 12:11 pm, siva viknesh  wrote:
>>>> > gn array - say a
>>>> >
>>>> > hav extra array - say b - initialise all values to zero
>>>> >
>>>> > ques 1:for(i=1;i<=n;i++)
>>>> > {
>>>> > b[a[i]]++;
>>>> >
>>>> > }
>>>> >
>>>> > On Jul 20, 12:07 pm, siva viknesh  wrote:
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > > 1.Given an array of size n. It contains numbers in the range 1 to n.
>>>> > > Each number is present at least once except for 2 numbers. Find the
>>>> > > missing numbers.
>>>> >
>>>> > > 2.Given an array of size n. It contains numbers in the range 1 to n.
>>>> > > Find the numbers which aren’t present.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from 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.
>>>
>>
>>
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Amazon ques

2011-07-20 Thread Shubham Maheshwari
let A:: ((n(n+1)/2) - sum)
let B:: ((n(n+1)(2n+1)/6) - (sum of squares of elements))

then missing number = ((B/A) + A)/2;

complexity O(n).
space complexity O(1).

On Wed, Jul 20, 2011 at 12:47 PM, saurabh singh  wrote:

> Q1 can be solved using some simple maths:)
> Hint:What is the sum of first n natural numbers?"And what is the sum of
> squares of first n natural numbers?
>
>
> On Wed, Jul 20, 2011 at 12:44 PM, siva viknesh wrote:
>
>> gn array - say a
>>
>> hav extra array - say b - initialise all values to zero
>>
>> ques 1:
>>
>> for(i=1;i<=n;i++)
>> {
>>b[a[i]]++;
>>
>> }
>>
>> then traverse b array and print i, for which b[i] = 2
>>
>> o(n) time & space
>>
>> same idea for ques 2
>>
>> better approaches please
>>
>> On Jul 20, 12:11 pm, siva viknesh  wrote:
>> > gn array - say a
>> >
>> > hav extra array - say b - initialise all values to zero
>> >
>> > ques 1:for(i=1;i<=n;i++)
>> > {
>> > b[a[i]]++;
>> >
>> > }
>> >
>> > On Jul 20, 12:07 pm, siva viknesh  wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > 1.Given an array of size n. It contains numbers in the range 1 to n.
>> > > Each number is present at least once except for 2 numbers. Find the
>> > > missing numbers.
>> >
>> > > 2.Given an array of size n. It contains numbers in the range 1 to n.
>> > > Find the numbers which aren’t present.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 questoin

2011-07-19 Thread Shubham Maheshwari
what is meant by unique string ...!!

On Tue, Jul 19, 2011 at 9:04 PM, SAMMM  wrote:

> There is only one unique string  in the list of strings (words) ?
>
>
> On Jul 19, 8:31 pm, "pacific :-)"  wrote:
> > Find unique string from a list of strings in one pass.
> >
> > --
> > regards,
> > chinna.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Solve it

2011-07-19 Thread Shubham Maheshwari
maintain 2 sums : incl and xclud.
incl is the sum of the elements including the previous element.
xclud is the sum of elements excluding the previous element.

now .. for evry element 1 to n-1.
set xclud = max(incl, xclud)
set incl = xclud (value from previous iteration) + a[i].

finally, print whicheva is the max.

On Tue, Jul 19, 2011 at 5:01 PM, Nitish Garg wrote:

> Typo in my above post.
> s[i] = max(s[i-2], s[i-2]+a[i], s[i-1]) work?
>
>
> On Tue, Jul 19, 2011 at 4:59 PM, Nitish Garg wrote:
>
>> Won't this recurrence work:
>> s[i] = max(s[i-2], s[i-2]+a[i], a[i-1]) work?
>> I think it works.
>>
>>
>> On Tue, Jul 19, 2011 at 4:54 PM, oppilas . wrote:
>>
>>> New constraint:-
>>> What if the array also contains positive and negative numbers?
>>>
>>> On Tue, Jul 19, 2011 at 4:36 PM, sagar pareek wrote:
>>>
>>>> ok ok ok thank you all
>>>>
>>>>
>>>> On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal 
>>>> wrote:
>>>>
>>>>> @Sagar: 13 is the correct answer. (6+4+3)
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Regards
>>>> SAGAR PAREEK
>>>> COMPUTER SCIENCE AND ENGINEERING
>>>> NIT ALLAHABAD
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] static vs dynamic array

2011-07-18 Thread Shubham Maheshwari
the 2.nd one is also working fine ...
check it out ..
http://www.ideone.com/ue96W

the given arguments are all correct .. bt since its returning a copy of it
to the main .. it'll work fine ...

On Mon, Jul 18, 2011 at 11:28 PM, sunny agrawal wrote:

> Yes thats right but a small but obvious correction which holds good till
> you explicitly call free function or...
>
>
> On Mon, Jul 18, 2011 at 10:49 PM, Swathi  wrote:
>
>> In first 1, you are using malloc() so the memory will be allocated from
>> heap which holds good till end of your program.. In second case, the memory
>> will be allocated on the stack.. so once the function is exited, your stack
>> data will be released...
>>
>>
>> On Mon, Jul 18, 2011 at 9:49 PM, rj7  wrote:
>>
>>> Can someone pls explain the difference between these two especially in
>>> terms of scope... one example i have come across is
>>>1.
>>>char *xxx(int n)
>>>{
>>>char *retbuf = malloc(25);
>>>if(retbuf == NULL)
>>>return NULL;
>>>sprintf(retbuf, "%d", n);
>>>return retbuf;
>>>}
>>>
>>>2.
>>>char *xxx(int n)
>>>{
>>>char retbuf[25];
>>>sprintf(retbuf, "%d", n);
>>>return retbuf;
>>>}
>>>
>>> First one is correct and the second one is wrong... why does the scope
>>> of retbuf extends to the calling function...
>>> am just a beginner so ignore the stupidity(if any).
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
the complexity of this func depends on the .include thing,
and if it were to be coded in C,
time cmplexity wud to to n^2.

On Tue, Jul 19, 2011 at 1:12 AM, Saket Choudhary  wrote:

> Ruby Solution for 1d array. The logic for 2d array remains same.
>
> a=[1,2,3,4,5,1]
> b=[]
> for m in a
>   unless b.include?(m)
> b<   else
> puts m
> break
>   end
> end
>
> On 19 July 2011 01:05, Saket Choudhary  wrote:
>
>> Have a hash Table. Read the elements and push it to the hash table. If it
>> alraedy exists you are done.
>>
>>
>> On 19 July 2011 01:02, Shubham Maheshwari wrote:
>>
>>> what would be the O(n^2) sol. to this ...!!
>>>
>>>
>>> On Tue, Jul 19, 2011 at 12:41 AM, snehi jain wrote:
>>>
>>>> can it be solved in less than O(n^2) like O(nlogn ) types..
>>>> i cant figure out any solution less than O(n^2).
>>>>
>>>>
>>>> On Tue, Jul 19, 2011 at 12:37 AM, ankit sambyal >>> > wrote:
>>>>
>>>>> @Snehi :If the elements are random, then it seems that this problem
>>>>> can't be solved in O(n) time
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Shubham Maheshwari
>>> ShubZz
>>> O.o o.O
>>>
>>> enJoY ...!!!
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
can we do anything else .. othr than hash tables ...

On Tue, Jul 19, 2011 at 1:05 AM, Saket Choudhary  wrote:

> Have a hash Table. Read the elements and push it to the hash table. If it
> alraedy exists you are done.
>
> On 19 July 2011 01:02, Shubham Maheshwari wrote:
>
>> what would be the O(n^2) sol. to this ...!!
>>
>>
>> On Tue, Jul 19, 2011 at 12:41 AM, snehi jain wrote:
>>
>>> can it be solved in less than O(n^2) like O(nlogn ) types..
>>> i cant figure out any solution less than O(n^2).
>>>
>>>
>>> On Tue, Jul 19, 2011 at 12:37 AM, ankit sambyal 
>>> wrote:
>>>
>>>> @Snehi :If the elements are random, then it seems that this problem
>>>> can't be solved in O(n) time
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from 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.
>>>
>>
>>
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
what would be the O(n^2) sol. to this ...!!

On Tue, Jul 19, 2011 at 12:41 AM, snehi jain  wrote:

> can it be solved in less than O(n^2) like O(nlogn ) types..
> i cant figure out any solution less than O(n^2).
>
>
> On Tue, Jul 19, 2011 at 12:37 AM, ankit sambyal wrote:
>
>> @Snehi :If the elements are random, then it seems that this problem
>> can't be solved in O(n) time
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Finding the Kth Prime

2011-07-17 Thread Shubham Maheshwari
@Dave: could you please extrapolate on the 'sequence point rule' a bit more.
i am nt familiar with it ...


On Sun, Jul 17, 2011 at 3:01 AM, Dave  wrote:

> @Anthony: Your code violates the sequence point rule, which states
> that the value of a variable can change at most one time between
> sequence points, and thus your code is nonstandard. The results of
> executing nonstandard code is undefined.
>
> Dave
>
> On Jul 15, 3:22 pm, Antony Kotre  wrote:
> > sorry I don't know how to post new thread so posting my query here and
> > please some one tell how to do that
> >
> > can any tell and explain the output of following code
> >
> > #include
> > main()
> > {   int a =5, b=5;
> > int res1=(++a)+(++a)+(++a);
> > int res2=(++b)+(++b)*10+(++b)*100;
> >
> > printf("%d\n%d\n",res1,res2);
> >
> >
> >
> > }- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

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



Re: [algogeeks] What is the output of the following program? Why?

2011-07-17 Thread Shubham Maheshwari
i wasnt sure abt the first part of it.
the one with multiple initializations ...
:P

On Sun, Jul 17, 2011 at 3:09 AM, sagar pareek  wrote:

> Well shubham if you know about the unions very well then why u asked this
> question?
>
>
> On Sun, Jul 17, 2011 at 2:27 AM, Shubham Maheshwari <
> shubham.veloc...@gmail.com> wrote:
>
>> :D
>>
>>
>> On Sun, Jul 17, 2011 at 2:24 AM, Kamakshii Aggarwal <
>> kamakshi...@gmail.com> wrote:
>>
>>> @shubham:yes u r right.thanks :)
>>>
>>>
>>> On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari <
>>> shubham.veloc...@gmail.com> wrote:
>>>
>>>> @Kamakshii:
>>>> thats probably becuz a union has a common memory location, accessed by
>>>> all its members.
>>>> so, the value '100' is treated as an int by 'a', as a char array by 'b'
>>>> and as a float by 'c'.
>>>> I thnk i read this read tis somewhere sometime back. ... so aint
>>>> completely sure abt it.
>>>>
>>>>
>>>> On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal <
>>>> kamakshi...@gmail.com> wrote:
>>>>
>>>>>
>>>>> u can always retrieve that value from the union that has been assigned
>>>>> last.therefore u get correct answer only for x.c
>>>>>
>>>>> in the case of union y
>>>>> y.a=100 and so the output
>>>>> but am not sure why y.b is printing character equivalent of 100.
>>>>>
>>>>>
>>>>> On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari <
>>>>> shubham.veloc...@gmail.com> wrote:
>>>>>
>>>>>> you mean to say .. the ques is wrong ... or what ...!!
>>>>>>
>>>>>>
>>>>>> On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek 
>>>>>> wrote:
>>>>>>
>>>>>>> I think you must first read about unions and the differences between
>>>>>>> union and structures :)
>>>>>>>
>>>>>>> On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari <
>>>>>>> shubham.veloc...@gmail.com> wrote:
>>>>>>>
>>>>>>>> "union" Data Type
>>>>>>>> What is the output of the following program? Why?
>>>>>>>> #include
>>>>>>>> main() {
>>>>>>>> typedef union {
>>>>>>>> int a;
>>>>>>>> char b[10];
>>>>>>>> float c;
>>>>>>>> }
>>>>>>>> Union;
>>>>>>>> Union x,y = {100};
>>>>>>>> x.a = 50;
>>>>>>>> strcpy(x.b,"hello");
>>>>>>>> x.c = 21.50;
>>>>>>>> printf("Union x : %d %s %f n",x.a,x.b,x.c);
>>>>>>>> printf("Union y : %d %s %f n",y.a,y.b,y.c);
>>>>>>>> }
>>>>>>>>
>>>>>>>> --
>>>>>>>> Shubham Maheshwari
>>>>>>>> ShubZz
>>>>>>>> O.o o.O
>>>>>>>>
>>>>>>>> enJoY ...!!!
>>>>>>>>
>>>>>>>>  --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>>>> For more options, visit this group at
>>>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> **Regards
>>>>>>> SAGAR PAREEK
>>>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>>>> NIT ALLAHABAD
>>>>>>>
>>>>>>>  --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>> To post to this group, send email to algogeeks@go

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
:D

On Sun, Jul 17, 2011 at 2:24 AM, Kamakshii Aggarwal
wrote:

> @shubham:yes u r right.thanks :)
>
>
> On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari <
> shubham.veloc...@gmail.com> wrote:
>
>> @Kamakshii:
>> thats probably becuz a union has a common memory location, accessed by all
>> its members.
>> so, the value '100' is treated as an int by 'a', as a char array by 'b'
>> and as a float by 'c'.
>> I thnk i read this read tis somewhere sometime back. ... so aint
>> completely sure abt it.
>>
>>
>> On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal <
>> kamakshi...@gmail.com> wrote:
>>
>>>
>>> u can always retrieve that value from the union that has been assigned
>>> last.therefore u get correct answer only for x.c
>>>
>>> in the case of union y
>>> y.a=100 and so the output
>>> but am not sure why y.b is printing character equivalent of 100.
>>>
>>>
>>> On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari <
>>> shubham.veloc...@gmail.com> wrote:
>>>
>>>> you mean to say .. the ques is wrong ... or what ...!!
>>>>
>>>>
>>>> On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek wrote:
>>>>
>>>>> I think you must first read about unions and the differences between
>>>>> union and structures :)
>>>>>
>>>>> On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari <
>>>>> shubham.veloc...@gmail.com> wrote:
>>>>>
>>>>>> "union" Data Type
>>>>>> What is the output of the following program? Why?
>>>>>> #include
>>>>>> main() {
>>>>>> typedef union {
>>>>>> int a;
>>>>>> char b[10];
>>>>>> float c;
>>>>>> }
>>>>>> Union;
>>>>>> Union x,y = {100};
>>>>>> x.a = 50;
>>>>>> strcpy(x.b,"hello");
>>>>>> x.c = 21.50;
>>>>>> printf("Union x : %d %s %f n",x.a,x.b,x.c);
>>>>>> printf("Union y : %d %s %f n",y.a,y.b,y.c);
>>>>>> }
>>>>>>
>>>>>> --
>>>>>> Shubham Maheshwari
>>>>>> ShubZz
>>>>>> O.o o.O
>>>>>>
>>>>>> enJoY ...!!!
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> **Regards
>>>>> SAGAR PAREEK
>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>> NIT ALLAHABAD
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Shubham Maheshwari
>>>> ShubZz
>>>> O.o o.O
>>>>
>>>> enJoY ...!!!
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from 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.
>>>
>>
>>
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

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



Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
@Kamakshii:
thats probably becuz a union has a common memory location, accessed by all
its members.
so, the value '100' is treated as an int by 'a', as a char array by 'b' and
as a float by 'c'.
I thnk i read this read tis somewhere sometime back. ... so aint completely
sure abt it.

On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal
wrote:

>
> u can always retrieve that value from the union that has been assigned
> last.therefore u get correct answer only for x.c
>
> in the case of union y
> y.a=100 and so the output
> but am not sure why y.b is printing character equivalent of 100.
>
>
> On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari <
> shubham.veloc...@gmail.com> wrote:
>
>> you mean to say .. the ques is wrong ... or what ...!!
>>
>>
>> On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek wrote:
>>
>>> I think you must first read about unions and the differences between
>>> union and structures :)
>>>
>>> On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari <
>>> shubham.veloc...@gmail.com> wrote:
>>>
>>>> "union" Data Type
>>>> What is the output of the following program? Why?
>>>> #include
>>>> main() {
>>>> typedef union {
>>>> int a;
>>>> char b[10];
>>>> float c;
>>>> }
>>>> Union;
>>>> Union x,y = {100};
>>>> x.a = 50;
>>>> strcpy(x.b,"hello");
>>>> x.c = 21.50;
>>>> printf("Union x : %d %s %f n",x.a,x.b,x.c);
>>>> printf("Union y : %d %s %f n",y.a,y.b,y.c);
>>>> }
>>>>
>>>> --
>>>> Shubham Maheshwari
>>>> ShubZz
>>>> O.o o.O
>>>>
>>>> enJoY ...!!!
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> **Regards
>>> SAGAR PAREEK
>>> COMPUTER SCIENCE AND ENGINEERING
>>> NIT ALLAHABAD
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

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



Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
you mean to say .. the ques is wrong ... or what ...!!

On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek  wrote:

> I think you must first read about unions and the differences between union
> and structures :)
>
> On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari <
> shubham.veloc...@gmail.com> wrote:
>
>> "union" Data Type
>> What is the output of the following program? Why?
>> #include
>> main() {
>> typedef union {
>> int a;
>> char b[10];
>> float c;
>> }
>> Union;
>> Union x,y = {100};
>> x.a = 50;
>> strcpy(x.b,"hello");
>> x.c = 21.50;
>> printf("Union x : %d %s %f n",x.a,x.b,x.c);
>> printf("Union y : %d %s %f n",y.a,y.b,y.c);
>> }
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> **Regards
> SAGAR PAREEK
> COMPUTER SCIENCE AND ENGINEERING
> NIT ALLAHABAD
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
"union" Data Type
What is the output of the following program? Why?
#include
main() {
typedef union {
int a;
char b[10];
float c;
}
Union;
Union x,y = {100};
x.a = 50;
strcpy(x.b,"hello");
x.c = 21.50;
printf("Union x : %d %s %f n",x.a,x.b,x.c);
printf("Union y : %d %s %f n",y.a,y.b,y.c);
}

-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread Shubham Maheshwari
according to saagar's algo, it'll be printed ...

On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul wrote:

> @Reynald
> Will 75 not be included in the tree that u have
> given..??
>
>
> On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek wrote:
>
>> here is the code
>> void border(node*);
>> void recur(node*);
>>
>> void border(node *ptr)
>> {
>>  node* tmp; int stack[20],top=0;
>>  if(tmp=ptr->left)
>>  {
>>   while(tmp->left)
>>   {
>>printf("%d ",tmp->data);
>>tmp=tmp->left;
>>   }
>>  }
>>  recur(ptr);
>>  if(tmp=ptr->right)
>>  {
>>   while(tmp->right)
>>   {
>>stack[top++]=tmp->data;
>>tmp=tmp->right;
>>   }
>>  }
>>  while(top--) printf("%d ",stack[top]);
>>  printf("%d\n",ptr->data);
>> }
>>
>> void recur(node* ptr)
>> {
>>  if(ptr->left) recur(ptr->left);
>>  if(!ptr->left&&!ptr->right) printf("%d ",ptr->data);
>>  if(ptr->right)   recur(ptr->right);
>>
>> }
>>
>> On Sat, Jul 16, 2011 at 7:07 PM, Reynald  wrote:
>>
>>> Algo to find the border of a given binary tree. Optimized for space
>>> and time.
>>> Input:
>>>  10
>>>   / \
>>> 50 50
>>>/  \ /   \
>>>  25  75   20020
>>>  / \   /  /\
>>> 15 35   120155   250
>>>
>>> Output:50 25 15 35 120 155 250 20 150 10
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>> **Regards
>> SAGAR PAREEK
>> COMPUTER SCIENCE AND ENGINEERING
>> NIT ALLAHABAD
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Google Interview Question

2011-05-27 Thread shubham
check whether these steps work:

step 1:
sort the given numbers in the decreasing order based on their first 
digit.
step 2:
if two numbers come out to be equal in the above case & both of 
their next digit exist then sort on the basis of their next digit, otherwise 
the number
whose next digit doesnot exist should be placed before the other 
number.
step 3:
   concatenate these numbers.

e.g.

(0,1,10,100) sorting it gives: 1,10,100,0 => 1101000
(97,8,9) sorting gives: 9,97,8 => 9978

correct me if i'm wrong.

Shubham

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: GOOGLE INTERVIEW QUESTION

2011-05-10 Thread shubham
check this one out:

#include
#include
#include
#include
using namespace std;
int check_palin(string str,int *start)
{
int pos=-1,ret,size=str.size()-1;
char last_char=str[size];
while(pos palin,str;
cin>>arr;str.push_back(arr);
while(arr!="")
{
int s=0,e=0,max=0,start=0,end=0,len;
string tmp="";
for(int i=0;imax){max=len;start=s;}
}
tmp=arr.substr(start,max);
palin.push_back(tmp);str.pop_back();
tmp=arr.substr(0,start);if(tmp!="") str.push_back(tmp);
tmp=arr.substr(start+max);if(tmp!="") str.push_back(tmp);
if(str.size())arr=str[str.size()-1];else arr="";
}
for(int i=0;ihttp://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Reading Huge input from the terminal in least time.

2011-04-19 Thread shubham
Hello Geeks,
Suppose we have a 2-d array arr[1000][1000] capable of storing 10^6
elements in it. Input is supplied one row at a time. Then what is the
best possible way to read this much data in the least amount of time
as scanf() or cin takes a lot of time?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Hard Problem

2011-03-20 Thread shubham
Hi there,
Please help me reveal the suitable logic behind this problem.
For a set of inputs, outputs are given. You are to guess the logic.

problem can be seen at-
http://www.spoj.pl/problems/HARDP/

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Need help regarding the SPOJ problem...

2011-03-18 Thread shubham
You have N marbles and K slots. You have to follow the below mentioned
rules :

   1. You can put in a marble or take out a marble from slot numbered
1 at any time.
   2. You can put in a marble or take out a marble from slot numbered
i only if there exists a marble at the slot i - 1.
   3. The game stops when a marble reaches the slot numbered K for the
first time.

Your task is to finish the game in minimum number of valid moves.

for further clarification one can visit:

http://www.spoj.pl/problems/MOVMRBL/

I am not able to calculate manually the steps for some (N,K) pair
(except the cases where K is less than or equal to N*(N-1)/2).
e.g how to proceed with just 3 marbles and 10 slots...

any idea in this direction will be appreciated...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Regarding Google recruiting

2011-02-06 Thread shubham singh
i applied for intern and get reply within a month.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] dp

2011-02-04 Thread shubham singh
thnx ...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] dp

2011-02-04 Thread shubham singh
if (u r calling dp of spoj as basic)
{
i would say u are a champ already ;
}
else
{
do practise more on spoj
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Google

2011-01-18 Thread shubham singh
thats cool i am from uptu google didnt visit here so no idea :D :D

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Google

2011-01-18 Thread shubham singh
wch college u are 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.



Re: [algogeeks] Re: bits groups

2010-12-21 Thread shubham singh
u can see topcoder and codechef tutorials may help

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