[algogeeks] meaning

2011-06-21 Thread sahil
#include int main() { int i=32, j=0x20 ,k,l,m; k= i|j; l=i&j; m= k^ l; printf("%d %d %d %d %d\n",i,j,k,l,m); return 0; } output: 32 32 32 32 0 please explain me ... j=0x20;wht does it mean.? and hoe ite value is 32...??? -- You received this message because you are subscribed to the

Re: [algogeeks] meaning

2011-06-21 Thread Srinivasan Sivaramachandran
Hexadecimal representation, 20h equals 32d Srinivasan Sivaramachandran On 21-Jun-2011 12:40 PM, "sahil" wrote: > #include > int main() > { > > int i=32, j=0x20 ,k,l,m; > k= i|j; > l=i&j; > m= k^ l; > printf("%d %d %d %d %d\n",i,j,k,l,m); > return 0; > > } > > > output: > 32 32 32 32 0 > > please

Re: [algogeeks] meaning

2011-06-21 Thread Manikanta Babu
0x20 means its a hexa decimal number and the decimal value is 32. Calculation is : 16 power of 0 + 2 * 16 power of 1 = 32 Thanks, Mani http://www.sanidapa.com On Tue, Jun 21, 2011 at 12:43 PM, Srinivasan Sivaramachandran < 21.sr...@gmail.com> wrote: > Hexadecimal representation, 20h equals 32d

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread uttam tiwari
i think it can be done by look ups..i.e. we start wid the smallest no..evaluate the factorial of dat n den using dis we can get the factorial of a bigger no.. ex. to calculate 10c3 we shud hav 3!, 7!, 10!, now firstly we evaluate 3!, den using dis evaluate 7! as 7!=7*6*5*4*3! n again 10!=10*9*8*7!

Re: [algogeeks] Google Search by Image

