[algogeeks] Re: MS
read everything once insert them in a dictionary of type char, listint where for each character key, u record the indices (since u record from left to right, they're gonna be in ascending order) then, for any character that's asked for, u can get to the list in O(1) time and can get the min distance... On Jun 30, 12:40 pm, bittu shashank7andr...@gmail.com wrote: lets take the example {1,2, 10, 2, 3, 5, 1, 1,2,3,5,2} clearly min distance is 1 between a=2 b=5 take variables current=-1 min=INT_Max so we start from last element say its index is last which is array size -1 check it with a b if its equal to any of these then check current !=- a[current]!=a[last] if its true then compare min with min current-last update the min e.g min=minimum(min,current-last) set current=n; repeat until we run out of loop so function looks like minDistance (int a[], int n, int b, int c) { int ret = INT_MAX, cur rent= -1; while(n--) { if(a[n] == b || a[n] == c) { if(cur rent!= -1 a[current] != a[n]) { min = minimum(min, current - n);} current = n//upodate current } Thanks Shashank Mani CSE, BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Sum to K problem
Wrote the code for same. #includeiostream using namespace std; int max(int a,int b) { if(ab) return a; else return b; } int main() { int n,k; cout\nEnter the count of numbers :; cinn; //Set of Elements cout\nEnter the elements :; int *A; A = new int[n]; for(int i = 0; in; i++) cinA[i]; //Input Sum Value cout\nEnter the value of k :; cink; //Matrix for holding boolean values for subproblems (max subproblems upto nk) int **M; M = (int **)new int[n]; for(int i=0; in; i++) M[i] = new int[k+1]; //Populate all the values to false for(int i=0; in; i++) for(int j=0; j=k; j++) M[i][j] = 0; for(int i=0; in; i++) M[i][0] = true; for(int i=1; in; i++) for(int j=0; j=k; j++) if(j-A[i]=0) { M[i][j] = max(M[i-1][j], M[i-1][j-A[i]]); } if(M[n-1][k] == 1) cout\nPossible Subset present; else cout\nPossible Subset not present; cin.get(); return 0; } On Fri, Jun 24, 2011 at 11:42 PM, ross jagadish1...@gmail.com wrote: This is the subset sum problem which is NP,. The DP is as follows, M[i,j] = 1 , if a subset of first i elements has a sum = j. else 0, The recurrence is, M[i,j] = max(M[i-1,j] , M[i-1,j-Ai]) where Ai is the ith element. You can maintain back pointers to keep track of previous elements so that the solution can be reconstructed from the DP. Once this matrix is populated till sum=k, Then, the column corresponding to sum=k, gives the answer. complexity o(nk). On Jun 20, 6:38 pm, Harshal hc4...@gmail.com wrote: The problem is NP. Complexity using DP will be O(nk), where n is number of elements and k is required sum. S[0]=true; //choose no element S[1...k] = false; for each number i in your input for s = k downto i if ( S[s - i] == true ) S[s] = true; S[s] = true indicates a sum of i can be obtained from a subset of the set. To get the elements, we can make S[s] contain the list of numbers that contain the sum. On Mon, Jun 20, 2011 at 6:53 PM, Navneet Gupta navneetn...@gmail.comwrote: Ideally, yes it can. Though i would be happy even if someone gives a good answer for non-negative values. On Mon, Jun 20, 2011 at 6:28 PM, Akshata Sharma akshatasharm...@gmail.com wrote: @Navneet: does the set contains negative elements also? On Mon, Jun 20, 2011 at 12:26 PM, pacific :-) pacific4...@gmail.com wrote: @vaibhav : Please note that more than two numbers can sum upto k. On Mon, Jun 20, 2011 at 12:21 PM, vaibhav shukla vaibhav200...@gmail.com wrote: sort the array using merge sort : order nlogn take the first element,subtract it with 'k' , then search the result using binary search in rest of the array : order nlogn hence u get two elements which sum up to K in order nlogn On Mon, Jun 20, 2011 at 12:14 PM, Navneet Gupta navneetn...@gmail.com wrote: Right, in the worst case, complexity with be O(2^N). So what are the possible optimizations here? Would building pre-computed data structures with intermediate sum values help in finding such pairs in less complexity? I think then we can apply dynamic programming to find such pairs. On Mon, Jun 20, 2011 at 12:09 PM, oppilas . jatka.oppimi...@gmail.com wrote: I think its a NP problem. The solution complexity can go up O(2^N) in worst case. On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.com wrote: Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to
[algogeeks] help..
the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] help..
i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: conditional compilation
Ya its cleard nw.. Thnx..:) On 7/2/11, Dumanshu duman...@gmail.com wrote: In ur second code change int i=2 and run it. It would still print bye. check the result of preprocessor using -E flag. On Jun 30, 4:46 pm, himanshu kansal himanshukansal...@gmail.com wrote: 1 more thngif its possible to eval. variable expression lyk abv... thn... int i=2; #if i==2 printf(hi); #else printf(bye); //prints byei think it shld print hi... #endif even this code prints bye. int i=3; #if i==2 printf(hi); #else printf(bye); #endif On Thu, Jun 30, 2011 at 5:13 PM, himanshu kansal himanshukansal...@gmail.com wrote: somewhere i read dt conditional compilation such as #if and #elif etc cn only use constant expressions and previously defined macrosthey cant use variables cz preprocessng is done b4 compilation... bt whn i try it on gcc and vc both r compiling it with variables abs. fyneven disabling extensions dint work i.e int i; #if i+1 printf(hi); vl print hi...no error occurs #endif thn i read it on net dt it cn eval. varables also nw m confused who is ryt... whtr it cn eval var also or nt... nd if it cn thn hws it possible dt preprocessor knows d val. of var. b4 compiling d prog... -- Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sent from my mobile device Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: help..
that will not work. for example we need a rope of length 4 from a rope of length 16 we need 2 cuts 16== 8 + 8 == 8+ 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] help..
yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: help..
nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
k - rope of desired length. l - rope of given length m = 2; while(k % m) m *= 2; ans :: (log2(l) - log2(m) + 1). ex. k = 6,l = 8 so initially m = 2; after 1st iteration m = 4; then break; so min = log2(8) - log2(4) + 1 = 3 -2 + 1 = 2. On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
xor the length of the rope with the required length and difference between the indexes of first set and last set bit *may* be the answer !! On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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.
[algogeeks] Re: help..
k is an even number and m=2 in your code. k%2 is always 0. your while loop does nothing. On Jul 2, 1:26 pm, varun pahwa varunpahwa2...@gmail.com wrote: k - rope of desired length. l - rope of given length m = 2; while(k % m) m *= 2; ans :: (log2(l) - log2(m) + 1). ex. k = 6,l = 8 so initially m = 2; after 1st iteration m = 4; then break; so min = log2(8) - log2(4) + 1 = 3 -2 + 1 = 2. On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
@varun I think u want to write while (k % m == 0) On Sat, Jul 2, 2011 at 1:56 PM, varun pahwa varunpahwa2...@gmail.comwrote: k - rope of desired length. l - rope of given length m = 2; while(k % m) m *= 2; ans :: (log2(l) - log2(m) + 1). ex. k = 6,l = 8 so initially m = 2; after 1st iteration m = 4; then break; so min = log2(8) - log2(4) + 1 = 3 -2 + 1 = 2. On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
whats mean by first set bit and last set bit? do you simply mean the index of first and last bit? On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote: xor the length of the rope with the required length and difference between the indexes of first set and last set bit *may* be the answer !! On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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.
Re: [algogeeks] Re: help..
yes i have written that only difference between indexes of first set bit and last set bit On Sat, Jul 2, 2011 at 2:08 PM, cegprakash cegprak...@gmail.com wrote: whats mean by first set bit and last set bit? do you simply mean the index of first and last bit? On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote: xor the length of the rope with the required length and difference between the indexes of first set and last set bit *may* be the answer !! On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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. -- 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.
Re: [algogeeks] Re: help..
l = 81 0 0 0 k = 6 0 1 1 0 xor 1 1 1 0 difference = 2 l = 161 0 0 0 0 k = 4 0 0 1 0 0 xor On Sat, Jul 2, 2011 at 2:09 PM, sunny agrawal sunny816.i...@gmail.comwrote: yes i have written that only difference between indexes of first set bit and last set bit On Sat, Jul 2, 2011 at 2:08 PM, cegprakash cegprak...@gmail.com wrote: whats mean by first set bit and last set bit? do you simply mean the index of first and last bit? On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote: xor the length of the rope with the required length and difference between the indexes of first set and last set bit *may* be the answer !! On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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.
[algogeeks] Re: help..
even that won't work for example: if we need a length of rope 14 from a length of rope 16 according to varun's algo initially m=2 14%2 is 0.. so m=4 14%4 is not 0.. break.. so log2(16)-log2(14)+ 1 == 4-3+1 = 2 which is wrong but actually we need atleast 3 cuts. 16== 8 + 8 == 8+ 4+ 4 == 8 + 4+ 2 + 2.. now we can merge 2,4 and 8 to form 14 On Jul 2, 1:35 pm, sunny agrawal sunny816.i...@gmail.com wrote: @varun I think u want to write while (k % m == 0) On Sat, Jul 2, 2011 at 1:56 PM, varun pahwa varunpahwa2...@gmail.comwrote: k - rope of desired length. l - rope of given length m = 2; while(k % m) m *= 2; ans :: (log2(l) - log2(m) + 1). ex. k = 6,l = 8 so initially m = 2; after 1st iteration m = 4; then break; so min = log2(8) - log2(4) + 1 = 3 -2 + 1 = 2. On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote: nope On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote: yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
@varun: i think it works.. could u tell me how u found it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: help..
@ sunny: so your's doesn't work right? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
why ? On Sat, Jul 2, 2011 at 2:20 PM, cegprakash cegprak...@gmail.com wrote: @ sunny: so your's doesn't work right? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
@varun: explanation or proof for your soln. plz.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
awesome!! thank you so much :) On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote: for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
btw what N = N-(N(N-1)) does actually On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote: for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
Re: [algogeeks] Re: help..
try out with examples!! u will surely get in 2-3 examples N(N-1) is a very famous expression, used in counting set bits. see what this expression return On Sat, Jul 2, 2011 at 2:51 PM, cegprakash cegprak...@gmail.com wrote: btw what N = N-(N(N-1)) does actually On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote: for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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.
[algogeeks] Re: Test Cases
Asymptotic complexity can never be better than O(n). But you can reduce the number of exact comparisons from 2n to 3n/2 . Take pair of numbers in each iteration and compare them. Then compare the smaller to Min and greater to Max . This way, you have 3 comparisons for every iteration where the number of iterations is n/2 so total number of comparison is 3n/2. On Jul 2, 8:47 am, Hemanth Sagar hemanth2...@gmail.com wrote: @sameer Though the asymptotic time complexity is equal,i.e. O(n), the actual time complexity is also influenced by the constants. I claim that running two loops will be slower because there are now three operations that are to be done additionally than the single loop. Also, if you take the case of insertion sort (vs) merge sort, though the time complexity of merge sort (nlogn) is better than insertion sort(n^2), for small n values, insertion sort is better. This is because there is also a role played by the constants. Correct me if I am wrong ! - Hemanth On Sat, Jul 2, 2011 at 8:20 AM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: @hemanth: doing it in seperate for loops or in a single for loop both results in O(n) time.It does not make a difference. I think there cannot be a solution better than O(n) as we need to traverse the array atleast once. On Fri, Jul 1, 2011 at 12:57 PM, Hemanth Sagar hemanth2...@gmail.comwrote: The most efficient code will be surely of O(n). This is because there is no way of finding the min and max without scanning the entire array atleast once. Is this so? or any counter arguments ? On Sat, Jul 2, 2011 at 1:06 AM, rajeevrvis rajeev.open.1...@gmail.comwrote: Are there any Algorithms for finding efficient max differences ? On Jul 1, 11:42 pm, Hemanth 007 hemanth2...@gmail.com wrote: Hii, One improvement is that finding min and max can be done in a single run, rather than calling the findMin and findMax separately. But yet the order is O(n); Is there any better soln than O(n); #includestdio.h #includelimits.h void findExtreme(int array[],int size,int* min,int* max){ int i; for(i=0;isize;i++){ if(array[i] *max)*max = array[i]; if(array[i]*min)*min=array[i]; } } main(){ int arr[]={0,609,211,432,31,}; int max=INT_MIN,min=INT_MAX; findExtreme(arr,sizeof(arr)/sizeof(arr[0]),min,max); printf(%d %d ,max,min); printf(%d,max-min);} ~ ~ ~ -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
@sunny that will work fine(xoring). In place of Xoring u can also do OR of two number and find the distance between fist set bit from left and first set bit from right, Since bit operation is really fast operation so best algo this is of complexity O(1); Explanation How it works: In l only one bit will be set. In m multiple bit would be set with all bit before the bit set in l. NOW suppose u divde l in 2 parts means u have shifted set bit of l to the right. dividing again will shift set bit in l to the right. u have to divide till set bit in l reached the position where first bit of m is set. how many times u have shifted is count of dividng the rope its Simple. u can check with any example Thanks Santosh On Sat, Jul 2, 2011 at 2:41 PM, sunny agrawal sunny816.i...@gmail.comwrote: for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: help..
@sunny the no of set bits in m will tell what all length(4,2 in above case) are need to be merged. e.g if if m ==6 then m = 0110 since bit set position are 2 and 1. so length of rope need to combine is 2^2=4 and 2^1 = 2;i.e 4 and 2 Thnaks Santosh On Sat, Jul 2, 2011 at 2:58 PM, santosh mahto santoshbit2...@gmail.comwrote: @sunny that will work fine(xoring). In place of Xoring u can also do OR of two number and find the distance between fist set bit from left and first set bit from right, Since bit operation is really fast operation so best algo this is of complexity O(1); Explanation How it works: In l only one bit will be set. In m multiple bit would be set with all bit before the bit set in l. NOW suppose u divde l in 2 parts means u have shifted set bit of l to the right. dividing again will shift set bit in l to the right. u have to divide till set bit in l reached the position where first bit of m is set. how many times u have shifted is count of dividng the rope its Simple. u can check with any example Thanks Santosh On Sat, Jul 2, 2011 at 2:41 PM, sunny agrawal sunny816.i...@gmail.comwrote: for a number N first set bit(From Left) is simply integer value of log(N) last set bit can be calculated as N = N-(N(N-1)); and then Log(N) int i = log(n); n -= n(n-1); int j = log(n); i-j will be the answer. On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote: oh fine.. got it now.. set bit is '1' right.. and is there any short ways to find the difference between first set and short set bit without dividing by 2 repeatedly? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: help..
@ sunny 21 is 0 32 is 2 43 is 0 5 4 is 4 65 is 4 I don't find anything -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
power of 2 less than n right? On Jul 2, 2:38 pm, cegprakash cegprak...@gmail.com wrote: @ sunny 21 is 0 32 is 2 43 is 0 5 4 is 4 65 is 4 I don't find anything -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
no no.. it should be multiple of 2 less than n? even that doesn't satisfies for 43 On Jul 2, 2:41 pm, cegprakash cegprak...@gmail.com wrote: power of 2 less than n right? On Jul 2, 2:38 pm, cegprakash cegprak...@gmail.com wrote: @ sunny 21 is 0 32 is 2 43 is 0 5 4 is 4 65 is 4 I don't find anything -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Sum to K problem
@navneet: good one.. In my above explanation, u could keep track of back pointers so that u may want to print the subset containing the sum.. On Jul 2, 11:54 am, Navneet Gupta navneetn...@gmail.com wrote: Wrote the code for same. #includeiostream using namespace std; int max(int a,int b) { if(ab) return a; else return b; } int main() { int n,k; cout\nEnter the count of numbers :; cinn; //Set of Elements cout\nEnter the elements :; int *A; A = new int[n]; for(int i = 0; in; i++) cinA[i]; //Input Sum Value cout\nEnter the value of k :; cink; //Matrix for holding boolean values for subproblems (max subproblems upto nk) int **M; M = (int **)new int[n]; for(int i=0; in; i++) M[i] = new int[k+1]; //Populate all the values to false for(int i=0; in; i++) for(int j=0; j=k; j++) M[i][j] = 0; for(int i=0; in; i++) M[i][0] = true; for(int i=1; in; i++) for(int j=0; j=k; j++) if(j-A[i]=0) { M[i][j] = max(M[i-1][j], M[i-1][j-A[i]]); } if(M[n-1][k] == 1) cout\nPossible Subset present; else cout\nPossible Subset not present; cin.get(); return 0; } On Fri, Jun 24, 2011 at 11:42 PM, ross jagadish1...@gmail.com wrote: This is the subset sum problem which is NP,. The DP is as follows, M[i,j] = 1 , if a subset of first i elements has a sum = j. else 0, The recurrence is, M[i,j] = max(M[i-1,j] , M[i-1,j-Ai]) where Ai is the ith element. You can maintain back pointers to keep track of previous elements so that the solution can be reconstructed from the DP. Once this matrix is populated till sum=k, Then, the column corresponding to sum=k, gives the answer. complexity o(nk). On Jun 20, 6:38 pm, Harshal hc4...@gmail.com wrote: The problem is NP. Complexity using DP will be O(nk), where n is number of elements and k is required sum. S[0]=true; //choose no element S[1...k] = false; for each number i in your input for s = k downto i if ( S[s - i] == true ) S[s] = true; S[s] = true indicates a sum of i can be obtained from a subset of the set. To get the elements, we can make S[s] contain the list of numbers that contain the sum. On Mon, Jun 20, 2011 at 6:53 PM, Navneet Gupta navneetn...@gmail.comwrote: Ideally, yes it can. Though i would be happy even if someone gives a good answer for non-negative values. On Mon, Jun 20, 2011 at 6:28 PM, Akshata Sharma akshatasharm...@gmail.com wrote: @Navneet: does the set contains negative elements also? On Mon, Jun 20, 2011 at 12:26 PM, pacific :-) pacific4...@gmail.com wrote: @vaibhav : Please note that more than two numbers can sum upto k. On Mon, Jun 20, 2011 at 12:21 PM, vaibhav shukla vaibhav200...@gmail.com wrote: sort the array using merge sort : order nlogn take the first element,subtract it with 'k' , then search the result using binary search in rest of the array : order nlogn hence u get two elements which sum up to K in order nlogn On Mon, Jun 20, 2011 at 12:14 PM, Navneet Gupta navneetn...@gmail.com wrote: Right, in the worst case, complexity with be O(2^N). So what are the possible optimizations here? Would building pre-computed data structures with intermediate sum values help in finding such pairs in less complexity? I think then we can apply dynamic programming to find such pairs. On Mon, Jun 20, 2011 at 12:09 PM, oppilas . jatka.oppimi...@gmail.com wrote: I think its a NP problem. The solution complexity can go up O(2^N) in worst case. On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.com wrote: Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to
Re: [algogeeks] Re: help..
@cegprakash Expression resets the least significant set bit On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote: May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
Re: [algogeeks] Re: help..
nn-1 is the expression to find out if n is a power of 2...If nn-1 returns 0 its a power of 2 else its not. And what sunny said is also ryt On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote: @cegprakash Expression resets the least significant set bit On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote: May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Sum to K problem
http://en.wikipedia.org/wiki/Subset_sum_problem http://en.wikipedia.org/wiki/Subset_sum_problem this should help u :) knapsack like dp :) On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.comwrote: Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] GATE 2011 C Ques
10. What does the following fragment of C-program print? char c[] = GATE2011; char *p =c; printf(%s, p + p[3] - p[1]); (A) GATE2011 (B) E2011 (C) 2011 (D) 011 Answer: - (C) why is p[3] - p[1] returning 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] GATE 2011 C Ques
p[3] = 'E' p[1] = 'A' p[3]-p[1] = 4 ? On Sat, Jul 2, 2011 at 7:10 PM, KK kunalkapadi...@gmail.com wrote: 10. What does the following fragment of C-program print? char c[] = GATE2011; char *p =c; printf(%s, p + p[3] - p[1]); (A) GATE2011 (B) E2011 (C) 2011 (D) 011 Answer: - (C) why is p[3] - p[1] returning 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] GATE 2011 C Ques
ASCII value of 'A' is 65 and Asciivalue of 'E' is 69. 69-65=4 On Sat, Jul 2, 2011 at 7:12 PM, abhijith reddy abhijith200...@gmail.comwrote: p[3] = 'E' p[1] = 'A' p[3]-p[1] = 4 ? On Sat, Jul 2, 2011 at 7:10 PM, KK kunalkapadi...@gmail.com wrote: 10. What does the following fragment of C-program print? char c[] = GATE2011; char *p =c; printf(%s, p + p[3] - p[1]); (A) GATE2011 (B) E2011 (C) 2011 (D) 011 Answer: - (C) why is p[3] - p[1] returning 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: GATE 2011 C Ques
got it dont bother!!! anyway thanx abhijith!!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Recurrence Relation
3. Consider the following recurrence: T(n) = 2T(n ^ (1/2)) + 1 Which one of the following is true? (A) T(n) = (loglogn) (B) T(n) = (logn) (C) T(n) = (sqrt(n)) (D) T(n) = (n) Can we solve this using master theorem??? any other way??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Recurrence Relation
answer is option A . On Sat, Jul 2, 2011 at 8:32 PM, KK kunalkapadi...@gmail.com wrote: 3. Consider the following recurrence: T(n) = 2T(n ^ (1/2)) + 1 Which one of the following is true? (A) T(n) = (loglogn) (B) T(n) = (logn) (C) T(n) = (sqrt(n)) (D) T(n) = (n) Can we solve this using master theorem??? any other way??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: help..
@sunny ya i wanted to write the while(k % m == 0) On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: nn-1 is the expression to find out if n is a power of 2...If nn-1 returns 0 its a power of 2 else its not. And what sunny said is also ryt On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote: @cegprakash Expression resets the least significant set bit On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote: May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
@sunny thnx for the correction. On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote: @sunny ya i wanted to write the while(k % m == 0) On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: nn-1 is the expression to find out if n is a power of 2...If nn-1 returns 0 its a power of 2 else its not. And what sunny said is also ryt On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote: @cegprakash Expression resets the least significant set bit On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote: May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] pointer increment problem can anyone tell why this output is coming?
#includeiostream using namespace std; int main() { int intArray[]={1,2,3}; int *p=intArray; cout*(p++); return 0; } output : 1 -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] pointer increment problem can anyone tell why this output is coming?
ptr is pointing to array. *(ptr++) will give ptr and *ptr will give 1,further ptr will be incremented and will point to 2. On Sat, Jul 2, 2011 at 10:17 PM, Deoki Nandan deok...@gmail.com wrote: #includeiostream using namespace std; int main() { int intArray[]={1,2,3}; int *p=intArray; cout*(p++); return 0; } output : 1 -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] pointer increment problem can anyone tell why this output is coming?
yes thanx a lot . becoz there is no sequence point and there is post increment operator is used . On Sat, Jul 2, 2011 at 10:22 PM, aditya kumar aditya.kumar130...@gmail.comwrote: though you have put bracket over pointer but it will still be defrenced first and then the pointer will increemnet to point o next location . its post increement dats y. On Sat, Jul 2, 2011 at 10:17 PM, Deoki Nandan deok...@gmail.com wrote: #includeiostream using namespace std; int main() { int intArray[]={1,2,3}; int *p=intArray; cout*(p++); return 0; } output : 1 -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Sum to K problem
Is there some way to find 3 elements whose sum equal to K in an array in linear time. Sum of 2 numbers can be done in linear time using hash in O(n) time, what if for that case i am not allowed any extra space. -- 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/-/90sRhX0Im5EJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: 2 D array(dynamic allocation)
Here's my solution. int** allocateMatrix(int m, int n) { int **rowList = (int**)malloc(sizeof(int)*m*n + sizeof(int*)*m); int *colList = (int*)(rowList+m); int i; for(i=0; im; i++) { rowList[i] = colList+i*n; } return rowList; } And here's the main method to test/understand the allocation. int main() { int m=3, n=4; int **mat = allocateMatrix(m,n); int i, j, c=0; int wordCount= m*n+m; //sizeof(int)*4*5 + sizeof(int*)*4; counting words so sizeof is not needed int* memMap = (int*)mat; // Fill array elements with some values to be able to test for(i=0; im; i++) for(j=0; jn; j++) mat[i][j] = c++; printf(\nAddress\tValue\n); for(i=0; iwordCount; i++) printf(\n%u\t== %u, memMap+i, memMap[i]); getchar(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: 2 D array(dynamic allocation)
@sandeep sir: thnx... good 1 :) On Sat, Jul 2, 2011 at 11:32 PM, Sandeep Jain sandeep6...@gmail.com wrote: Here's my solution. int** allocateMatrix(int m, int n) { int **rowList = (int**)malloc(sizeof(int)*m*n + sizeof(int*)*m); int *colList = (int*)(rowList+m); int i; for(i=0; im; i++) { rowList[i] = colList+i*n; } return rowList; } And here's the main method to test/understand the allocation. int main() { int m=3, n=4; int **mat = allocateMatrix(m,n); int i, j, c=0; int wordCount= m*n+m; //sizeof(int)*4*5 + sizeof(int*)*4; counting words so sizeof is not needed int* memMap = (int*)mat; // Fill array elements with some values to be able to test for(i=0; im; i++) for(j=0; jn; j++) mat[i][j] = c++; printf(\nAddress\tValue\n); for(i=0; iwordCount; i++) printf(\n%u\t== %u, memMap+i, memMap[i]); getchar(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- best wishes!! Vaibhav Shukla -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] output plzzzz
1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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.
[algogeeks] Re: Recurrence Relation
Answer (B) Let n = 2^m, T(n) = T(2^m) Let T(2^m) = S(m) From the above two, T(n) = S(m) S(m) = 2S(m/2) + C1 Above expression is a binary tree traversal recursion whose time complexity is (m). You can also prove using Master theorem. S(m) = (m) = (logn) /* Since n = 2^m */ Now, let us go back to the original recursive function T(n) T(n) = S(m) = (Logn) I din understand this its GATE 2006 Q... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output plzzzz
i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output plzzzz
@piyush plz explain how are u getting this.. On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- HARSHIT PAHUJA M.N.N.I.T. 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.
[algogeeks] Taking Input
Hello, I came across a problem where the first line of the input specfies a number n. Then next n lines, every line contains a few(no limit) number seperated by spaces. Then I want to find the sm of numbers on each line. eg. INPUT 5 1 4 5 3 1 6 11 23 1 9 8 7 6 7 7 7 Now algorithm offcourse is not a problem. But I'm not getting how to take input in C. This is driving me crazy. tried with scanf and getchar but unable to get it right. Please help -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: GATE 2011 C Ques
using pointer arithmetic we have to skip four characters then 2011 is correct Wladimir Araujo Tavares *Federal University of Ceará * On Sat, Jul 2, 2011 at 11:00 AM, KK kunalkapadi...@gmail.com wrote: got it dont bother!!! anyway thanx abhijith!!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output plzzzz
will ny1 xplain this extern concept y this is a linker error? On Sat, Jul 2, 2011 at 12:49 PM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: @piyush plz explain how are u getting this.. On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- HARSHIT PAHUJA M.N.N.I.T. 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.
[algogeeks] Interview Question
Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without extra space? -- 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/-/W921z1woFOQJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Number of Comparisons!
How many comparisons are necessary to find the largest and smallest of a set of n distinct elements? Let's discuss it for n = 10 and maybe we can generalize it from there. -- 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/-/3HMDH51b-NcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Taking Input
you can use gets() ,to read a line and then easily find the individual numbers On Sun, Jul 3, 2011 at 1:22 AM, anonymous procrastination opamp1...@gmail.com wrote: Hello, I came across a problem where the first line of the input specfies a number n. Then next n lines, every line contains a few(no limit) number seperated by spaces. Then I want to find the sm of numbers on each line. eg. INPUT 5 1 4 5 3 1 6 11 23 1 9 8 7 6 7 7 7 Now algorithm offcourse is not a problem. But I'm not getting how to take input in C. This is driving me crazy. tried with scanf and getchar but unable to get it right. Please help -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: 2 D array(dynamic allocation)
Unfortunately this invokes undefined behavior, so it may not work for all architectures and compilers. It relies on pointers to int having the same alignment as int. By far the best way to do this is use C99 features: double (*a)[n_cols] = calloc(n_rows, sizeof *a); If you don't have C99 and the row length is fixed, then you can allocated a 2d array very easily: #include stdio.h #include stdlib.h #define ROW_SIZE 10 typedef double ROW[ROW_SIZE]; int main(void) { int i, j n_rows = 15; ROW *array = malloc(n_rows * sizeof(ROW)); for (i = 0; i n_rows; i++) for (j = 0; j ROW_SIZE; j++) array[i][j] = 100 * i + j; for (i = 0; i n_rows; i++) { for (j = 0; j ROW_SIZE; j++) printf(%5.0f, array[i][j]); printf(\n); } return 0; } If you need both array axes to be variable, then the norm is to allocate a 1d array and define a macro to allow 2d access: #include stdio.h #include stdlib.h typedef double *ARRAY; #define Elt(A, I, J, NCOLS) ((A)[(I) * (NCOLS) + (J)]) int no_fixed(void) { int i, j, n_rows = 15, n_cols = 10; ARRAY array = malloc(n_rows * n_cols * sizeof array[0]); for (i = 0; i n_rows; i++) for (j = 0; j n_cols; j++) Elt(array, i, j, n_cols) = 100 * i + j; for (i = 0; i n_rows; i++) { for (j = 0; j n_cols; j++) printf(%5.0f, Elt(array, i, j, n_cols)); printf(\n); } return 0; } On Jul 2, 2:05 pm, vaibhav shukla vaibhav200...@gmail.com wrote: @sandeep sir: thnx... good 1 :) On Sat, Jul 2, 2011 at 11:32 PM, Sandeep Jain sandeep6...@gmail.com wrote: Here's my solution. int** allocateMatrix(int m, int n) { int **rowList = (int**)malloc(sizeof(int)*m*n + sizeof(int*)*m); int *colList = (int*)(rowList+m); int i; for(i=0; im; i++) { rowList[i] = colList+i*n; } return rowList; } And here's the main method to test/understand the allocation. int main() { int m=3, n=4; int **mat = allocateMatrix(m,n); int i, j, c=0; int wordCount= m*n+m; //sizeof(int)*4*5 + sizeof(int*)*4; counting words so sizeof is not needed int* memMap = (int*)mat; // Fill array elements with some values to be able to test for(i=0; im; i++) for(j=0; jn; j++) mat[i][j] = c++; printf(\nAddress\t Value\n); for(i=0; iwordCount; i++) printf(\n%u\t== %u, memMap+i, memMap[i]); getchar(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- best wishes!! Vaibhav Shukla- 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.
Re: [algogeeks] Number of Comparisons!
If n is odd, then we perform 3*n/2 comparisons. If n is even, we perform 1 + 3*(n-2)/2 -- Regards UDIT DU- MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output plzzzz
this will help -sizeof operator only need declaration not definition.since sizeof operator calculates size at compile time. At compile time code doesnot seek for definition.it only need declaration.if any variable is declared with extern,it thinks that its definition will be found at linking time. In ur question: 1 case. when a =20 is done compiler see that its value is declared.so its OK .but at link time since def of a is not found so linker error. since linker tries to find the actual memory address where the def of a is. see after compilation the symbol table for a will be as symbolname| memory location| value a |find later(garbage)| 20 so there is no problem with compiler .but at link time garbage value need to be filled with actual memory address since def is not there so linker error. case2. there will be noentry in the symbol table for a. as code doesnot include any defintion related operation. iF anything helps you, dont forget to say thanks Thanks Santosh On Sun, Jul 3, 2011 at 1:38 AM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: will ny1 xplain this extern concept y this is a linker error? On Sat, Jul 2, 2011 at 12:49 PM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: @piyush plz explain how are u getting this.. On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- HARSHIT PAHUJA M.N.N.I.T. 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.
[algogeeks] Re: Interview Question
xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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 Question
xor will only result if corresponding elements are same . what if in both the array set of integers are same but they arnt corresponding to each other ?? On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote: xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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] Re: Taking Input
#includestdio.h #includestdlib.h #define INF 9 int main() { int no,i,j=0,num=0; int adj[102][102]={INF}; char neighbours[103],c; scanf(%d,no); for(i=1;i=no;i++) { j=0; gets(neighbours); puts(neighbours); } system(PAUSE); } Can you please tell me why the following code is taking only (no-1) strings as input? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question
Dont think that the corresponding elements should be same. XOR Should do it anyway. Btw other question How would you find the second largest element in an array using minimum no of comparisons?Any thing better than O(n).? On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar aditya.kumar130...@gmail.comwrote: xor will only result if corresponding elements are same . what if in both the array set of integers are same but they arnt corresponding to each other ?? On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote: xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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. -- Mohit Mittal 4th year , Computer Engineering Student-Coordinator , DTU WebTeam Delhi Technological University -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Taking Input
Hey Thanks,, I got it.. when I press enter after entering the number it takes that as an empty string. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question
@mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont think dat you can find second largest in less than O(n). On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.com wrote: Dont think that the corresponding elements should be same. XOR Should do it anyway. Btw other question How would you find the second largest element in an array using minimum no of comparisons?Any thing better than O(n).? On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar aditya.kumar130...@gmail.com wrote: xor will only result if corresponding elements are same . what if in both the array set of integers are same but they arnt corresponding to each other ?? On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote: xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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. -- Mohit Mittal 4th year , Computer Engineering Student-Coordinator , DTU WebTeam Delhi Technological University -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output plzzzz
thanx i got it :) On Sat, Jul 2, 2011 at 1:57 PM, santosh mahto santoshbit2...@gmail.comwrote: this will help -sizeof operator only need declaration not definition.since sizeof operator calculates size at compile time. At compile time code doesnot seek for definition.it only need declaration.if any variable is declared with extern,it thinks that its definition will be found at linking time. In ur question: 1 case. when a =20 is done compiler see that its value is declared.so its OK .but at link time since def of a is not found so linker error. since linker tries to find the actual memory address where the def of a is. see after compilation the symbol table for a will be as symbolname| memory location| value a |find later(garbage)| 20 so there is no problem with compiler .but at link time garbage value need to be filled with actual memory address since def is not there so linker error. case2. there will be noentry in the symbol table for a. as code doesnot include any defintion related operation. iF anything helps you, dont forget to say thanks Thanks Santosh On Sun, Jul 3, 2011 at 1:38 AM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: will ny1 xplain this extern concept y this is a linker error? On Sat, Jul 2, 2011 at 12:49 PM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: @piyush plz explain how are u getting this.. On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- HARSHIT PAHUJA M.N.N.I.T. 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. -- HARSHIT PAHUJA M.N.N.I.T. 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.
Re: [algogeeks] Re: Taking Input
#include stdio.h #include string.h #include stdlib.h int main() { int n, num, i; scanf(%d, n); for (i = 0; i n; ++i) { char ch = '#'; printf(scanned from %d line: , i + 1); while (ch != '\n') { scanf(%d%c, num, ch); printf(%d , num); } printf(\n); } return 0; } Better? Veni Vedi Slumber ! On Sun, Jul 3, 2011 at 2:47 AM, anonymous procrastination opamp1...@gmail.com wrote: Hey Thanks,, I got it.. when I press enter after entering the number it takes that as an empty string. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] null macro
#include cstdio #define NULL1 (void *)0 #define NULL2 0 int main() { int* p = NULL1; // void* being assigned to a int*, C++ complains. int* q = NULL2; return 0; } Veni Vedi Slumber ! On Sat, Jul 2, 2011 at 10:28 PM, Decipher ankurseth...@gmail.com wrote: Hey I was asked this question in Broadcom's interview. I thought its worth to share it here since its related to null pointer : What's the dif b/w #define NULL (void*)0 and #define NULL 0 ? -- 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/-/mtyvsP4WoGIJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: ReadyForZero Programming Challenge
Hi VJ, You were right. By assuming that the traversal was that of a complete binary tree with height 9 (not 10), the solution was trivial. Thanks a lot men On Jun 23, 6:08 am, VJ vikas.jethn...@gmail.com wrote: what if we assume that it's a complete binary tree with height 10(2^10-1 = 1023) ?? On Jun 22, 3:05 pm, Tundebabzy tundeba...@gmail.com wrote: Thanks so much Wladmir. This algorithm will assume that the second character in the string will be the root of the binary tree which could be misleading. The root might be the last character in the string. The only thing that seems to be universally correct is that the first character in the string is a leaf in the binary tree. I thought of extracting all the numbers in the string. If i remember right, they are 136 in number. Since we are talking of the sum, it means that we don't have to bother about which side of the tree the digits in the leaves are since 2L + 3R = 5 and 3L + 2R = 5. But then again, I got to the question begging for an answer, which exactly in these numbers are in the leaves of the binary tree. I could brute force a calculation starting by assuming that all the digits are in the leaves and then eliminating some of the numbers but that will hardly be elegant and could just be called plain cheating even though the site does not penalize for getting an answer wrong. On Jun 22, 2:49 am, Wladimir Tavares wladimir...@gmail.com wrote: I thought of a brute force approach but did not work. For each character, I tested two possibilities: 1. Being a leaf (the leftmost node) and the next character is the root of a subtree. 2. Be the root of a subtree. After testing all possible sums! Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 21, 2011 at 10:55 AM, Tundebabzy tundeba...@gmail.com wrote: Hi guys, Can anyone help me solve this (I mean explain to me how to solve it): The following text is an in-order traversal of a binary tree with 1023 nodes. What is the sum of the digits appearing in the leaves? bDq4i3eFNmjh2oMgjNsIFkRWsonRl=tz9kf8gOpED2gVQrfx49GjR9/ QNqTEJkSzM30p4RfneDc7EmdusIYdxxZ8KKdND==YpLlmN/FkErS7uqVHYIyGEBIhIRX +mbg6FjVGqfYjobX3F1lSmPpLXXxhux1lV=EzIgGct9pd=ogzAdJU4/ yZOj9=njfvbSo11bcE/yUDHg/J=6DAtmWt+P/VDvE4GyYHlKVGUoksn +Lzm6Y1VVF6qw=onnKZS=CQQUPeMlUGtMobJEeyIyGBMFj5kHml1waI97qgVt/ yeKWSXxhJyK+As0M0UR2KL+U7klKMlWlxgbIJ2beN0gaMHbIClKrBuroo +L73CwnbFKRiyKOx8Ke=PPukm1BWYd4Do5nikrT0dgPWlmItCzyZrEiOBgBtEB9FG1qdQJud182 qYU4Xwry=bR7R5PH=Npab7JQ7gY=MYHW24iw=m2+XayIachr=QVt4giclLluUEu3Dx/ 5y7R0GlINqoJc9O6QwEP6a9PRsdt86nZYQUF/ b729lzilkM1PB8mDPACTOGobXSJJQshRQCoJoC9TX6ERou/ tlMWNQTaaU0YmzIFh8t72lgOeIMu4W2S9V8Y5jO8T47ZPRGxeQDWRQlpx1tc3AC4+x2zJxZaYV6 d4+rxxWgYnYC1ZwUvXNF2YLaRw7ldRXCz9/7xZ3mKBj4Ox51L3PqGXAIB +OI4pgkUc1X52tOPdRPgpsfi8wNpynfylwjITvNKq93iViQiyiEVGBgazbHQ7boh5tejStBE1SC k1fMe1=ycNoxJzhAH4x/ YlQSUOz/2qkl+JxFBt8sqRYXZjZ6R=Gh87ZwS4B0Meo56/WF+40bf2mTgG05KQ/ qR89NMyttHdwwnzvkZuXGrlt/yuStJaXJNkqQ5atDPWqLJy4Q9iylEdI3qmTe6Wmou/ umQG7Q +aiOXorJde3Z4CzMyTYnCWvudFDZvgEZsuKRiSOurstnxFRlqVQ0LC7WRuS=qCsDcxoDT5dl9NH usV4kZ/ I came across this @www.readyforzero.com/challenge(problem2) Please help me, I'm already tearing my hair out and i'm already getting bald. I'm stuck because I don't know how it is possible to figure out a tree from just its in-order traversal -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: help..
Another alternative soln. int rec_cut(int l, int k) { if (l == k) return 0; int tmp = k - (l1); return 1 + rec_cut(l1, tmp = 0 ? k : tmp); } int main() { int l, k; scanf(%d%d, l, k); printf(%d\n, rec_cut(l, k)); return 0; } Veni Vedi Slumber ! On Sat, Jul 2, 2011 at 9:47 PM, varun pahwa varunpahwa2...@gmail.comwrote: @sunny thnx for the correction. On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote: @sunny ya i wanted to write the while(k % m == 0) On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: nn-1 is the expression to find out if n is a power of 2...If nn-1 returns 0 its a power of 2 else its not. And what sunny said is also ryt On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote: @cegprakash Expression resets the least significant set bit On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote: May be this can work.give any counter example... int count; main() { int l,rope,cuts; scanf(%d%d,l,rope); count =0; find_cuts(l,rope); printf(cuts needed is %d,count); getch(); return 0; } int find_cuts(int l,int rope) { if(l==rope) return count; count++; printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; find_cuts(l,rope); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: Sort - Consecutive Array in O(n)
You can use a count sort, but you need an array to store the counts. The oppilas algorithm needs only constant extra storage. On Jun 30, 7:23 am, hary rathor harry.rat...@gmail.com wrote: can we not use count sort because of 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 algogeeks@googlegroups.com. To unsubscribe from 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 Question
@aditya. xor all elements mean that. take xor of each element of 1st array store in a variable that take xor of variable and each element of the second array if all elements are common then the variable will be 0 some where. var = a[0]; for(i = 1; i sizeof(a)/sizeof(a[0]); i++) var = var ^ a[i]; for(i = 0; i sizeof(b)/sizeof(b[0]); i++) var = var ^ b[i]; On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar aditya.kumar130...@gmail.comwrote: @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont think dat you can find second largest in less than O(n). On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.comwrote: Dont think that the corresponding elements should be same. XOR Should do it anyway. Btw other question How would you find the second largest element in an array using minimum no of comparisons?Any thing better than O(n).? On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar aditya.kumar130...@gmail.com wrote: xor will only result if corresponding elements are same . what if in both the array set of integers are same but they arnt corresponding to each other ?? On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote: xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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. -- Mohit Mittal 4th year , Computer Engineering Student-Coordinator , DTU WebTeam Delhi Technological University -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Number of Comparisons!
@Udit: This can't be correct. For n = 3, it predicts 4-1/2 comparisons. I don't know what half of a comparison is. Three comparisons are all that is required. In fact, for all odd n, it predicts a non-integer number of comparisons. Dave On Jul 2, 3:51 pm, udit sharma sharmaudit...@gmail.com wrote: If n is odd, then we perform 3*n/2 comparisons. If n is even, we perform 1 + 3*(n-2)/2 -- Regards UDIT DU- MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Number of Comparisons!
plz refer sahani's book of algo..:) On 7/2/11, Dave dave_and_da...@juno.com wrote: @Udit: This can't be correct. For n = 3, it predicts 4-1/2 comparisons. I don't know what half of a comparison is. Three comparisons are all that is required. In fact, for all odd n, it predicts a non-integer number of comparisons. Dave On Jul 2, 3:51 pm, udit sharma sharmaudit...@gmail.com wrote: If n is odd, then we perform 3*n/2 comparisons. If n is even, we perform 1 + 3*(n-2)/2 -- Regards UDIT DU- MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, -- **DIPANKAR DUTTA M-TECH,Computer Science Engg. EC Dept,IIT ROORKEE Uttarakhand , India – 247667 --- website:http://people.iitr.ernet.in/shp/09535009/Website/index.html ph no-09045809987 Lab: 286454 email:dipan...@iitr.ernet.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] output plzzzz
One thing to remember is that, *sizeof* operator does not evaluate the expression used as the parameter, it only evaluates type of the parameter. So, in case 2, sizeof(a) == sizeof(int) == 4. We never actually access 'a' Regards, Sandeep Jain Member of Technical Staff, Adobe Systems, India On Sun, Jul 3, 2011 at 3:13 AM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: thanx i got it :) On Sat, Jul 2, 2011 at 1:57 PM, santosh mahto santoshbit2...@gmail.comwrote: this will help -sizeof operator only need declaration not definition.since sizeof operator calculates size at compile time. At compile time code doesnot seek for definition.it only need declaration.if any variable is declared with extern,it thinks that its definition will be found at linking time. In ur question: 1 case. when a =20 is done compiler see that its value is declared.so its OK .but at link time since def of a is not found so linker error. since linker tries to find the actual memory address where the def of a is. see after compilation the symbol table for a will be as symbolname| memory location| value a |find later(garbage)| 20 so there is no problem with compiler .but at link time garbage value need to be filled with actual memory address since def is not there so linker error. case2. there will be noentry in the symbol table for a. as code doesnot include any defintion related operation. iF anything helps you, dont forget to say thanks Thanks Santosh On Sun, Jul 3, 2011 at 1:38 AM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: will ny1 xplain this extern concept y this is a linker error? On Sat, Jul 2, 2011 at 12:49 PM, HARSH PAHUJA hpahuja.mn...@gmail.comwrote: @piyush plz explain how are u getting this.. On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote: i) [Linker error] undefined reference to `a' ii) 4 On 7/3/11, HARSH PAHUJA hpahuja.mn...@gmail.com wrote: 1) #includestdio.h int main() { extern int a; a=20; printf(%d,sizeof(a)); return 0; } 2) #includestdio.h int main() { extern int a; printf(%d,sizeof(a)); return 0; } -- HARSHIT PAHUJA M.N.N.I.T. 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- HARSHIT PAHUJA M.N.N.I.T. 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. -- HARSHIT PAHUJA M.N.N.I.T. 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.
[algogeeks] Dynamic Programming problem
I need a help with this dynamic programming problem please. It is from the entrance exam practice problem set: Given an integer sequence x_1 ... x_n is there a nonempty sub sequences which sums to zero? Describe - no code necessary - a dynamic programming solution based on the predicate: A nonempty sub sequence of x_1 ... x_n has sum s I think that solution should be built on the recursive backtracking function that selects a min from these subsequences choices, but I think I am missing lots of details here. Any assistance is appreciated. Thank you in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Dynamic Programming problem
This is a recently discussed problem in this group. Refer to subset sum problem. http://en.wikipedia.org/wiki/Subset_sum_problem On Sun, Jul 3, 2011 at 6:34 AM, Edmon ebeg...@gmail.com wrote: I need a help with this dynamic programming problem please. It is from the entrance exam practice problem set: Given an integer sequence x_1 ... x_n is there a nonempty sub sequences which sums to zero? Describe - no code necessary - a dynamic programming solution based on the predicate: A nonempty sub sequence of x_1 ... x_n has sum s I think that solution should be built on the recursive backtracking function that selects a min from these subsequences choices, but I think I am missing lots of details here. Any assistance is appreciated. Thank you in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Interview Question
I think that the above algo will fail for the following two arrays: a={2,2,3,3} b={4,4,1,1} sum(a)=sum(b); a^b=0; len(a)=len(b); Correct me if i am wrong! Pranav On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.comwrote: @aditya. xor all elements mean that. take xor of each element of 1st array store in a variable that take xor of variable and each element of the second array if all elements are common then the variable will be 0 some where. var = a[0]; for(i = 1; i sizeof(a)/sizeof(a[0]); i++) var = var ^ a[i]; for(i = 0; i sizeof(b)/sizeof(b[0]); i++) var = var ^ b[i]; On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar aditya.kumar130...@gmail.com wrote: @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont think dat you can find second largest in less than O(n). On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.comwrote: Dont think that the corresponding elements should be same. XOR Should do it anyway. Btw other question How would you find the second largest element in an array using minimum no of comparisons?Any thing better than O(n).? On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar aditya.kumar130...@gmail.com wrote: xor will only result if corresponding elements are same . what if in both the array set of integers are same but they arnt corresponding to each other ?? On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote: xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each of the two arrays have the same set of ntegers ? Suggest an algo which can run faster than NlogN without 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 algogeeks@googlegroups.com. To unsubscribe from 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. -- Mohit Mittal 4th year , Computer Engineering Student-Coordinator , DTU WebTeam Delhi Technological University -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.