Re: [algogeeks] BT

2011-01-09 Thread Harshal
@Nishaanth T1 has millions of nodes. Suppose all the nodes of T1 are equal to root of T2. Then u will have to check every where in T1. Putting height as constraint, u will have to check only those nodes whose height is equal to T2. It will reduce time complexity. Well m not able to think of

Re: [algogeeks] Re: post and pre increment operators

2011-01-09 Thread nishaanth
@priya...ya thats wat i meant by interleaving of operations(non-atomic operations). you can understand the results if you can trace the register values. On Sat, Jan 8, 2011 at 10:18 PM, Priyanka Chatterjee dona.1...@gmail.comwrote: @harshal, sundi: Use some compiler to check, i checked on gcc ,

Re: [algogeeks] tic tac toe

2011-01-09 Thread nishaanth
someone - going by the exact words of the problem description. Just see all the 8 possible winning combinations(row,column, 2 diagonals)...if anyone combination is filled by the same player..then there is a winner. I know it sounds trivial, correct me if i am wrong. On Sat, Jan 8, 2011 at 11:16

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread nishaanth
In essence what you say boils down to DFS , isnt it ? On Sat, Jan 8, 2011 at 10:15 PM, Algoose chase harishp...@gmail.com wrote: Will this work ? Find the node x, then the node y within the sub tree rooted at x and then z within the sub tree rooted at y since they must within a unique path

[algogeeks] Linear Recurrences

2011-01-09 Thread shady
hi all, Is there a way to find a formula for the nth element of a linear recurrence ? Instead of going linearly one by one c1, c2, c3 are the three constants. a(n+3) = c1*a(n+2) - c2*a(n+1) + c3*a(n) thanks. shady -- You received this message because you are subscribed to the Google

Re: [algogeeks] Serialization in BT

2011-01-09 Thread juver++
And what else? List doesn't represent the original tree structure. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-09 Thread juver++
There are 4 kids). So 1, 2, 3 are connected into a circle. There is no place for the remaining 4-th) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Linear Recurrences

2011-01-09 Thread radha krishnan
yes,u can use matrix exponentiation On Sun, Jan 9, 2011 at 3:49 PM, shady sinv...@gmail.com wrote: hi all, Is there a way to find a formula for the nth element of a linear recurrence ? Instead of going linearly one by one c1, c2, c3 are the three constants. a(n+3) = c1*a(n+2) -

[algogeeks] Re: Serialization in BT

2011-01-09 Thread juver++
You may find this http://en.wikipedia.org/wiki/Binary_tree#Encodings useful. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Serialization in BT

2011-01-09 Thread juver++
And this: http://www.cs.usfca.edu/~galles/cs245/lecture/lecture9.pdf -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Amazon Intrerview

2011-01-09 Thread juver++
Your approach is failed! Read my previous post. There is a simple counterexample when doing dfs from x we cannot reach target node cause z can be placeed into another subtree, so x is not its ancestor. -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: Linear Recurrences

2011-01-09 Thread juver++
There is very useful technique for this kind of problem. A(n) = C1 * A(n-1) - C2 * A(n-2) + C3 * A(n - 3). Let's introduce matrix B: C1 -C2 C3 100 010. A(n-1) A(n) B x A(n-2) = A(n-1) A(n-3) A(n-2) and so on.. So to find A(n) you should muultiply

[algogeeks] Re: tic tac toe

2011-01-09 Thread juver++
What do you mean by N term? Is it a size of the matrix N*N? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] post and pre increment operators

2011-01-09 Thread juver++
You are wrong, this doesn't depend on the order which is used by printf. In C/C++ order of evaluating function's parameters is undefined. So you may receive different results in different compilers. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: Google Interview Question

2011-01-09 Thread bittu
@lalit hi its because whenever we talk about multi-threading we need to take care of synchronization as the problem clearly says application made only single threaded means not synchronized otherwise as a programmer its his job to make a app..for multithreaded environment so that such problem

Re: [algogeeks] Re: Linear Recurrences

2011-01-09 Thread shady
I am not familiar with such techniques, can you please refer to some article where such techniques are explained, ... Regards, Shady On Sun, Jan 9, 2011 at 5:44 PM, juver++ avpostni...@gmail.com wrote: There is very useful technique for this kind of problem. A(n) = C1 * A(n-1) - C2 * A(n-2)

Re: [algogeeks] Re: Linear Recurrences

2011-01-09 Thread radha krishnan
You find this so useful http://zobayer.blogspot.com/2010/11/matrix-exponentiation.html On Sun, Jan 9, 2011 at 6:10 PM, shady sinv...@gmail.com wrote: I am not familiar with such techniques, can you please refer to some article where such techniques are explained,  ... Regards, Shady On

[algogeeks] Adobe - Algorithm

