[algogeeks] Re: Spoj problem (dynamic programming)

2010-09-08 Thread Adam
There is my version of DP: Define C(m,n) as the number of proper bracket expressions B1,B2,B3,...,Bm+n with m left brackets '(' and n right brackets ')', in which 'proper' means that for each i belonging to {1,2,...,m+n} the number of left brackets '(' in B1,B2...Bi is larger than or equal to the

[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

[algogeeks] Re: Subsequence

2010-08-28 Thread Adam
Actually, your code just considers the only non-decreasing subsequence which starts from a[0] and is the most 'LEFT' one in this situation rather than all the possible subsequences. For example, we have such sequence as 2,3,999,, and k = 2. In this situation, your code will give the subsequen

[algogeeks] Re: Counting number of rectangles

2010-08-28 Thread Adam
this number as Ci. Finally, we count up C0, C1 ... Ck. Then we get the final answer C = C0 + C1 + ... + Ck. On Aug 24, 5:43 am, Saikat Debnath wrote: > Thank you Adam, but the thing is I don't only want the solution but > also, how to go about such questions? How do you came to a sol

[algogeeks] Re: kth smallest element in a heap < x

2010-08-26 Thread Adam
Just do a little changes on your given function, that may help you understand it: We denote the transformed function as heap_compare_new: int heap_compare_new(priority_queue *q, int i, int count, int x) { if ((count >= k) || (i > q->n) return(k-count); /* change */ if (q->q[i] < x) { count++;

[algogeeks] Re: Counting number of rectangles

2010-08-23 Thread Adam
Write here again: I find an easier non-recursive solution to compute the rectangle number (represented as RN) of an h x w rectangle (which has a height of h units and a width of w units): Situation 1: If (h and w are coprime) or (h = 1) or (w = 1) then RN = h + w - 1. Situation 2: If h and w a

[algogeeks] Re: Counting number of rectangles

2010-08-23 Thread Adam
Write here again: I find an easier non-recursive solution to compute the rectangle number (represented as RN) of an h x w rectangle (which has a height of h units and a width of w units): Situation 1: If (h and w are coprime) or (h = 1) or (w = 1) then RN = h + w - 1. Situation 2: if h and w a

[algogeeks] Re: Counting number of rectangles

2010-08-23 Thread Adam
I find an easier non-recursive solution to compute the rectangle number (represented as RN) of an h x w rectangle (which has a height of h units and a width of w units): Situation 1. if (h and w are coprime) or (h = 1) or (w = 1), then RN = h + w - 1 Situation 2. if h and w are not relatively pri

[algogeeks] Re: linked list as tree

2010-08-23 Thread Adam
What do you exactly mean? You want to represent a linear structure by using a tree structure? You can imagine a linked list as a tree with all its root and inner nodes only having one descendent/child node. On Aug 23, 10:50 am, Raj N wrote: > What will be the representation. How do you define lef