Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread sagar pareek
Sorry for the previous post it got a mistake here take a look again :- In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save "sagar" wi

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread sagar pareek
In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save "sagar" with phone no. 123456789 then we store it in TRIE as : s-NULL | a-NULL | g-NU

Re: [algogeeks] Re: MS question

2011-06-29 Thread rizwan hudda
Sorry dave, your solution works. Thanks for the answer, What I was assuming to be a Counting sort was a variant of it for integers. On Thu, Jun 30, 2011 at 7:56 AM, Dave wrote: > @Rizwan: I don't see the problem. Initialize an array of counters, one > for each possible last character, to zero. I

Re: [algogeeks] strange output

2011-06-29 Thread Jitendra singh
scanf returns no of integers it read,not the read integer. On 6/26/11, sameer.mut...@gmail.com wrote: > It breaks out correctly when test condition value is 0 i.e when value of t > is 1 > > On Sat, Jun 25, 2011 at 4:41 PM, sunny agrawal > wrote: > >> No, Read about the return type of scanf >>

Re: [algogeeks] linked list

2011-06-29 Thread Rohan Kalra
http://geeksforgeeks.org/?p=12000 -- 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/-/OnLux79bj3MJ. To post to this group, send email to algogeeks@googlegroups.

Re: [algogeeks] Re: Amazon telephonic question

2011-06-29 Thread ankit sambyal
@bittu : In your first approach which u pointed out : What if the minimum element is poped out of the stack ?? We may have to search the whole stack to get the minimum element. O(n) in worst case In your second approach which u pointed out : If u use 2 stacks, consistency of 2 stacks in a

Re: [algogeeks] Reverse

2011-06-29 Thread sagar pareek
Thanks On Wed, Jun 29, 2011 at 2:45 AM, aditya kumar wrote: > @sagar : it works perfectly fine. > > > On Tue, Jun 28, 2011 at 3:29 PM, sagar pareek wrote: > >> Check out my solution above :) >> Its reversing the string >> >> >> On Tue, Jun 28, 2011 at 1:56 PM, shady wrote: >> >>> no, you are

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread sunny agrawal
No reverse is not possible On Thu, Jun 30, 2011 at 5:58 AM, Dave wrote: > @Bittu: When you are finishedm can you change the DLL back into the > original BST? > > Dave > > On Jun 29, 5:54 pm, bittu wrote: > > Algorithm: > > 1.Convert BST into sorted DLL which Will Take O(N) Time(Check previous >

[algogeeks] hari wants to chat

2011-06-29 Thread hari
--- hari wants to stay in better touch using some of Google's coolest new products. If you already have Gmail or Google Talk, visit: http://mail.google.com/mail/b-6ef61f8152-0a1809a38a-VhQtjvDuk5tyOdsQd1DUn_Ec5dU You'll need to c

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

2011-06-29 Thread Wladimir Tavares
I know that is not the best solution but here we go: p [i] [j] = 1 if s [i.. j] is palindrome, 0 otherwise p [i] [i] = 1 p [i] [i +1] = s [i] == s [i +1] p [i] [k] = s [i] == s [k] & & p [i +1] [k-1], k> i +1 time complexity = O (n ^ 2) Space complexity = O (n ^ 2) You can modify the algorithm

Re: [algogeeks] Re: Queue using a stack

2011-06-29 Thread Ashish Goel
yes that is the solution is also wrote, however one critical point in this solution is if queue size is x then each stack needs to be of size x thereby requiring overall 2x space. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Thu, Jun 30, 2011

Re: [algogeeks] Google Interview

2011-06-29 Thread Jitendra singh
kthlargest(a[],b[],lefta,righta,leftb,rightb,k) { mida=lefta+(righta-lefta)/2; midb=leftb+(rightb-leftb)/2; if(a[mida]bmidb]) kthlargest(a[],b[],lefta,mida-1,midb+1,rightb,); else return a[mida]; } On 6/25/11, Anantha Krishnan wrote: > Idea is like this since both the array

Re: [algogeeks] Binary Tree