2011-01-09 Thread Decipher
Convert in O(n) time and O(1) space : a1,a2,a3,a4,.aN,b1,b2,b3,b4,.,bN to a1,b2,a2,b2,a3,b3,a4,b4,..aN,bN. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

[algogeeks] Re: Adobe Question

2011-01-09 Thread bittu
i think its DP Problemstill thinking on the soultion.. @ankur..ur approach nearly matches to mine..what i thought..but we need actual solution.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] SUMMER INTERNSHIP

2011-01-09 Thread Ankur Khurana
somebody might enlighten for 3rd year as well (INDIA) On Sun, Jan 9, 2011 at 6:53 PM, abhishesh srivastava abhishesh.srivast...@gmail.com wrote: Can anyone please tell me about the summer internship programs of various institute. I want to know how to register and about various summer

[algogeeks] Re: Adobe - Algorithm

2011-01-09 Thread Decipher
No its a single array . You have to convert first array into second in O(n) time and O(1) space . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group,

[algogeeks] Re: SUMMER INTERNSHIP

2011-01-09 Thread Decipher
Post your resume on some Job search website or try LinkedIn(Job search option) . In the search engine (of that website) put trainee or software trainee . You might find some useful result there . Or google search internship . -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread nishaanth
so if its in another subtree, whats the problem? If z is not reachable print 'no'. On Sun, Jan 9, 2011 at 5:32 PM, juver++ avpostni...@gmail.com wrote: Your approach is failed! Read my previous post. There is a simple counterexample when doing dfs from x we cannot reach target node cause z

[algogeeks] Re: Amazon Interview - Algorithms

2011-01-09 Thread juver++
It doesn't matter how to make transitions: from current position make all necessary moves, or determine all positions from which we can achieve i-th position. So your method is only the one of possible. -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread juver++
x = 2, z = 3, y = 1. Does your algo give correct answer for this? node 1 cannot be reached while DFS from node 2 https://lh3.googleusercontent.com/_qdJSDBXyZKE/TSi5XyCrEzI/ARg/PB7anNiPA2c/graph.png -- You received this message because you are subscribed to the Google Groups

[algogeeks] c aps

2011-01-09 Thread siva viknesh
#includestdio.h int main() { int i=2; for(printf(cat );printf(rat )i--;printf(mat )) { printf(bat ); } } ouput : cat rat bat mat rat bat mat rat can anybody plz explain how we get this output?? -- Regards, $iva -- You received this message because you are subscribed to the

[algogeeks] Re: c aps

2011-01-09 Thread juver++
This is simple. cat - initilization step of for loop rat - first loops's if passed, so i == 1 now bat - loop's body mat - loop's post operations rat - second loop's if passed, i == 0 now bat - loop's body mat - loop's post operations rat - thirrd calculation of the loop statement, first term

Re: [algogeeks] c aps

2011-01-09 Thread Prateek Jain
the printf function returns 1 when it prints a string.. for (1;1i--;1) { printf(bat); } note that i=2 has been cunningly initialized before. and the decrement of i has been done in middle expression of the for loop hence, actually its like for(;i--;) { } how many times will this execute?

Re: [algogeeks] Re: tic tac toe

2011-01-09 Thread juver++
For each row, column and both diagonals keep track amount of equal marks. Update these counts in O(1) when player makes move. To determine winner, iterater over each column, row and diagonals to check whether there is N equal marks. -- You received this message because you are subscribed to the

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread nishaanth
please describe the tree...give an elaborate explanation to your input On Sun, Jan 9, 2011 at 8:02 PM, juver++ avpostni...@gmail.com wrote: x = 2, z = 3, y = 1. Does your algo give correct answer for this? node 1 cannot be reached while DFS from node 2

[algogeeks] Problem from ACM ICPC 2010_2

2011-01-09 Thread rgap
I have solved the last one :) how can i solve this one: http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4805 using LCA, I used this algorithm: http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=lowestCommonAncestor but i dont know how to count the weights of the edges. I

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread juver++
See at the image. It is enough to see tre structure of the tree. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Problem from ACM ICPC 2010_2

2011-01-09 Thread juver++
Run dfs/bfs from the root (node 0). Store distance from the root to each node at the node's data. Then the final path's weight between i and j is: dist[i] + dist[j] - dist[lca(i, j)]. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

Re: [algogeeks] Re: Linear Recurrences

2011-01-09 Thread shady
thanks that was a very nice tutorial. but i am still stuck with S(n,3) = A(n+3) = 6*A(n+2) - 11*A(n+1) + 6*A(n) --- 1 S(n+1,4)=S(n,3)+4*S(n,4) 2nd stirling number 3*S(n+1,4) = 0, 0, 3, 30, 195, 1050, 5103, 23310 what will be the matrix for the

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread SVIX
Use a linked list (maintain both head and tail positions) and treat it as a queue insert/delete front or back... whatever... For each insert, see if it's less than the current min and maintain min... If you're deleting the current min, you may traverse from head to tail and recompute the

