[algogeeks] Re: how to code a deterministic or Non-Deterministic finite state automata model?

2012-05-09 Thread Gene
The scanner part of any program that processes a language is probably a DFA. There are three main methods to code DFAs. Two use an explicit variable to represent state in this fashion: int state = INITIAL_STATE; while (!is_accepting_state(state)) { char ch = get_next_char(); state =

Re: [algogeeks] algorithm that returns number of internal nodes in the tree

2012-05-09 Thread Amit Jain
Here is my version Algorithm count(x) 1: if (x==nil || (left[x]== nil and right[x]==nil)) 2: return 0 3: return count(left[x]) + count(right[x]) +1 Time Complexity: O(n) where is n is total number of node in tree. Thanks On Wed, May 9, 2012 at 11:17 AM, Akshay Rastogi akr...@gmail.com

Re: [algogeeks] Re: find a point closest to other points

2012-05-09 Thread Nima Aghdaii
Wait! Let's clarify things before shooting random guesses. First of all, which norm is used for distance? I'm assuming that it is L2 norm (Euclidean distance). The problem statement clearly mentions that the answer should be one of the given points. So, I don't see any rationale behind taking the

Re: [algogeeks] algorithm that returns number of internal nodes in the tree

2012-05-09 Thread atul anand
internal_nodes=TotalNodes(root) - No_of_leaf_nodes(root); On Wed, May 9, 2012 at 1:19 PM, Amit Jain aj201...@gmail.com wrote: Here is my version Algorithm count(x) 1: if (x==nil || (left[x]== nil and right[x]==nil)) 2: return 0 3: return count(left[x]) + count(right[x]) +1 Time

Re: [algogeeks] Re: find a point closest to other points

2012-05-09 Thread atul anand
sort p(xi,yi) on the basis of x-axis. find media of x-axis = x_median sort p(xi,yi) on the basis of y-axis. find media of y-axis = y_median find distance from p(x_median,y_median) to all N points. the distance minimum from p(x_median,y_median) is the point closest point. algo seems to work ,