[algogeeks] maximize spread in advertisement assignment

2010-06-22 Thread slack
Hello everybody. I'm asked to find a 2 approximate solution to this problem: You’re consulting for an e-commerce site that receives a large number of visitors each day. For each visitor i, where i € {1, 2 . n}, the site has assigned a value v[i], representing the expected revenue that can be

[algogeeks] seg fault

2010-06-22 Thread sharad
#includestdio.h int main() { char a,b; printf(%d\n,12); printf(%d\n,printf(%d,143)); printf(%d\n,scanf(%2d%3d,a,b)); } y this prog is giving seg fault after all its o/p -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
i knoe c++ well so i can understand java code bt i m not able to understand this code so pl explain it or give algo thnx in advance -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread Raajay
Hi Sharad, I suppose this is what you are looking for. Assume non-negative integers. Otherwise, there are infinite possibilities. #includeiostream #includeset #includevector using namespace std; vector vectorint allCombinations; void findAllCombinations(vectorint elements, int left) {

[algogeeks] no of bits

2010-06-22 Thread divya
find the no. of bits set in a no. in logn time -- 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] Re: seg fault

2010-06-22 Thread Shravan
%c is the format specifier for char.Provide space between them. On Jun 22, 2:54 pm, sharad sharad20073...@gmail.com wrote: #includestdio.h int main() {         char a,b;         printf(%d\n,12);         printf(%d\n,printf(%d,143));         printf(%d\n,scanf(%2d%3d,a,b));} y this

[algogeeks] Re: seg fault

2010-06-22 Thread Debajyoti Sarma
i don't understand what this statement will do ? scanf(%2d%3d,a,b); -- 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] Re: minimum spanning tree

2010-06-22 Thread jalaj jaiswal
prims and krushkal dont' work for directed graphs On Tue, Jun 22, 2010 at 6:44 AM, Gene gene.ress...@gmail.com wrote: On Jun 20, 7:48 am, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: give an algo to find a minimum spanning tree of a directed graph ?? -- With Regards, Jalaj Jaiswal

[algogeeks] a bst

2010-06-22 Thread divya
a bst is given whose leaf nodes having left as well as right pointers not pointing to NULL. rather all the leaf nodes are forming a circular doubly linked list. u have to calculate height of tree. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] single linked list to tree

2010-06-22 Thread divya
u r given a single linked list u have to make a minimally skewed tree such that each child points to its parent.. -- 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

Re: [algogeeks] Re: seg fault

2010-06-22 Thread Rahul Singhal
I think its due to typecasting of char to int just change char a,b to int a,b or last line change inside scan %c segementation fault will not come as size of char is less than size of int On Tue, Jun 22, 2010 at 3:37 PM, Shravan shravann1...@gmail.com wrote: %c is the format specifier for

Re: [algogeeks] seg fault

2010-06-22 Thread mohit ranjan
i am not getting any seg fault on gcc any specific i/p you are giving for scanf ? Mohit Ranjan On Tue, Jun 22, 2010 at 2:54 PM, sharad sharad20073...@gmail.com wrote: #includestdio.h int main() { char a,b; printf(%d\n,12); printf(%d\n,printf(%d,143));

Re: [algogeeks] seg fault

2010-06-22 Thread Dhritiman Das
Which version of gcc are u using ? I do get a error in 4.3.2 If size of scanf's argument is smaller than format specified, behaviour is undefined. Hence implementation is free to choose a behaviour. On Tue, Jun 22, 2010 at 3:37 PM, mohit ranjan shoonya.moare h...@gmail.comwrote: i am not

[algogeeks] Re: no of bits

2010-06-22 Thread Dave
Assuming 32 bit integers: n = ((x 1) 0x) + (x 0x) n = ((n 2) 0x) + (n % 0x) n = ((n 4) 0x0F0F0F0F) + (n 0x0F0F0F0F) n = ((n 8) 0x00FF00FF) + (n 0x00FF00FF) n = ((n 16) 0x) + (n 0x) n now is the number of bits set in x. Time is O(1).

[algogeeks] CFP: Optical SuperComputing Workshop 2010: Deadline Extension

2010-06-22 Thread optical supercomputing
CFP: Optical SuperComputing Workshop 2010: Deadline Extension 3rd International Workshop on Optical SuperComputing in Bertinoro (OSC10) November 17-19, Bertinoro, Italy http://www.cs.bgu.ac.il/~dolev/OSC10 SCOPE: OSC, the International Workshop on Optical SuperComputing, is an annual forum

Re: [algogeeks] Re: no of bits

2010-06-22 Thread chitta koushik
For more such problems and solns http://graphics.stanford.edu/~seander/bithacks.html for (c = 0; v; c++) { v = v - 1; // clear the least significant bit set } O(k) -- no. of bits set in the number --Koushik C On Tue, Jun 22, 2010 at 7:16 PM, Dave dave_and_da...@juno.com wrote:

[algogeeks] 23 candies among 7 kids

2010-06-22 Thread Aarthi Thangamani
Given 23 chocolates and there are 7 kids. How many ways are there to spilt the chocolates among the 7 kids? All of the chocolates must be distributed and it can happen that some kids do not get any. For example: first kid gets 23 chocolates and rest get none is one possibility. First 6 kids get

Re: [algogeeks] 23 candies among 7 kids

2010-06-22 Thread rajat ahuja
x1+x2+x3+x4+x5+x6+x7=23,,, noe no of solution is,,, of equation is,, n+r-1C(COMBINATION )r-1 (n identical items to be distributed into R grups) so ,, ans 23+7-1c7-1;(identical) if unidentical case, then each each cholate wud hav 7 options,, so ,, ans -- 7^23 (different) On Tue, Jun 22, 2010

