Re: [algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread atul anand
@Rahul : if you check the flow properly ,(lets concentrate on the root node , call other as left and right subtree) you will find that after done with reversing root->left->left subtree , it reaches root(backtrack to root) node and then swap root->left and root->right. now because it is inorder way

Re: [algogeeks] Re: How many ways n points can be connected

2012-02-09 Thread Terence
@rspr: Are you talking about dependencies in my approach? or adding new constraints? In my DP approach, f(n,m) only depends on f(n-1,m'), f(n-2, m') ,..., f(1,m') (m' <= m) Using s(n,m) denoting the number of all graphs of n vertices and m edges, obviously s(n,m) = C(n(n-1)/2, m) Instead of

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
What about just the root being reversed? Why is it different only in case of root? Rahul On Feb 9, 10:52 pm, Don wrote: > Because it reverses one side twice and the other side not at all. > It does a lot of work to accomplish nothing. > Don > > On Feb 9, 9:06 am, Rahul Menon wrote: > > > > > >

[algogeeks] Subset Generation

2012-02-09 Thread shady
Hi All, Anyway to implement this in a good manner http://www.spoj.pl/ARHN/problems/PRINCESS, solution is simple, check for ones and then generate numbers is an increasing number... so if a number n = 22(10110) then for k = 1, ans = 2(10) then for k = 2, ans = 4(100) then for k = 3, ans = 6(110) S

Re: [algogeeks] Spoj Domino Tiling

2012-02-09 Thread shady
well i have used three recurrences :P formed them by following a traditional approach f[i] = f[i-1] + 2*g[i-1] + h[i-1] + f[i-2]; g[i] = f[i-1] + g[i-1]; h[i] = f[i-1] + h[i-2]; On Thu, Feb 9, 2012 at 7:19 PM, Kunal Patil wrote: > I am solving spoj problem Tiling a Grid

[algogeeks] Re: determining if frequency is greater than n/2

2012-02-09 Thread Don
It can't be done in O(log n) unless the array is sorted or there is some other special property, for example, if all values x are known to be contiguous, allowing you to use a binary search to find the first and last location of x. In the general case it is impossible in O(log n) because you have

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
Because it reverses one side twice and the other side not at all. It does a lot of work to accomplish nothing. Don On Feb 9, 9:06 am, Rahul Menon wrote: > How come it just reversed the root? I still dont get it! > > Rahul > > On Feb 9, 7:57 pm, Don wrote: > > > > > It appears to be an attempt to

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
How come it just reversed the root? I still dont get it! Rahul On Feb 9, 7:57 pm, Don wrote: > It appears to be an attempt to reverse the tree. However, there is a > problem. It reverses the left sub-tree, then swaps the left and right > sub-trees. Then it reverses the right sub-tree. But wait!

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
Thanks! I knew that it wont reverse the tree but was not sure about how it reversed just the root. On Feb 9, 7:57 pm, Don wrote: > It appears to be an attempt to reverse the tree. However, there is a > problem. It reverses the left sub-tree, then swaps the left and right > sub-trees. Then it rev

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
It appears to be an attempt to reverse the tree. However, there is a problem. It reverses the left sub-tree, then swaps the left and right sub-trees. Then it reverses the right sub-tree. But wait! The original left sub-tree which we reversed is now the right sub-tree, so we actually unreversed it.

[algogeeks] Binary Search Tree Question

2012-02-09 Thread Rahul Menon
What does this function do? void function(Node **node){ if(*node!=NULL){ function(&(*node)->Left); Node *temp; temp = (*node)->Left; (*node)->Left= (*node)->Right; (*node)->Right = temp; functio

[algogeeks] Re: Finding pre order representation of expression

2012-02-09 Thread Gene
I think all the answers are wrong. Also pre-order is probably the wrong term here. The conventional term is prefix or Polish notation. You'd break up this expression at the level of lowest precedence as: (A - B) - C where A = ~16, B = ~14 / ~12, and C = 2 * 8 . Note I'm using ~ for unary nega

[algogeeks] Spoj Domino Tiling

2012-02-09 Thread Kunal Patil
I am solving spoj problem Tiling a Grid With Dominoes.(http://www.spoj.pl/problems/GNY07H/).. I am not able to come up with a recurrence relation.. One of my friend said it has the recurrence relation as f(n) = f(n-1) + 5*f(n-2) + f(n-3) - f(n-4). I am not convinced and have trouble deriving this f

[algogeeks] Finding pre order representation of expression

2012-02-09 Thread Rahul Menon
>From the following options, select the correct pre-order representation of the following expression. – 16 – – 14 / – 12 - 2 * 8 Please do answer how you arrived at the answer! Answers -–16--/14–12*28 -–16--/-1412*28 -–16-/–14–12*28 */--–16-14–1228 -- You received this message because you are s

[algogeeks] Re: How many ways n points can be connected

2012-02-09 Thread rspr
@Terence: The DP approach is nice. if we have constraint likewhile choosing the first 3 edges if it makes a triangle so we will require n edges to connect the graph completely...in the same fashion...after selecting 2 more edgesagain we have to check that is it making more trianglethen

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread payal gupta
i dont think its possible for unsorted array in O(logn).. Regards, PAYAL GUPTA , NIT-B On Thu, Feb 9, 2012 at 6:02 PM, atul anand wrote: > @payal : this will work for only sorted array not for unsorted. > > > On Thu, Feb 9, 2012 at 5:50 PM, payal gupta wrote: > >> http://www.geeksforgeeks

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread atul anand
@payal : this will work for only sorted array not for unsorted. On Thu, Feb 9, 2012 at 5:50 PM, payal gupta wrote: > http://www.geeksforgeeks.org/archives/4722 > O(logn) soln... > > Regards, > PAYAL GUPTA, > NIT-B > > > On Thu, Feb 9, 2012 at 5:33 PM, atul anand wrote: > >> ignore my commen

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread payal gupta
http://www.geeksforgeeks.org/archives/4722 O(logn) soln... Regards, PAYAL GUPTA, NIT-B On Thu, Feb 9, 2012 at 5:33 PM, atul anand wrote: > ignore my comment... > > > On Thu, Feb 9, 2012 at 4:15 PM, Ashish Goel wrote: > >> log n is impossible. the other solution i thought was of building a tree

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread atul anand
ignore my comment... On Thu, Feb 9, 2012 at 4:15 PM, Ashish Goel wrote: > log n is impossible. the other solution i thought was of building a tree > where each node contains value and its count. and then building a heap out > of these counts, but this will be overkill. > > the fact that rest of

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread Ashish Goel
log n is impossible. the other solution i thought was of building a tree where each node contains value and its count. and then building a heap out of these counts, but this will be overkill. the fact that rest of the n/2 elements are not unique is the killer in the logic otherwise only n/2+1 elem

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread atul anand
i guess can be done using binary indexed tree. On Thu, Feb 9, 2012 at 2:07 PM, Prakhar Jain wrote: > But in this post, we don't have prior information about what can be > possible majority element. > > According to my question, we know that either x is the majority element or > there is no major

Re: [algogeeks] determining if frequency is greater than n/2

2012-02-09 Thread Prakhar Jain
But in this post, we don't have prior information about what can be possible majority element. According to my question, we know that either x is the majority element or there is no majority element. Can we use that information to reduce complexity to O(log n)..??? -- You received this message b

Re: [algogeeks] Re: Function Name Mismatch

2012-02-09 Thread Aman Kumar
Thanx for reply can you provide some code snippet here? or some link for it. On Tue, Feb 7, 2012 at 11:30 PM, Prem Krishna Chettri wrote: > This is a simple implementation to Factory Design Pattern. What you have > to do is make an arbitrary class (Your Adapter) and always call this. > Howeve