2011-06-21 Thread Raghavan
An idea which strikes to mind is, 1.Initially to form a map based on the text and all related text to it.[text,images]map 2.Also make a bitwise manipulation of every image and relate the texts to it.[imagebitwise,texts] map 3.If a image is put forth for search, check the texts from [imagebitwise,

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread Vandana Bachani
Why cant we first cancel the higher denominator first? Eg: For 10C3, 10!/(7!*3!) can be written as (10*9*8)/3!. This will be a little more performing if the difference in n/2 and r is significant. On Tue, Jun 21, 2011 at 1:09 PM, uttam tiwari wrote: > i think it can be done by look ups..i.e. we

Re: [algogeeks] [Brain Teaser] Extraordinary Riddle 21 june

2011-06-21 Thread Navneet Gupta
Time-Date was 12:34 5/6/78 On Tue, Jun 21, 2011 at 1:31 PM, Lavesh Rawat wrote: > Extraordinary Riddle  21 june > > Something Extraordinary happened on May 6th 1978 at 12:34am what was that? > > Update Your Answers at : Click Here > > Solution: > > Will be updated after 1 day > > -- > >          

[algogeeks] Re: priority inversion

2011-06-21 Thread ricky
But if low priority process is preempted then it should give up its resources right? On Jun 20, 10:30 am, Anand wrote: > What if low priority process holds a lock to some critical section which > high priority process when allowed for execution needs it. So if low > priority process is pre-empted

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Dumanshu
Dynamic programming using memoization is the best one i think. On Jun 21, 3:17 am, PRAMENDRA RATHi rathi wrote: > what is the shortest algo to find the value of nCr if both > n,r<100... > > - > PRAMENDRA RATHI > NIT ALLAHABAD -- You received this mess

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread kartik sachan
but for big numbers this method is very expensiveand hope give TLE in 1 sec question where n=1000 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe

Re: [algogeeks]

2011-06-21 Thread Navneet Gupta
One crude idea could be to generate permutations of all substrings of seq2 and then check if any of such permutations is a substring of seq1. Maintaining a count for chars in substring generated and updating it every time we get a higher value. ^thinking for better solution. On Tue, Jun 21, 2011

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread ross
Hi, Ya DP with memoization is best.. nCr= n-1Cr-1 + n-1 C r DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; (LINEAR SPACE COMPLEXITY is possible because at each time we require only 2 rows of the matrix) Base Cases, nCn = 1. DP[i,i]=1. 1Cn = 1 DP[1,j] =1. nC1 = n . nC0 = 1 for ( i = 0 - N ) for ( j= i -

Re: [algogeeks] Amazon

2011-06-21 Thread Navneet Gupta
I think searching for palindromes with same starting and ending characters and required lengths to construct the rectangle is one tricky way i can think of. For generic solution, a good data structure i can think of is a table of trees. We need to find the shortest and longest word and then create

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread ross
A small correction, j = 0 to i. On Jun 21, 2:01 pm, ross wrote: > Hi, > Ya DP with memoization is best.. > > nCr= n-1Cr-1 + n-1 C r > > DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; > > (LINEAR SPACE COMPLEXITY is possible because at each time we require > only 2 rows of the matrix) > > Base Cases, > nCn =

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
but it is O(N^2)...will give TLE On Tue, Jun 21, 2011 at 2:33 PM, ross wrote: > A small correction, j = 0 to i. > > On Jun 21, 2:01 pm, ross wrote: > > Hi, > > Ya DP with memoization is best.. > > > > nCr= n-1Cr-1 + n-1 C r > > > > DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; > > > > (LINEAR SPACE COMPLE

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
DP is good when we need to use intermediate values too.. here we only need to compute nCr as a final result so we cannot use DP here the Logic Vandana used will be helpful here. as nCr = n! / r! * n-r! without loss of generality we can assume that r < n-r else we can just replace r = n-r then w

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread PRAMENDRA RATHi rathi
@sunny if we calculate (n-r+1)*(n-r+2).*n first and then divide this value by r!.. then this method will fail with little large value of n..because first value will increase vry fast and will go out of limit.. - PRAMENDRA RATHI NIT ALLAHABAD O

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
no we can divide also with in the same loop On Tue, Jun 21, 2011 at 3:20 PM, PRAMENDRA RATHi rathi wrote: > @sunny if we calculate (n-r+1)*(n-r+2).*n first and then divide this > value by r!.. > then this method will fail with little large value of n..because first > value will increase vry f

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread PRAMENDRA RATHi rathi
are u saying to use double in the loop to divide and multiply together? or to use array to divide with one by which current value of (n-r+1) is divisible... - PRAMENDRA RATHI NIT ALLAHABAD On Tue, Jun 21, 2011 at 3:25 PM, sunny agrawal wrote: > no w

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
if it is given tha final answer fits in 64 bit signed integer then we can run a loop for i = n-r+1 to n keeping result in a 64 bit signed integer each time multiplying with i in this loop we need to add some code that will divide the result with r! to do this initialize a int j to 1 and each ite

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
this problem is same as *http://www.codechef.com/problems/MARBLES/* solution to this are public u can check for more clarification On Tue, Jun 21, 2011 at 3:51 PM, sunny agrawal wrote: > if it is given tha final answer fits in 64 bit signed integer then > > we can run a loop for i = n-r+1 to n >

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread hary rathor
nCr=(n-1)Cr+(n-1)C(r-1) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread kartik sachan
@ sunny i am not getting ur apporach but i am thinking like this.. taking an array from and intilize it to n to n-r a[1000]; int k=0; for(int i=n;i>=n-r;i--) a[k++]=i; for(int y=n-r;y>1;y--) for(j=0;jhttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] finding vlaue of nCr

2011-06-21 Thread sunny agrawal
i am doing the same thing without using array long long int res = 1; int j = 2; for(int i = n-k+1; i <= n; i++){ res *= (long long int)i; while(j <= k && res%j == 0){ res/=j; j++; } } On Tue, Jun 21, 2011 at 4:25 PM, kartik sachan wrote: > >

[algogeeks] Binary Tree

2011-06-21 Thread Anantha Krishnan
Hi All, Given a binary tree, find 2 leaf nodes say X and Y such that F(X,Y) is maximum where F(X,Y) = sum of nodes in the path from root to X + sum of nodes in the path from root to Y - sum of nodes in the common path from root to first common ancestor of the Nodes X and Y. Any ideas. Thanks & R

Re: [algogeeks] Binary Tree

2011-06-21 Thread Piyush Sinha
i am assuming all nodes have positive values.. Keep a buffer of all the leaf nodes..take two leaf nodes and find the LCA..compute sum from root to LCA and subtract it from the sum of nodes from root to the leaves...store all the sums and find maximum out of it.. On Tue, Jun 21, 2011 at 4:52 PM, A

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Dumanshu
@Sunny: the value can still overflow because Using the while loop u r dividing the res value whenever possible. so the while checks if the current j divides res or not. What if current res value is not divisible by that particular j ... it will multiply by i for next res value and it will keep doin

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
i have already mentioned that if final answer fits in 64 bit integer then it will not overflow On Tue, Jun 21, 2011 at 5:34 PM, Dumanshu wrote: > @Sunny: the value can still overflow because > Using the while loop u r dividing the res value whenever possible. so > the while checks if the curren

[algogeeks] Find an element which is not present?

2011-06-21 Thread Nitish Garg
We are given an array A of integers, we have to find an integer k that is not present in A. One assumption that is given is that the integers are 32 bit signed integers. One thing that can be done is to find the max or min element of the array and return max+1 or min-1 resp. But this solution f

[algogeeks] Re: Find an element which is not present?

2011-06-21 Thread Nitish Garg
One thing more it is not the question in which the array elements are from 1 to N and one element is missing. -- 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

Re: [algogeeks] Binary Tree

2011-06-21 Thread sunny agrawal
@Piyush good to start with But i think a recursive O(n) is possible in downward calls pass sum from root to node and on return calls pass sum from leafs to root of each subtree and using this collective information updating a global ans max. On Tue, Jun 21, 2011 at 5:05 PM, Piyush Sinha wrote: >

[algogeeks] Past bin for c, C++,Java

2011-06-21 Thread anji swe
Hi Folks, Please suggest a "best" pastebin for running c , c++, java code snippets. provide url also. -- Thanks&Regards Anjaiah Pulla -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googleg

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread keyan karthi
one way might be... find min element, max element declare a array buffer[max-min] memset this to -1 for( i=0 to size ) buffer[input[i]-min elemet]=1 now check in O(n) the first position that has a -1 in array buffer, this position + min element is the answer but this uses lotta extra memory

[algogeeks] ReadyForZero Programming Challenge

2011-06-21 Thread Tundebabzy
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/ QNqTEJkSzM30p4RfneDc7EmdusIYd

Re: [algogeeks] Google Search by Image

2011-06-21 Thread DK
There are specific algorithms for image matching. One of the more famous ones is to use Wavelet coefficients. Wavelet Coefficients are resolution independent ways of representing image content (The image data is mapped into a 0-1 2D space). You can perform a 2D difference analysis of the search

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread sunny agrawal
one of the possible create the min heap O(n) keep extracting elements and look for missing elements worst case it will be O(nlgn) equivalent to heap sort or Simply sort using quick sort or merge sort and then traverse through the array and look for missing ones On Tue, Jun 21, 2011 at 7:09 PM,

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread kartik sachan
hey sunny suppose u have to calculate 100c50 then there is a lot of chances of over flow becoz u have to multiply 100 to 50...i don't think it will work.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to thi

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread Nitish Garg
^^ The first solution could have done had it not for that much extra space. ^ I think the question can be solved in O(n) without using extra space. Need to scratch the grey cells! -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this

Re: [algogeeks] Re: spoj problem chairs

2011-06-21 Thread shady
what will be the dynamic programming solution to the above problem ? can anyone explain the states of the dp ? On Mon, Jun 20, 2011 at 6:53 PM, oppilas . wrote: > I think you have not read the question carefully. Please read it again and > try to ans for small values of n,k first. > for k=1, answ

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
i dont know why r u thinking so but this was my accepted solution for the problem. On Tue, Jun 21, 2011 at 7:34 PM, kartik sachan wrote: > hey sunny suppose u have to calculate 100c50 then there is a lot of > chances of over flow becoz u have to multiply 100 to 50...i > don't think i

[algogeeks] Re: Amazon

2011-06-21 Thread DK
Assumption 1: The alphabet size of the dictionary is a constant 'c' independent of the dictionary size 'n' (a reasonable assumption valid for this case). Assumption 2: Words are allowed to repeat in the array. (Otherwise it's a huge combinations explosion) Create a 2D array elements such that

[algogeeks] Re: Amazon

2011-06-21 Thread DK
Sorry, small amendment: Find the largest rectangle (by area) in the irregularly shaped elements array and output its dimensions as the result. This largest rectangle can be found using obvious DP equations. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread sanket dhopeshwarkar
1. find the min , max, and sum of all elements in array(say z) - o(n) 2. find x= sum(1..min) and y = sum(1..max) 3. ans = y-(x-min) -z if(ans ==0) return (min-1) or (max +1); else return ans; On Tue, Jun 21, 2011 at 7:37 PM, Nitish Garg wrote: > ^^ The first solution could have done had

Re: [algogeeks] priority inversion

2011-06-21 Thread dinesh bansal
Priority inversion happens when a higher priority task is help blocked by a lesser priority task. Suppose a system has a low priority task L, a high priority task H and few medium priority tasks. Now resource R has been locked by L and goes to sleep due to other medium priority tasks coming in. Si

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread PRAMENDRA RATHi rathi
i have also got AC...i am only asking for best algo. PRAMENDRA RATHI NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Wladimir Tavares
I got a doubt in the following code: if (k> n / 2) k = n-k; for (i = 1; i <= k, i + +) ans = ans * (n +1- i) / i; If (n +1- i) is not divisible by i this code should be wrong? I thought I needed to keep the numerator and denominator and go by dividing the numerator and denominator gcd num = 1 d

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread sunny agrawal
both will work fine in first case in each step what is done is ans = (ans*(n+1-i))/i; what happens is first iteration ans = n, i =1 so i divides ans sec. iteration ans = product of 2 consecutive nos at least one even so divisible by 2 in third, ans is prod of 3 consecutive no.s so divisible by 3

Re: [algogeeks] image processing

2011-06-21 Thread DK
If the two preconditions for an affine relationship are met: The collinearity relation between points; i.e., the points which lie on a line continue to be collinear after the transformation Ratios of distances along a line; i.e., for distinct colline

Re: [algogeeks] image processing

2011-06-21 Thread Arun Vishwanathan
thanks DK... what if its a perspective transformation and not affine exactly? cos i tried using this matrix [xnew ynew 1]=[a b c;d e f;0 0 1][x y 1] now after getting the matrix parameters using the feature points matched in both the images , when i put the border pixels as input to this matrix th

Re: [algogeeks] Re: spoj problem chairs

2011-06-21 Thread keyan karthi
dp(int chair,int person,bool previous) if(previous) dp(chair-1,person,0) else dp(chair-1,person-1,1)+dp(chair-1,person,0) with basic conditions as it is a circle.. if person is placed in first chair u cant place a person in last chair On Tue, Jun 21, 2011 at 7:38 PM, shady

[algogeeks] sort the array

2011-06-21 Thread aanchal goyal
you have an array of size n where first n/2 is sorted and the sencond half is sorted . You need to sort the entire array inplace Its second modification version is where first part is sorted and other is NOT sorted . You need to make entire sorted . -- Regards,* Aanchal Goyal*. -- You received

Re: [algogeeks] Binary Tree

2011-06-21 Thread Anantha Krishnan
Thanks. I expect more details in implementation point of view. Thanks & Regards, Anantha Krishnan On Tue, Jun 21, 2011 at 6:41 PM, sunny agrawal wrote: > @Piyush > good to start with > But i think a recursive O(n) is possible > in downward calls pass sum from root to node > and on return calls p

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Anika Jain
hey 1Cn is not 1.. On Tue, Jun 21, 2011 at 2:33 PM, ross wrote: > A small correction, j = 0 to i. > > On Jun 21, 2:01 pm, ross wrote: > > Hi, > > Ya DP with memoization is best.. > > > > nCr= n-1Cr-1 + n-1 C r > > > > DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; > > > > (LINEAR SPACE COMPLEXITY is possib

Re: [algogeeks] Minimum draws for correct labels

2011-06-21 Thread pacific :-)
Is it 4 draws if we were to identify them back ? On Tue, Jun 21, 2011 at 9:22 AM, Navneet Gupta wrote: > Nice..! > > On Tue, Jun 21, 2011 at 2:36 AM, oppilas . > wrote: > > Yes. One draw only. > > As all the box are incorrectly labeled so, box BW willl either contain > > 2Black or 2 white balls.

Re: [algogeeks] Minimum draws for correct labels

2011-06-21 Thread Nitish Garg
The answer is 1 only as stated in the above posts. -- 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/-/9N_HO3G2AX8J. To post to this group, send email to algoge

Re: [algogeeks] Coin Chain Reaction

2011-06-21 Thread Anika Jain
@navneet: i didnt get the question that expected no. of what u r asking?? On Mon, Jun 20, 2011 at 3:56 PM, Navneet Gupta wrote: > We have an unlimited number of dice at our disposal. Let's roll the > die. If the outcome is 1, 2, or 3, we stop; otherwise, if it is 4, 5, > or 6, a corresponding num

Re: [algogeeks] sort the array

2011-06-21 Thread Anika Jain
its like inplace mergesort On Tue, Jun 21, 2011 at 10:13 PM, aanchal goyal wrote: > you have an array of size n where first n/2 is sorted and the sencond half > is sorted . You need to sort the entire array inplace > Its second modification version is where first part is sorted and other is > NOT

Re: [algogeeks] sort the array

2011-06-21 Thread Praveen
i think we can use insertion sort On Tue, Jun 21, 2011 at 10:56 PM, Anika Jain wrote: > its like inplace mergesort > > > On Tue, Jun 21, 2011 at 10:13 PM, aanchal goyal > wrote: > >> you have an array of size n where first n/2 is sorted and the sencond half >> is sorted . You need to sort the e

Re: [algogeeks] sort the array

2011-06-21 Thread himanshu kansal
@anika: yar merge sort vl tk nlogn timeinstead u cn do dt maintain two ptrs one at the beginning and one intitially pointing to middle of the array... thn compare the elemnts pointed by them and swap the values if necesary nd incremnt d ptr as u go on... ths vl tk (n/2)+(n/2)-1 =O(n) time c

[algogeeks] OS

2011-06-21 Thread Akshata Sharma
A thread is usually defined as a ‘light weight process’ because an operating system (OS) maintains smaller data structures for a thread than for a process. In relation to this, which of the followings is TRUE? (A) On per-thread basis, the OS maintains only CPU register state (B) The OS does not ma

Re: [algogeeks] OS

2011-06-21 Thread rahul
A, D On Tue, Jun 21, 2011 at 11:16 PM, Akshata Sharma wrote: > A thread is usually defined as a ‘light weight process’ because an > operating system (OS) maintains smaller data structures for a thread than > for a process. In relation to this, which of the followings is TRUE? > (A) On per-thread

[algogeeks] os

2011-06-21 Thread Akshata Sharma
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x n y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore S. void P (binary_semaphor

Re: [algogeeks] os

2011-06-21 Thread rahul
If u want us to solve the GATE paper, please attach the paper, we will post the solution. regards. On Tue, Jun 21, 2011 at 11:21 PM, Akshata Sharma wrote: > The atomic fetch-and-set x, y instruction unconditionally sets the memory > location x to 1 and fetches the old value of x n y without allo

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread kartik sachan
hey anika here n<=1 and n>=0 so its 1 only -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] OS

2011-06-21 Thread Akshata Sharma
But, the OS maintains a separate PC (program counter ),stack and A CPU register state for a thread . So option A I am not sure is correct, it says ONLY.. scheduling and accounting information is stored for a process right? Can you please explain why C is not correct and D is correct? On Tue, Jun 2

Re: [algogeeks] Binary Tree

2011-06-21 Thread sunny agrawal
see this * https://ideone.com/1ZtIq* On Tue, Jun 21, 2011 at 10:23 PM, Anantha Krishnan < ananthakrishnan@gmail.com> wrote: > Thanks. > I expect more details in implementation point of view. > > Thanks & Regards, > Anantha Krishnan > > > On Tue, Jun 21, 2011 at 6:41 PM, sunny agrawal wrote: >

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread oppilas .
@Sanket, This is one of the possible solution but it does not take into account. On 6/21/11, sanket dhopeshwarkar wrote: > 1. find the min , max, and sum of all elements in array(say z) - o(n) > 2. find x= sum(1..min) and y = sum(1..max) > 3. ans = y-(x-min) -z >if(ans ==0) return (min-1)

[algogeeks] Amazon - Longest palindrome in a string in O(n)

2011-06-21 Thread Swathi
Does any one know how to return the "Longest palindrome in a string in O(n)". >From googling i found that we can use suffix trees but there is no code. I am looking for logic and also for running code. Thanks, Swathi -- You received this message because you are subscribed to the Google Groups "

Re: [algogeeks] Amazon - Longest palindrome in a string in O(n)

2011-06-21 Thread Balaji S
LCS(string,reverse(string)) ?? but this is not O(n) ryt.. -- With Regards, Balaji.S -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send

[algogeeks] Re: Intuitive Understanding of XOR Operation

2011-06-21 Thread sav
An interesting fact about XOR: a = 1 b = 2 a = a ^ b b = a ^ b a = a ^ b The code above swaps 'a' and 'b' without the need of a third receipt. Magic! I'm sure this is pretty well known but in my case it really helped clearing my sight on this matter. The father of pragmatism (Charles S. Peirce

Re: [algogeeks] image processing

2011-06-21 Thread DK
Have you tried pixel interpolation? (Because affines are pretty easy and you should try really hard to make them work). If it really is a perspective transformation then check: http://alumni.media.mit.edu/~cwren/interpolator/ (I have no experience with this so you're on your own after this). --

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread oppilas .
Nikhil, Not sure whether I understood the problem properly or not, but If we know the range of the element's why can't we do this? for (i=min_r;i<=max_r;i++) temp^-i; and then xor temp with array elements. If it is not what you are looking for then please provide some sample input and corresponding

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread L
The answer fits in 64 bit range. The calculations done are of the form D = (A*B) / C. Here {A,B,C,D} can be represented are 64 bit integers. But we cannot say that A*B will be a 64 bit integer and will cause overflows. To avoid this, Let's say G=GCD(A,C). Then the above can be written as D = ((A/G

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread kartik sachan
sir i think the same ans i gave the above.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegr

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Wladimir Tavares
@sunny agrawal In theory, it would be necessary to prove that the product of n consecutive numbers is divisible by n! do you agree? Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 21, 2011 at 5:01 PM, kartik sachan wrote: > sir i think the same ans i gave the above...

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread oppilas .
@Wladmir. If you see carefully,then it is quite obvious that product of n consecutive number will be divisible by n!. 3 must be a divisor of at least one number out of three consecutive number.( because each multiple of 3 lies, 3 number ahead of previous one.) Similarly, we can argue for ith numbe

Re: [algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Wladimir Tavares
@oppilas thanks! Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 21, 2011 at 9:47 PM, oppilas . wrote: > @Wladmir. > If you see carefully,then it is quite obvious that product of n > consecutive number will be divisible by n!. > > 3 must be a divisor of at least one numb

Re: [algogeeks] ReadyForZero Programming Challenge

2011-06-21 Thread Wladimir Tavares
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

Re: [algogeeks] Binary Tree

2011-06-21 Thread Anantha Krishnan
@sunny agrawal *Thanks a lot.* *Great code. I got the logic now.Thanks again.* * * Thanks & Regards, Anantha Krishnan On Tue, Jun 21, 2011 at 11:52 PM, sunny agrawal wrote: > see this > * > https://ideone.com/1ZtIq* > > > On Tue, Jun 21, 2011 at 10:23 PM, Anantha Krishnan < > ananthakrishnan@

Re: [algogeeks] Minimum draws for correct labels

2011-06-21 Thread Sriganesh Krishnan
nice!! On Tue, Jun 21, 2011 at 10:47 PM, Nitish Garg wrote: > The answer is 1 only as stated in the above posts. > > -- > 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/m

Re: [algogeeks] sort the array

2011-06-21 Thread Sriganesh Krishnan
ya...we can do it in O(n) n time!!! nice question! On Tue, Jun 21, 2011 at 11:01 PM, himanshu kansal < himanshukansal...@gmail.com> wrote: > @anika: yar merge sort vl tk nlogn timeinstead u cn do dt maintain two > ptrs one at the beginning and one intitially pointing to middle of the > array.

[algogeeks] strings

2011-06-21 Thread Sriganesh Krishnan
Input will be a string. We need to o/p a string with the order of characters same as the input but with same characters grouped together. I/P: abcdacde O/P: aabccdde I/P: kapilrajadurga O/P: kpilrrjdug I/P: 1232 O/P: 1223 …….. O(n) time……….. O(1) space…. how can you approach these t

Re: [algogeeks] strings

2011-06-21 Thread Harshal
You can make use of an auxiliary array(initialized to 0) to store the count of each char and then print it that many times. char inp[]="abcdaabcdefe"; int buff[256]={0}; for(int i=0;iwrote: > Input will be a string. We need to o/p a string with the order of > characters same as the input but w

Re: [algogeeks] strings

2011-06-21 Thread Harshal
ignore above solution. My bad, did'nt see O(1) space constraint!! On Wed, Jun 22, 2011 at 10:53 AM, Harshal wrote: > You can make use of an auxiliary array(initialized to 0) to store the count > of each char and then print it that many times. > char inp[]="abcdaabcdefe"; > int buff[256]={0}; >

Re: [algogeeks] Binary Tree

2011-06-21 Thread oppilas .
Sunny, Can but can we modify this code to get the *node X and node Y*?. On Wed, Jun 22, 2011 at 8:32 AM, Anantha Krishnan < ananthakrishnan@gmail.com> wrote: > @sunny agrawal > *Thanks a lot.* > *Great code. I got the logic now.Thanks again.* > * > * > Thanks & Regards, > Anantha Krishnan >