Re: [algogeeks] 23 candies among 7 kids

2010-06-22 Thread ANUJ KUMAR
(2^7-1)^23 On Tue, Jun 22, 2010 at 8:22 PM, Aarthi Thangamani aarthi.thangam...@gmail.com wrote: Given 23 chocolates and there are 7 kids. How many ways are there to spilt the chocolates among the 7 kids? All of the chocolates must be distributed and it can happen that some kids do not get

Re: [algogeeks] seg fault

2010-06-22 Thread mohit ranjan
@Dhritiman gcc 4.3.4 - Mohit ran...@mohit-home ~ $ ./test 12 1433 1 // i/p given 2 // i/p given 2 - Mohit Ranjan On Tue, Jun 22, 2010 at 6:46 PM, Dhritiman Das dedhriti...@gmail.comwrote: Which version of gcc are u using ? I do get a

[algogeeks] sum k in sub array

2010-06-22 Thread sharad kumar
How will you find the subarray whose sum is k in an array of negative and positive numbers -- 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

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
thnx Raajay n Jeeva for giving so clear explainations bt actually my question is ...if i/p is 5 then u hve to print 1+4 1+1+3 1+1+1+2 1+1+1+1+1 1+2+2 1+4 2+3 and all such pairs giving 5 i hope i m clear this time -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
@ Jeeva...abt ur soln when a[1] comes i.e 2 so i think according to algo 10-2 i.e 8 must go in plzz correct me if i wrongly understood it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] 23 candies among 7 kids

2010-06-22 Thread bala chander
Hi, Given that u need to split 23 into 6 parts. Its all about placing + with 24 spots( wit 23 1's )(6 ,5...0). So, the answer is Description : 1 1 1 1 1 1 1 1 1 1 1 1 .. 1 + + + 1. Sharing with just one means there is no + - 24 C 0 2. Sharing with just

Re: [algogeeks] tree in array

2010-06-22 Thread Anand
if we store the Binary tree in array as array[1] = x1 array[2] = x2 array[3] = x3 array[4] = x4 array[5]= x5 array[6]= x6 array[7]=x7 x1 is first node at level 0 root node x2 is left node and x3 is right node of x1 at level 1 x4 is left node and x5 is right node of x2 at level 2 and x5 is left

Re: [algogeeks] There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-22 Thread Naveen Kumar
Hi Rohit, Can you explain your approach a bit more? On Sun, Jun 20, 2010 at 2:48 PM, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: Why not just change the definition of when one number is bigger than another and do normal sort ? I guess that is better and simpler.

[algogeeks] Re: Bit wise operator

2010-06-22 Thread Dave
int HighestBitSet (unsigned int n) { double x; int exp; x = frexp((double)n, exp); return exp-1; } To see how it works, look up the standard C++ function frexp. Dave On Jun 22, 2:37 pm, Anand anandut2...@gmail.com wrote: How to find the Most significant bit position of a given

Re: [algogeeks] sum k in sub array

2010-06-22 Thread Amit Jaspal
Let A[] be a array. Step 1: Find Cumulative Sum array say C[] if A[]={2,-1,3,5,6,-7,8} C[]={0,2,1,4,9,15,18,16} Now traverse through this C[] and keep storing C[i] in a BST. Whenever C[j]-C[i] = K (We have found our needed subarray) So for every element of C[] chk if C[i]-K is found in BST . If

[algogeeks] compressed trie

2010-06-22 Thread ANUJ KUMAR
Please send me a c++ code for a compressed trie. -- 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] find all the combination of number whose sum is n

2010-06-22 Thread Jeeva A
yes it must go into hashSet ...You have got it right. On Tue, Jun 22, 2010 at 5:55 PM, sharad kumar sharad20073...@gmail.comwrote: @ Jeeva...abt ur soln when a[1] comes i.e 2 so i think according to algo 10-2 i.e 8 must go in plzz correct me if i wrongly understood it -- You received this

[algogeeks] linked list

2010-06-22 Thread divya
Two link lists are given ...check if one is reverse of other. Do it without using extra space. -- 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,

Re: [algogeeks] 23 candies among 7 kids

2010-06-22 Thread Jitendra Kushwaha
coefficient of x^23 in (1 + x + x^2 + x^3 + ... + x^23) ^ 7 i.e. 29C23 -- Regards Jitendra Kushwaha 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 algoge...@googlegroups.com. To

Re: [algogeeks] Re: no of bits

2010-06-22 Thread divya jain
@ dave how did u come to this formula... m nt getting the logic.. @ sathaiah yes u r rite On 22 June 2010 19:32, chitta koushik koushik.infin...@gmail.com wrote: For more such problems and solns

[algogeeks] Re: check divisibility

2010-06-22 Thread Dave
Let m = 2^k - 1. To check divisibility of n by m, 1. If n is zero, return true. 2. If n is negative, replace n with -n. 3. While n m, replace n with (n k) + (n m). 4. Return (n == m). This is equivalent to the casting out nines algorithm to determine if a number is a multiple of 9. Dave On

[algogeeks] Re: no of bits

2010-06-22 Thread Dave
Did you actually try the code by hand on a number to see what it does? If you do, you will see that the first statement replaces the bits in each pair of bit positions with the number of bits in those positions. The second adds the bits in each pair of pairs, replacing each nibble with the number

Re: [algogeeks] There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-22 Thread Mayur
Rohit's approach put into a typical c++ construct... inline is_odd(int x) { return ((x 1) == 1); } struct new_compare { bool operator () (int i, int j) { bool b_i_odd = is_odd(i); bool b_j_odd = is_odd(j); if ((b_i_odd b_j_odd) || (!b_i_odd !b_j_odd))