2011-06-29 Thread rajeev bharshetty
By traversing tree either preorder or inorder or postorder and storing the partial sums along the way and comparing the partial sums with the required sum can solve the problem On Wed, Jun 29, 2011 at 7:56 PM, Akshata Sharma wrote: > How to find a path in a given binary tree which sums up to a gi

Re: [algogeeks] Binary Tree

2011-06-29 Thread varun pahwa
I don't have any alternative solution till now. On Wed, Jun 29, 2011 at 8:05 PM, varun pahwa wrote: > @ankit: ur space complexity will be too high. i think it will be ultimately > 2^n where n is the number of the nodes. > > On Wed, Jun 29, 2011 at 1:10 PM, ankit sambyal wrote: > >> The idea is to

Re: [algogeeks] Binary Tree

2011-06-29 Thread varun pahwa
@ankit: ur space complexity will be too high. i think it will be ultimately 2^n where n is the number of the nodes. On Wed, Jun 29, 2011 at 1:10 PM, ankit sambyal wrote: > The idea is to traverse the binary tree in post order and find out all > the path sums and store them. Use a hashtable or any

[algogeeks] Re: Queue using a stack

2011-06-29 Thread Sanket
Well obviously. Were you suggesting using 4 stacks, each of size x/4 to enqueue x elements? Can you please share the algo for that? On Jun 28, 7:54 pm, Ashish Goel wrote: > sanket, if 2 stacks r of length x, then2x  elements should be nqed > Best Regards > Ashish Goel > "Think positive and find f

Re: [algogeeks] Re: Amazon Interview Question

2011-06-29 Thread Wladimir Tavares
Hi Guys, The @pacific solution is the best? Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 28, 2011 at 7:26 AM, sunny agrawal wrote: > you can initialize it to (Max-Min+1) > where Max = max of all elements > Min = min of all elements > > Or simple initialise it to a larg

[algogeeks] Re: MS question

2011-06-29 Thread Dave
@Rizwan: I don't see the problem. Initialize an array of counters, one for each possible last character, to zero. If there are no restrictions on the last character, use an array of 256 counters. Then, for each string, increment the counter corresponding to the last character of the string by the l

[algogeeks] Re: 2 D array(dynamic allocation)

2011-06-29 Thread Dave
@Rizwan: Not completely. What if ROW in your code is a variable (not a constant) that is not known until run time? Then you need to dynamically allocate space for your arr2D as well. So, contradicting my earlier "No" response, maybe something like this would work to allocate an array a with m rows

Re: [algogeeks] Backtracking!

2011-06-29 Thread rizwan hudda
http://www.acmsolver.org/books/Programming_Challenges_Miguel_Skiena.pdf Theres a chapter on Backtracking in this book.. On Thu, Jun 30, 2011 at 12:20 AM, Nitish Garg wrote: > I have found many problems solvable using backtracking like Find > permutations, 8 queens problem, 10*10 array maze etc.

Re: [algogeeks] Re: POWER CRISES :Spoj

2011-06-29 Thread rizwan hudda
http://ideone.com/MSLXT The constraints are so less that you can brute force the solution..N<100. My solution is O(N^3) On Thu, Jun 30, 2011 at 1:13 AM, harshit pahuja wrote: > http://en.wikipedia.org/wiki/Josephus_problem > here there is an explanation of the derivation of josephus  which is nt

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread rizwan hudda
I have solved this using one malloc find the code in http://ideone.com/BV9Kj On Thu, Jun 30, 2011 at 1:20 AM, Piyush Sinha wrote: > ohh sorrymy bad...i didnt read the whole question..i just read the > subject...:P > > i think its not possible if u want other than hary's solution... > > On 6/3

Re: [algogeeks] Re: MS question

2011-06-29 Thread rizwan hudda
@Dave: Think of it again counting sort won't work, If you are just considering the last character as the even though key is just last character, the value is the whole string.. On Tue, Jun 28, 2011 at 1:53 PM, juver++ wrote: > List[letter] - linked list of all words with the last character as l

Re: [algogeeks] Re: MS

2011-06-29 Thread rizwan hudda
There is a very simple solution to this problem, Pseudo Code follows: Inputs: str - string, c1,c2 are characters. *MinDistance(str, c1, c2): initialize RightMostIndex[127] with all entries as -1 initialize curMin as Len(str)+1 For i = 0 to Len(str) - 1 if str[i] is same c1 then

