[algogeeks] Re: Directi question-centre of the tree

2010-10-03 Thread abhiram_n
I don't understand what you mean when you say minimum among all the
nodes in the graph.

In any case, your definition of centre of tree looks similar to the
closeness centrality measure - 
http://www.faculty.ucr.edu/~hanneman/nettext/C10_Centrality.html#Closeness

I doubt you can do it in O(N)...

On Sep 29, 12:41 pm, jayapriya surendran priya7...@gmail.com wrote:
 In graph theory, a tree is defined as a graph on N nodes,and (N-1)
 un-directed edges such that there are no cycles in the graph.Each node
 has a single unique path to every other node.
 Let D(u,v) be the number of edges in the unique path from node 'u' to
 node 'v' (or from node 'v' to 'u' since the edges are
 un-directed).D(u,u) is 0 for all nodes 'u'.
 M(u)=MAX(D(u,i):for all nodes i)
 The center of a tree is the node (or nodes) 'u',for which M(u) is
 minimum among all the nodes in the graph.
 You'll be given a graph which has N nodes (1=N=20).The nodes are
 labeled 1,2,3,..N.You will be provided with N-1 edges in the form of
 a b pairs where 1=a,b=N.No edge will be repeated.You can assume
 that the edges are specified such that the graph is a valid tree as
 defined above.
 Output the node labels of the center(or centers) of the tree.
 Sample Input:
 6(value of N)
 1 3 (edges)
 1 4
 1 2
 2 5
 2 6

 Sample Output
 1
 2
 Expected:O(N) complexity algo
 can anyone plz help me out with O(N) algo?

-- 
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 at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Multiplication of two numbers

2010-09-20 Thread abhiram_n
Wonder if this works:

x = A / 10^(a-1)  // take it as a decimal value itself
y = B / 10^(b-1) // take it as a decimal value itself
if x * y = 10.0
  return (a+b)
else
  return (a+b-1)

One advantage of the above method is that it can be done mentally.

On Sep 20, 10:47 am, Dave dave_and_da...@juno.com wrote:
 @Rahul. No. Considering your example 33*30, x*y + x + y = 3*3 + 3 + 3
 = 15 is not  10, so, as specified by Sumant, u will need a complex
 logic to solve.

 Dave

 On Sep 20, 5:31 am, rahul patil rahul.deshmukhpa...@gmail.com wrote:



  On Mon, Sep 20, 2010 at 1:15 PM, Baljeet Kumar baljeetk...@gmail.comwrote:

   If a and b are the numbers then
   dig = log10(a) + log10(b);
   if dig has some fractional part then number of digits is dig + 1 else dig.

  found this correct onw

   On Mon, Sep 20, 2010 at 11:19 AM, sumant hegde 
   sumant@gmail.comwrote:

   Adding to the partial solution, if x, y are first digits, and  x*y + x + 
   y
10, the result will be  a+b -1 digits. If not, u will need a complex
   logic to solve

  if we take 30 *  33 as an example then it is (3*3 + 3+3 ) 10  which says
  ans will be 4 digit
  but ans is 990 which is 3 digit.

   On Mon, Sep 20, 2010 at 10:50 AM, rahul patil 
   rahul.deshmukhpa...@gmail.com wrote:

   A partial solution is , if you multiply first digits of  two nos  and
   result is greater than 10 then surely result will be a+b digits
   If not, according to me, u will need a complex logic to solve.

   On Mon, Sep 20, 2010 at 10:41 AM, Srinivas 
   lavudyasrinivas0...@gmail.com wrote:

   how to find the no. of digits in the product of two numbers without
   multiplying??
   if a is the number of digits in A and
   if b is the number of digits in B
   the number of digits in A*B is either a+b or a+b-1 but how to find the
   exact one?

   --
   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.comalgogeeks%2bunsubscr...@googlegroups
­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

   --
   Regards,
   Rahul Patil

    --
   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.comalgogeeks%2bunsubscr...@googlegroups
­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

    --
   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.comalgogeeks%2bunsubscr...@googlegroups
­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

    --
   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.comalgogeeks%2bunsubscr...@googlegroups
­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

  --
  Regards,
  Rahul Patil- Hide quoted text -

  - Show quoted text -

-- 
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 at 
http://groups.google.com/group/algogeeks?hl=en.