[algogeeks] Re: combinations problem

2011-01-09 Thread SVIX
knapsack typically tries to maximize one attribute while minimizing some other (or optimal max for both or similar such conditions)... for this problem, all we need to do is find one subset that adds up to the given number... there's no second criteria to maximize/minimize... Please correct me if

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread juver++
All operations should constant at least on average. So your idea is not suitable. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: combinations problem

2011-01-09 Thread juver++
As I've stated, problem is similar to the 0-1 knapsack. Find subset of elements which sums up to a given value. Possible transitions - to take or not to take particular element. That's why it's 0-1 knspsack. -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: Amazon Intrerview

2011-01-09 Thread SVIX
Start from the root and do a breadth first traversal until you hit x or Z... Once you have x or Z, treat that node as root and traverse breadth first on that sub-tree till you reach the other node (i.e, if you hit X first, see if you can reach Z from X)... At the same time, if you encounter Y

[algogeeks] Re: Amazon Intrerview

2011-01-09 Thread SVIX
Start from the root and do a breadth first traversal until you hit x or Z... Once you have x or Z, treat that node as root and traverse breadth first till you reach the other node (if you hit X first, see if you can reach Z from X)... At the same time, if you encounter Y during the sub-tree

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread SVIX
why's the linked list option not constant (at least for most cases)? the time's not constant only for delete operation (that too only if you delete the current min)... otherwise, everything is a O(1) operation... get_min() already has the min... push_rear(), pop_front() - you're maintaining the

Re: [algogeeks] Re: Adobe - Algorithm

2011-01-09 Thread Avi Dullu
Hey guys .. saw this discussion and wanted to add something .. I wrote the below program in college .. and I kindof have forgotten wat was the logic (see the problem with badly written code :P ), It works on a pattern which I found in this problem, I checked it and feel it works in order O(n) as

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread juver++
When you remove element from the front of queue, you should update min value for all remaining nodes. So it's linear. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

Re: [algogeeks] Re: Linear Recurrences

2011-01-09 Thread shady
Sorry for the confusion, Given series : http://oeis.org/A032263/list How to get the nth number of the series in O(log(n)) ? Regards, Shady On Mon, Jan 10, 2011 at 12:36 AM, shady sinv...@gmail.com wrote: thanks that was a very nice tutorial. but i am still stuck with S(n,3) = A(n+3) =

[algogeeks] Re: Adobe - Algorithm

2011-01-09 Thread bhawana goel
It can be done in O(n) time and O(1) space. Logic: 1. Start at i = 0. 2. Take first half of the array and exchange elements at i=2 to n/2 with n/2+1 3. n = n/2, start = n/2+1 4. Repeat steps 2 and 3 until n becomes 0. On Jan 9, 7:41 am, Decipher ankurseth...@gmail.com wrote: No its a single

[algogeeks] Mathalon

2011-01-09 Thread Hemant Verma
About Me: Currently work as SDE in Microsoft . Constant participant in programming contest around the world Handle : FameofLight. Successfully conducted many programming contest in college , including Alkhwarizm [ First Indian Contest to Publish a Editorial : I should take credit for this , as

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread Algoose chase
@Juver++ I am not sure if your input represents a path as asked in the problem. We typically think of a path within a binary tree as a downward path(from root to a leaf) thats not spread across different branches. Of course, if you consider that example as a valid case, then DFS wont work ! On

[algogeeks] Re: c aps

2011-01-09 Thread siva viknesh
@juver and prateekthanks a lot for the detailed and nice explanation :) On Jan 9, 8:03 pm, juver++ avpostni...@gmail.com wrote: This is simple. cat - initilization step of for loop rat - first loops's if passed, so i == 1 now bat - loop's body mat - loop's post operations rat - second

[algogeeks] Re: Problem from ACM ICPC 2010_2

2011-01-09 Thread rgap
Thanks, i finished it. :) it wasdist[i] + dist[j] - 2*dist[lca(i, j)] this problem is difficult :( http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4809 I dont have idea how to solve it. -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread SVIX
I think you misunderstood my solution... There's no min value for each node here... The queue class i propose will look like this... public class MyQ { private int? currentMin; //nullable current minimum val in the queue private LinkedListint itemsList; //constructor and init

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread SVIX
The only operation for which this solution doesn't have constant time (variable based on number of items in the list) is for 'delete' and that too when the minimum item is deleted. For all other cases, delete is constant as well... For delete in those special cases, time is O(n)... On Jan 9,

Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread yq Zhang
Then it is O(n) worst case. While juver's algo is amortized constant time in worst case. On Jan 9, 2011 10:26 PM, SVIX saivivekh.swaminat...@gmail.com wrote: The only operation for which this solution doesn't have constant time (variable based on number of items in the list) is for 'delete' and