Re: [algogeeks] Re: How to print path of a node

2010-09-07 Thread Mayur
Like Adam says, the complexity will depend upon what your input looks like, as also, what exactly is the problem. If you are required to do a search for the keys first, then it's going to be really expensive. If on the other hand, you already have the two pointers, and if you do have the parent po

[algogeeks] Re: Spoj problem (dynamic programming)

2010-09-07 Thread Gene
This is a nice problem. The trick is always defining the recurrence in an artful way. Here let E(L, e) be the number of bracket expressions of length L that are proper _except_ that there are e extra left brackets. So for L = 1 and 0 <= e <= n, we have E(1, e) = (e == 1) ? 1 : 0 That is, the on

Re: [algogeeks] Re: Spoj problem (dynamic programming)

2010-09-07 Thread Yan Wang
nice! On Tue, Sep 7, 2010 at 8:00 PM, Gene wrote: > This is a nice problem.  The trick is always defining the recurrence > in an artful way. > > Here let E(L, e) be the number of bracket expressions of length m that > are proper _except_ that there are e extra left brackets. > > So for L = 1 and

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-07 Thread Anand
Maximum Value Contiguous Subsequence problem in O(n). http://codepad.org/BhYxSlp4 On Tue, Sep 7, 2010 at 2:40 PM, ashish agarwal wrote: > yeah..it will be i=j+1; > it was misprinted > > > On Tue, Sep 7, 2010 at 10:57 AM, Sahana Gururaj wrote: > >> In the else if condition, the increment of the e

[algogeeks] Re: Spoj problem (dynamic programming)

2010-09-07 Thread Gene
This is a nice problem. The trick is always defining the recurrence in an artful way. Here let E(L, e) be the number of bracket expressions of length m that are proper _except_ that there are e extra left brackets. So for L = 1 and 0 <= e <= n, we have E(1, e) = (e == 1) ? 1 : 0 That is, the o

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-07 Thread ashish agarwal
yeah..it will be i=j+1; it was misprinted On Tue, Sep 7, 2010 at 10:57 AM, Sahana Gururaj wrote: > In the else if condition, the increment of the end index i should be i=j+1, > not i=j+i; Otherwise the algo is right, follows the principles of Kadane's > algo : > http://en.wikipedia.org/wiki/Maxi

[algogeeks] Stable in place counting sort

2010-09-07 Thread angshuman karmakar
Is it possible to perform counting sort on n elements without creating the extra array of size n,which is usually done in counting sort?where each element is [0,k-1].it can be done by swapping but the stable property of sorting is gone? so can we do it preserving the stability? -- You receive

Re: [algogeeks] Re: how we can access 2nd element of an struct

2010-09-07 Thread albert theboss
typedef struct list node; node a; (float*)((char*)a+2) is it correct ?? correct me i am wrong -- 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 gro

[algogeeks] Re: How to print path of a node

2010-09-07 Thread Adam
What do you input into the algorithm corresponding to the specific node? A pointer pointing to the node or just the key value of that node used for query? These two situations are totally different in which the former one can be handled in O(d) time complexity and the other one will be O(2^d) compl

Re: [algogeeks] Re: Take 5 digit number and find 2 power that number.............

2010-09-07 Thread prasad rao
Thanks But it is used bigint but find a value without using bigint. On 4 September 2010 11:54, Shravan wrote: > http://ideone.com/4wj5t > > On Sep 3, 10:52 pm, Discover wrote: > > But how the number(in decimal form) will be displayedif ques > > demands so. > > > > On Sep 2, 1:49 pm, saurabh

Re: [algogeeks] Re: How to print path of a node

2010-09-07 Thread saurabh singh
what about iterative post order traversal ??? At any point when top matches the node to be searched then elements in stack give the path... On Tue, Sep 7, 2010 at 9:52 PM, soundar wrote: > try DFS > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Gee

Re: [algogeeks] Re: How to print path of a node

2010-09-07 Thread Yan Wang
This problem is not about which searching algorithm we should use. It's about what information we should store on every node while constructing the tree, which can help us backtrack to the root node from any given node in the tree and find the corresponding path. On one hand, if we don't store a po

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-07 Thread Sahana Gururaj
In the else if condition, the increment of the end index i should be i=j+1, not i=j+i; Otherwise the algo is right, follows the principles of Kadane's algo : http://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane.27s_algorithm On Mon, Sep 6, 2010 at 3:50 PM, ashish agarwal wrote: > int max

[algogeeks] Re: Spoj problem (dynamic programming)

2010-09-07 Thread soundar
post the problem link -- 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+unsubscr...@googlegroups.com. For more options, vi

[algogeeks] Re: How to print path of a node

2010-09-07 Thread soundar
try DFS -- 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+unsubscr...@googlegroups.com. For more options, visit this group

[algogeeks] Re: how we can access 2nd element of an struct

2010-09-07 Thread soundar
u didn't give any name for the structure so it'll give error.correct me if i am wrong -- 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

[algogeeks] how we can access 2nd element of an struct

2010-09-07 Thread ram das
how we can access 2nd element of an struct defined as struct { int a; flaot b; } we have given a void pointer of this struct. we dont know what is the structre only knows 2nd element is a flaot type. -- Thanks & Regards Ram Narayan Das mob: +91 9177711195 -- You received this message because

Re: [algogeeks] How to print path of a node

2010-09-07 Thread Yan Wang
While you are constructing a tree, you should store every node's parent in its field. Then the corresponding tree as you referred above should be 1(0) / \ 2(1) 3(1) / \ / \ 4(2) 5(2) 6(3) 7(3) / \ / \ / \ / \ 8(4) 9(4)

Re: [algogeeks] How to print path of a node

2010-09-07 Thread Yan Wang
Just store the parent on every node. On Mon, Sep 6, 2010 at 11:08 PM, Debajyoti Sarma wrote: > How to print the path from root to a specific node in a binary tree?? > I want to store the path in a array[] of node*. > can it b done in O(n) or less? > Remember it's not BST. > >              1 >    

[algogeeks] How to print path of a node

2010-09-07 Thread Debajyoti Sarma
How to print the path from root to a specific node in a binary tree?? I want to store the path in a array[] of node*. can it b done in O(n) or less? Remember it's not BST. 1 / \ 2 3 / \ / \ 4 5 67 / \/ \

[algogeeks] Spoj problem (dynamic programming)

2010-09-07 Thread hari
You are given: * a positive integer n, * an integer k, 1<=k<=n, * an increasing sequence of k integers 0 < s1 < s2 < ... < sk <= 2n. What is the number of proper bracket expressions of length 2n with opening brackets appearing in positions s1, s2,...,sk? plz.. explain how to solve th