Re: [algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-29 Thread rizwan hudda
@Dumanshu: Your idea is definitely a good improvement, however the SPOJ Runtimes are not reliable.. The code which was getting 0.00 AC with 512 KB Buffer now runs in 0.02 Seconds.. And I tried submitting the code with enhancement u suggested it runs in 0.01 even with 8KB Buffer. http://ideone.com/

Re: [algogeeks] Amazon telephonic question

2011-06-29 Thread vikas
for 2nd part of 1st question, when array has become sorted for ex: 3 5 10 16 17 35 40 56 67 and num is 33 becomes : 3 5 10 16 16 .. make array of 17 elements s[0,0,1,2..] s[16] = 2 means we find a duplicate hense resultu int m = (num%2==1)?(num/2+1):(num/2) for (int i=0;im){arr

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread Dave
@Bittu: When you are finishedm can you change the DLL back into the original BST? Dave On Jun 29, 5:54 pm, bittu wrote: > Algorithm: > 1.Convert BST into sorted DLL which Will Take O(N) Time(Check previous > Posts Already Coded) you can see here "cslibrary.stanford.edu/109" > 2.take find sum int

[algogeeks] Re: 2 D array(dynamic allocation)

2011-06-29 Thread Dave
Apoorve: No. Dave On Jun 29, 2:34 pm, Apoorve Mohan wrote: > @piyush: only one call to malloc...ur sol has 2 > > On Thu, Jun 30, 2011 at 12:58 AM, Piyush Sinha > wrote: > > > > > > > int **p; > > p = (int **)malloc(sizeof(int *)*row); > > for(i = 0;i >       p[i] = (int *)malloc(sizeof(int)*col

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
O(n^2) and O(n^3) respectively. On Jun 30, 3:47 am, Dumanshu wrote: > if the output for the input "doomdoomdoom" is 8 then refer > tohttp://ideone.com/kX8MV > else if the output is 4 then refer tohttp://ideone.com/3tAKN > the second one is having a higher complexity. > ny suggestions? > > On Jun

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread bittu
Algorithm: 1.Convert BST into sorted DLL which Will Take O(N) Time(Check previous Posts Already Coded) you can see here "cslibrary.stanford.edu/109" 2.take find sum into DLL two pointer start,end which points to starting & end position of DLL. 3. start from start->data & end->data , keep checking u

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
if the output for the input "doomdoomdoom" is 8 then refer to http://ideone.com/kX8MV else if the output is 4 then refer to http://ideone.com/3tAKN the second one is having a higher complexity. ny suggestions? On Jun 29, 9:54 pm, Swathi wrote: > Given a string (assume there no spaces or punctuati

[algogeeks] Re: Queue using a stack

2011-06-29 Thread bittu
@ashish Dude you can Have a Look http://shashank7s.blogspot.com/2011/04/wap-to-implement-queue-using-stack.html do notify me if we can optimize the solution..:) Thanks Shashank "I Don't Do Code to Code But I Do Code to Build Product" Computer Science & Engineering Birla Institute of Technology,M

[algogeeks] Re: Amazon telephonic question

2011-06-29 Thread bittu
@juver++ correct @ankit you can see here 1st Approach . You can implement this by having each node in the stack keep track of the minimum beneath itself. Then, to find the min, you just look at what the top element thinks is the min.When you push an element onto the stack, the element is given th

[algogeeks] Re: Yahoo Question

2011-06-29 Thread bittu
1.Use Haddop & Map Reduce Framework .Obviously We Need Distributed Algo we will make one computer as master & assign the job to all slave computer to do the crawling the web depending upon the geographic area ( m thinking real time problem).to crawled the maximum pages in least time we need

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread bittu
use suffix array time will be O(N) e.g. in case of banana answer will be ana you can find more info here http://shashank7s.blogspot.com/2011/06/longest-repeated-substring-eg-maximum.html Thanks Shashank "I Don't Do Code to Code But I Do Code to Build Product" Computer Science & Engineering Bi

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
for the input "doomdoomdoom" output is 4 or 8? On Jun 30, 2:04 am, Dumanshu wrote: > I have used suffix arrays. Its easier to implement than trees. > code here-http://ideone.com/kX8MV > In case u find a test case givin wrong output plz do tell. > > On Jun 29, 9:54 pm, Swathi wrote: > > > > > > >

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
I have used suffix arrays. Its easier to implement than trees. code here- http://ideone.com/kX8MV In case u find a test case givin wrong output plz do tell. On Jun 29, 9:54 pm, Swathi wrote: > Given a string (assume there no spaces or punctuations), write a code that > returns the max. length of

Re: [algogeeks] Binary Tree

2011-06-29 Thread ankit sambyal
The idea is to traverse the binary tree in post order and find out all the path sums and store them. Use a hashtable or any other data structure to store the possible paths rooted at a node and going down-only. Now we can construct all paths going through a node from itself and its childrens' paths

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Piyush Sinha
ohh sorrymy bad...i didnt read the whole question..i just read the subject...:P i think its not possible if u want other than hary's solution... On 6/30/11, Apoorve Mohan wrote: > @piyush: only one call to malloc...ur sol has 2 > > On Thu, Jun 30, 2011 at 12:58 AM, Piyush Sinha > wrote: > >>

[algogeeks] Re: POWER CRISES :Spoj

2011-06-29 Thread harshit pahuja
http://en.wikipedia.org/wiki/Josephus_problem here there is an explanation of the derivation of josephus which is nt very clearcan some1 explain it plzz On Wed, Jun 29, 2011 at 12:40 PM, harshit pahuja wrote: > Hello guys... > http://www.spoj.pl/problems/POCRI/ > > this problem is using

[algogeeks] POWER CRISES :Spoj

2011-06-29 Thread harshit pahuja
Hello guys... http://www.spoj.pl/problems/POCRI/ this problem is using a variant of josephus problem. in josephus we for given n persons in a circle we start killing every kth person and last person remaining is the survivor..kth 2kth 3kth...so on i solved it using *f(n,k)=(f(n-1,k)+k)%m

Re: [algogeeks] Re: SPOJ GPA1

2011-06-29 Thread kartik sachan
@sunny atof(ab) is giving me as zero.so it will not affect the calculation i think so... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe f

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
@piyush: only one call to malloc...ur sol has 2 On Thu, Jun 30, 2011 at 12:58 AM, Piyush Sinha wrote: > int **p; > p = (int **)malloc(sizeof(int *)*row); > for(i = 0;i p[i] = (int *)malloc(sizeof(int)*column); > > On 6/30/11, Apoorve Mohan wrote: > > though thankx :) > > > > On Thu, Jun 30

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Piyush Sinha
int **p; p = (int **)malloc(sizeof(int *)*row); for(i = 0;i wrote: > though thankx :) > > On Thu, Jun 30, 2011 at 12:44 AM, Apoorve Mohan > wrote: > >> @above: man i need a 2d array not a 1d array... >> >> >> On Thu, Jun 30, 2011 at 12:38 AM, hary rathor >> wrote: >> >>> >>> #include >>> >>> int ma

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
though thankx :) On Thu, Jun 30, 2011 at 12:44 AM, Apoorve Mohan wrote: > @above: man i need a 2d array not a 1d array... > > > On Thu, Jun 30, 2011 at 12:38 AM, hary rathor wrote: > >> >> #include >> >> int main () >> { >> int *mat; >> int i,j; >> int ROW=4; >> int COL=3; >>

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
@above: man i need a 2d array not a 1d array... On Thu, Jun 30, 2011 at 12:38 AM, hary rathor wrote: > > #include > > int main () > { > int *mat; > int i,j; > int ROW=4; > int COL=3; > int k=0; > mat=(int *)malloc(ROW*COL*sizeof(int)); > >for(i=0;ifor(j=0;jmat[

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread oppilas .
Sorry, didn't noticed that it was hard coded :) On Thu, Jun 30, 2011 at 12:13 AM, oppilas . wrote: > You code returns 1 for > >- input: > > >abab1abab1 > >output: > > >1 > >- input: > > >abababab1abab: > > >1 > > > > On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread hary rathor
#include int main () { int *mat; int i,j; int ROW=4; int COL=3; int k=0; mat=(int *)malloc(ROW*COL*sizeof(int)); for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

[algogeeks] Backtracking!

2011-06-29 Thread Nitish Garg
I have found many problems solvable using backtracking like Find permutations, 8 queens problem, 10*10 array maze etc. Can anyone point me to some source from where I can learn BackTracking? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread oppilas .
You code returns 1 for - input: abab1abab1 output: 1 - input: abababab1abab: 1 On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan < ananthakrishnan@gmail.com> wrote: > http://ideone.com/oEfLE > > > On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan < > ananth

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread Anantha Krishnan
http://ideone.com/oEfLE On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan < ananthakrishnan@gmail.com> wrote: > I wish to say that we should not use any inbuilt functions. > > > On Wed, Jun 29, 2011 at 11:43 PM, oppilas . wrote: > >> What I wanted to say that, it's a trivial question for alg

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread Anantha Krishnan
I wish to say that we should not use any inbuilt functions. On Wed, Jun 29, 2011 at 11:43 PM, oppilas . wrote: > What I wanted to say that, it's a trivial question for algorithmic point of > view. > You could have just implemented a normal function without worrying about > complexity because the

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread oppilas .
What I wanted to say that, it's a trivial question for algorithmic point of view. You could have just implemented a normal function without worrying about complexity because the constraints were quite low. I have not tested it for all corner cases. If it fails somewhere then give the test case. I w

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread oppilas .
http://ideone.com/YlGCC On Wed, Jun 29, 2011 at 10:47 PM, Swathi wrote: > If you have any strong solution then write the pseudo code and explain your > logic... please dont simply write like this.. it saves lot of time... code > and explain > > > On Wed, Jun 29, 2011 at 10:45 PM, oppilas . wrote

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread ankit sambyal
@Swathi :We can't use trie data structure to store the phone numbers. The most sound reason is that the users require phone numbers to be sorted by name, but by using the trie data structure we can't get the phone numbers which are sorted by name. Again we can't use trie whose nodes are numbers, be

Re: [algogeeks] Re: SPOJ GPA1

2011-06-29 Thread sunny agrawal
hey how r u dealing with absent cases. for each case u r directly converting string to float but for absent u will call atof() for "ab" and compare it. On Wed, Jun 29, 2011 at 11:02 PM, kartik sachan wrote: > any one plzz reply > > -- > You received this message because you are subscr

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Ashish Goel
how abt two passes first one makes a multi map of char and its positions second one a bit tricky to eg abcabcabc first pass a,0,3,6, b,1,4,7 c,2,5,8 second pass first char is a, its next position is 3(find thrugh the map) repeated substring can be of length 3 for loop with this (count

Re: [algogeeks] BST

2011-06-29 Thread Anantha Krishnan
Check this http://ideone.com/o8gF2 On Wed, Jun 29, 2011 at 10:28 PM, Swathi wrote: > This should be very simple... follow inorder.. > > Inorder(Node* node, int counter, int N) > { > if(node == null)return; > Inorder(node->left, counter, N); > counter++; > if(counter == N) > { > print(node

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Piyush Sinha
jokes apart...then i think it can be done using dynamic programming using the similar approach of LCS but the time and space complexity both will be N^2.i am working on the pseudocode and post it within a few moments if it works.. On 6/29/11, Swathi wrote: > I dont know why people reply in pl

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Swathi
I never said you don't have right but even after saying they asked me to write the code.. you are asking the same question which is not at all good.. On Wed, Jun 29, 2011 at 11:01 PM, Ashish Goel wrote: > chk this and try to write urself > http://www.allisons.org/ll/AlgDS/Tree/Suffix/ > > peopl

[algogeeks] Re: SPOJ GPA1

2011-06-29 Thread kartik sachan
any one plzz reply -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more op

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Ashish Goel
chk this and try to write urself http://www.allisons.org/ll/AlgDS/Tree/Suffix/ people hv right to decide if they want to WAP or not. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Wed, Jun 29, 2011 at 10:55 PM, Swathi wrote: > I dont know why

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Swathi
I dont know why people reply in plain words.. I personally had this experience and i was asked to code but i couldn't On Wed, Jun 29, 2011 at 10:53 PM, Piyush Sinha wrote: > I dnt think any company is gonna ask u to code suffix tree..:P :P > > On 6/29/11, Swathi wrote: > > It does but i am asked

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Piyush Sinha
I dnt think any company is gonna ask u to code suffix tree..:P :P On 6/29/11, Swathi wrote: > It does but i am asked to code.. if you know the code for suffix tree then > please provide.. > > On Wed, Jun 29, 2011 at 10:30 PM, Piyush Sinha > wrote: > >> i think suffix tres will do the job if i hav

[algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
Is there any way to dynamically allocate a 2-D array using *using single call to malloc* in C ? -- regards Apoorve Mohan -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To un

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread Swathi
If you have any strong solution then write the pseudo code and explain your logic... please dont simply write like this.. it saves lot of time... code and explain On Wed, Jun 29, 2011 at 10:45 PM, oppilas . wrote: > Why are we thinking of suffix tree in this case. Does not make sense. > It the pa

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread oppilas .
Why are we thinking of suffix tree in this case. Does not make sense. It the password is valid then it is of length between 5-12 only. Simple brute force approach will give decent time enough + we will not waste necessary memory and large line of code. On Wed, Jun 29, 2011 at 10:38 PM, Swathi wro

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread Swathi
Please provide the psuedo code for suffix array or suffix trees which does this.. I got this question in amazon online test... We need to write code, compile and test in amazon online test.. On Wed, Jun 29, 2011 at 10:36 PM, rajat ahuja wrote: > i think > we need to form suffix array of the given

Re: [algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread rajat ahuja
i think we need to form suffix array of the given string with one extra information tht is frm which index we are considerin suffix then sort those uffixe pointres after tht single scan wud do the job thanks rajat ahuja On Wed, Jun 29, 2011 at 10:23 PM, Swathi wrote: > Write the implementation o

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Swathi
It does but i am asked to code.. if you know the code for suffix tree then please provide.. On Wed, Jun 29, 2011 at 10:30 PM, Piyush Sinha wrote: > i think suffix tres will do the job if i have not misunderstood the > question... > > On 6/29/11, Swathi wrote: > > Given a string (assume there no

Re: [algogeeks] Amazon - max substring

2011-06-29 Thread Piyush Sinha
i think suffix tres will do the job if i have not misunderstood the question... On 6/29/11, Swathi wrote: > Given a string (assume there no spaces or punctuations), write a code that > returns the max. length of the string that has repeated more than once. > > Thanks, > Swathi > > -- > You receiv

Re: [algogeeks] BST

2011-06-29 Thread Swathi
This should be very simple... follow inorder.. Inorder(Node* node, int counter, int N) { if(node == null)return; Inorder(node->left, counter, N); counter++; if(counter == N) { print(node->data); return; } Inorder(node->right, counter, N); } On Wed, Jun 29, 2011 at 9:03 PM, piyush kapo

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread Swathi
Please explain why you think TRIE use more space? To my knowledge TRIE says lot of memory as the common numbers are saved only once.. If you have any good reason then please explain and don't make any single line statements. On Wed, Jun 29, 2011 at 9:21 PM, MONSIEUR wrote: > trie uses more space

[algogeeks] Amazon - max substring

2011-06-29 Thread Swathi
Given a string (assume there no spaces or punctuations), write a code that returns the max. length of the string that has repeated more than once. Thanks, Swathi -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send ema

[algogeeks] Amazon - ispasswordvalid() implementation

2011-06-29 Thread Swathi
Write the implementation of isPasswordValid() function which return true if the following conditions matches 1) If password length is between 5 to 12 characters 2) It should be alpha numerics 3) There should not be any consecutive substrings ex - ab12abc [valid as there are no consecutive substrin

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread Dave
@Juver++: Because the two-inorder-traversals approach is less work than the one-inorder-traversal-plus-scan, since it only processes part of the BST, until it finds the match. Furthermore, it is more elegant, it that it doesn't use an extra array of size n. My guess is that the total stack space re

Re: [algogeeks] Binary Tree

2011-06-29 Thread Akshata Sharma
ya..there can be other paths, like the on you mentioned.. On Wed, Jun 29, 2011 at 9:25 PM, Piyush Sinha wrote: > 7+3 also give the sum to be 10??? > > On 6/29/11, Akshata Sharma wrote: > > How to find a path in a given binary tree which sums up to a given target > > value? > > for example if the

Re: [algogeeks] Binary Tree

2011-06-29 Thread Piyush Sinha
7+3 also give the sum to be 10??? On 6/29/11, Akshata Sharma wrote: > How to find a path in a given binary tree which sums up to a given target > value? > for example if the given BT is > >5 > / \ > 3 2 > / > 7 > and if the target is 10, then the path is root(5) + left node(3) + >

[algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread MONSIEUR
trie uses more space On Jun 29, 5:52 pm, sudheer kumar wrote: > USE TRIE > > > > On Wed, Jun 29, 2011 at 6:10 PM, shady wrote: > > go through the archives you will definitely find the answer :) > > > On Wed, Jun 29, 2011 at 6:05 PM, MONSIEUR wrote: > > >> What is the most efficient way, memory

[algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread MONSIEUR
u r right buddy but problem is to save memory On Jun 29, 7:33 pm, ankit sambyal wrote: > Hey guys, phone usually has comparatively very less memory. So, we > can't afford to have pointers for each phone no. So, the idea of > having a tree is rooted out. The best way can be to use a fixed arra

[algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread MONSIEUR
if u have known the answer u would have probably answered rather than writing this thing..:| On Jun 29, 5:40 pm, shady wrote: > go through the archives you will definitely find the answer :) > > On Wed, Jun 29, 2011 at 6:05 PM, MONSIEUR wrote: > > What is the most efficient way, memory-wise,

Re: [algogeeks] BST

2011-06-29 Thread piyush kapoor
Order Statistics Tree On Wed, Jun 29, 2011 at 8:15 PM, sunny agrawal wrote: > At each node if we store the Number of nodes in the left subtree.we can > find kth smallest in O(lgn) > else do a inorder traversal for k nodes > > On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal < > mittal.nishan..

[algogeeks] Re: linked list

2011-06-29 Thread Nishant
@sunny oh... i cudnt understand.can u plz explain by an example On Jun 29, 7:58 pm, sunny agrawal wrote: > I am not using extra space as i am not allocating new memory for storing > Nodes > i m using just 2 pointers on the same list, i think that will be allowed > > > > On Wed, Jun 29, 2011 a

Re: [algogeeks] linked list

2011-06-29 Thread Piyush Sinha
node *segregate(node *head) { node *even,*odd,*even1,*odd1; even=odd=NULL; while(head) { if((head->data)%2) { if(!odd) { odd = head;

Re: [algogeeks] Explain the o/p

2011-06-29 Thread rajeev bharshetty
@ashwini singh Printf() returns the number of values printed to the output so printf("%d %d",2,2) returns 3 and the second printf returns 4 so bitwise and of 3 and 4 is 0 so i is 0 . further printf statements print the values and the last two printf statements have 3 & 3 so answer is 3. Regards

Re: [algogeeks] Explain the o/p

2011-06-29 Thread rajeev bharshetty
@ashwini singh Printf() returns the number of values printed to the output so printf("%d %d",2,2) returns 3 and the second printf returns 4 so bitwise and of 3 and 4 is 0 so i is o . Similar explanation to further printf statements . Regards Rajeev N B I Blog @ www.opensourcemania.co.cc On Wed,

[algogeeks] Re: Explain the o/p

2011-06-29 Thread Nishant
in 1st printf no. of characters written are 3 and 4 and 3 & 4 is 0 which is equal to i next 3 printf are easy... now in last printf no. of characters written by 2 printf(s) are 3 and 3 and 3 & 3 is 3 which is printed by outer printf On Jun 29, 7:40 pm, ashwini singh wrote: > please ex-pla

Re: [algogeeks] Re: linked list

2011-06-29 Thread sunny agrawal
I am not using extra space as i am not allocating new memory for storing Nodes i m using just 2 pointers on the same list, i think that will be allowed On Wed, Jun 29, 2011 at 8:18 PM, Nishant wrote: > @sunny plz tell me the solution without using extra list...i've solved > it using extra list..

Re: [algogeeks] query

2011-06-29 Thread oppilas .
I have just copied ans pasted the code of OP. And changed " ". http://codepad.org/rBnx7z8V On Wed, Jun 29, 2011 at 8:17 PM, udit sharma wrote: > @Vaibhav: Sunny is also right bcz if u jst copy n paste d above code with > (/ *jp) it'll show an error... And the error is in printf statement. jst cut

[algogeeks] Re: linked list

2011-06-29 Thread Nishant
@sunny plz tell me the solution without using extra list...i've solved it using extra list... On Jun 29, 7:38 pm, sunny agrawal wrote: > maintain two pointers one at the tail of even number list one at tail of odd > Number list > traverse the list and add the number at required list > > On Wed, J

Re: [algogeeks] query

2011-06-29 Thread udit sharma
@Vaibhav: Sunny is also right bcz if u jst copy n paste d above code with (/ *jp) it'll show an error... And the error is in printf statement. jst cut it from the program n thn write it again.. It'll wrk properly -- You received this message because you are subscribed to the Google Groups "A

Re: [algogeeks] BST

2011-06-29 Thread sunny agrawal
At each node if we store the Number of nodes in the left subtree.we can find kth smallest in O(lgn) else do a inorder traversal for k nodes On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal wrote: > how to find kth smallest element in BST... > > -- > You received this message because you are su

Re: [algogeeks] BST

2011-06-29 Thread rajeev bharshetty
http://mukeshiiitm.wordpress.com/2010/04/07/finding-kth-smallest-element-in-binary/ I think this solves the problem :) Rajeev On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal wrote: > how to find kth smallest element in BST... > > -- > You received this message because you are subscribed to the

[algogeeks] Explain the o/p

2011-06-29 Thread ashwini singh
please ex-plain the o/p of each line o/p is 2 23 2 0 3 2 2 2 23 2 3 #include #include main() { int i; i=printf("%d %d",2,2) & printf("%d %d ",3,2); printf("\n%d",i); printf("\n%d\n",3,4); printf("%d %d ",2,2); printf("\n%d",printf("%d %d",2,2) & printf(

Re: [algogeeks] linked list

2011-06-29 Thread sunny agrawal
maintain two pointers one at the tail of even number list one at tail of odd Number list traverse the list and add the number at required list On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal wrote: > segregate even and odd nodes in a singly linked list.Order of even and > odd numbers must be same

[algogeeks] BST

2011-06-29 Thread Nishant Mittal
how to find kth smallest element in BST... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com.

[algogeeks] linked list

2011-06-29 Thread Nishant Mittal
segregate even and odd nodes in a singly linked list.Order of even and odd numbers must be same... e.g:- i/p list is 4->1->3->6->12->8->7->NULL o/p list 4->6->12->8->1->3->7->NULL -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to th

Re: [algogeeks] GOOGLE QUESTION

2011-06-29 Thread ankit sambyal
Hey guys, phone usually has comparatively very less memory. So, we can't afford to have pointers for each phone no. So, the idea of having a tree is rooted out. The best way can be to use a fixed array with circular indexing which is sorted by name, because the most frequent query is to search a pe

[algogeeks] Binary Tree

2011-06-29 Thread Akshata Sharma
How to find a path in a given binary tree which sums up to a given target value? for example if the given BT is 5 / \ 3 2 / 7 and if the target is 10, then the path is root(5) + left node(3) + right node (2). -- You received this message because you are subscribed to the Google Gro

Re: [algogeeks] GOOGLE QUESTION

2011-06-29 Thread rajeev bharshetty
@MONSIEUR Use Binary Search Tree as the data Structure to store the values for the Phone numbers because insertion and deletion is easy plus you will get the additional advantage of sorted list of phone numbers . So Binary search tree is better than using hash data structure . Regards Rajeev N B

  1   2   >