[algogeeks] Re: sorting range of numbers in O(n)

2010-08-04 Thread Avik Mitra
Radix uses the count sort..that is why its running time O(n). -- 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

Re: [algogeeks] Copy Constructor and reference

2010-08-04 Thread Raj N
If it isn't passed by reference it goes to an infinite recursion. On Wed, Jul 21, 2010 at 12:08 AM, mallesh mallesh...@gmail.com wrote: In C++ Why is it that copy constructor uses only reference as parameter and not the actual class? I was given a hint that it has got something to do with

[algogeeks] interesting c++ questions

2010-08-04 Thread Raj N
1) Can a constructor call another constructor to initialize the same object? 2) Can a struct variable be assigned to another if the structure contains an array as a field? 3) Can we pass a private member by reference to a non member function? 4) Can the destructor be called explicitly? 5) Can copy

Re: [algogeeks] Re: interview-question

2010-08-04 Thread jalaj jaiswal
@ritesh..you dnt have to output v.. you have to output the minimum number of flips so that your tree evaluates to v(v is either 0 or 1) and if it alreday evaluates to v then return 0(no flips required) if not possible return -1 On Wed, Aug 4, 2010 at 12:11 AM, RITESH SRIVASTAV

[algogeeks] 1's counting

2010-08-04 Thread amit
(3*4096+15*256+3*16+3). How many 1's are there in the binary representation of the result. Is there a quick way to count the number of set bits in this number manually??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] 1's counting

2010-08-04 Thread Seçkin Can Şahin
either count it with a for loop or if you are using C, use __builtin_popcount(int x) or x is given int count = 0; for(int i=0; i32;i++) count += (x (1i)) != 0; On Tue, Aug 3, 2010 at 12:04 PM, amit amitjaspal...@gmail.com wrote: (3*4096+15*256+3*16+3). How many 1's are there in the binary

[algogeeks] Re: 1's counting

2010-08-04 Thread Dave
The straightforward way is simply to write the number out in binary and count the one-bits. It works for any number. In this specific case, since the multiplications are by powers of 2, resulting in shifts, and the resulting binary numbers don't overlap, the number of bits is bitcount(3*4096) +

[algogeeks] Re: Diff b\w BST and binary tree............

2010-08-04 Thread Dave
See http://en.wikipedia.org/wiki/Binary_search_tree#Insertion Dave On Aug 4, 9:56 am, UMESH KUMAR kumar.umesh...@gmail.com wrote: On Tue, Aug 3, 2010 at 11:22 PM, Anand anandut2...@gmail.com wrote: While creating BST we follow the rule that element on the left hand side of the root should

[algogeeks] Re: interesting c++ questions

2010-08-04 Thread RITESH SRIVASTAV
1) A constructor can call another constructor but not for the same object if we are talking just the precise meaning of object and not considering the raw storage as Objects. 4) Destructor can be called explicitly .This is generally used when u have used your own new operator so that

Re: [algogeeks] Re: interesting c++ questions

2010-08-04 Thread Anand
Can a struct variable be assigned to another if the structure contains an array as a field? You can. But it will be like a shallow copy. if the structure has a pointer variables those memory need to be assigned explicitly. 3) Can we pass a private member by reference to a non member function? No

Re: [algogeeks] Re: Sapient Interview Question

2010-08-04 Thread Anand
As per the problem it seems to be that there is one root node (CEO) and all employees are child node. B'cos iin the question it is mentioned that each employee is led by only 1 person except for the CEO (who has no boss). Correct me if I am wrong. On Wed, Aug 4, 2010 at 4:32 PM, Gene

Re: [algogeeks] 1's counting

2010-08-04 Thread jalaj jaiswal
it is 3*2^12 + 15*2^8 + 3*2^4 + 3 so it becomes 312 + 158 + 34 +3.. let this equal to n take a int count=0; while(n){ n=n(n-1); count++; } return count; 2010/8/4 Seçkin Can Şahin seckincansa...@gmail.com either count it with a for loop or if you are using C, use

Re: [algogeeks] Associativity...............

2010-08-04 Thread Raj N
Both are unary operators and hence the associativity is from right to left. On Wed, Aug 4, 2010 at 8:31 AM, UMESH KUMAR kumar.umesh...@gmail.comwrote: How to decide associativity of the operation on operand so a simple Ex:- *ptr++ and ++*ptr how to work both ? --

Re: [algogeeks] 1's counting

2010-08-04 Thread jalaj jaiswal
it is 3*2^12 + 15*2^8 + 3*2^4 + 3 so it becomes 312 + 158 + 34 +3.. let this equal to n take while(n){ 2010/8/4 Seçkin Can Şahin seckincansa...@gmail.com either count it with a for loop or if you are using C, use __builtin_popcount(int x) or x is given int count = 0; for(int i=0;

Re: [algogeeks] 1's counting

2010-08-04 Thread Bhanu Pratap Singh
Hi Amit, If you are answer this question orally then the format you have given is just a hexadecimal number. Its value would be 0x3f33. So the number of 1's would be simply 2+4+2+2 = 10. Programatically whatever solution Sahin has given seems to be good enough. 2010/8/4 Seçkin Can Şahin

[algogeeks] Initialization list

2010-08-04 Thread Raj N
Can someone tell me why the order of initialization in the initialization list of constructor, the order of declaration of data members in C++ ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: interesting c++ questions

2010-08-04 Thread vikas kumar
1) Yes ofcourse 2) yes you can 3) yes ofcourse 4) yes 5) i dont think . May we our default constructor def not matching ;) On Aug 3, 8:42 pm, Raj N rajn...@gmail.com wrote: 1) Can a constructor call another constructor to initialize the same object? 2) Can a struct variable be assigned to

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-08-04 Thread Ashish Goel
void dyckWords(int index, int open, int close) { static int dyck=0; if (index == 2 *n) { printf(%s\n, out); return ; } out[index] = '('; //or A if ((open + 1) = n open = close) { dyckWords(index + 1, open + 1, close); } out[level] = ')';//or B if ((close + 1) = n

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-08-04 Thread Ashish Goel
void dyckWords(int index, int open, int close) { static int dyck=0; if (index == 2 *n) { printf(%s\n, out); return ; } out[index] = '('; //or A if ((open + 1) = n open = close) { dyckWords(index + 1, open + 1, close); } out[index] = ')';//or B