Re: [algogeeks] Re: trie display

2012-06-28 Thread Guruprasad Sridharan
You should do a dfs from the node which matches the prefix say abc. If
its a word then print it.

On Thu, Jun 28, 2012 at 3:55 PM, deepikaanand swinyanand...@gmail.comwrote:

 It is not working..Even i tried to solve the problem using recursion
 but it didnt work

 code :-

 http://ideone.com/UhTTx

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] Question asked in Amazon Online test

2012-06-23 Thread Guruprasad Sridharan
Let u and r be the distance to move in the up and right directions. u=y2-y1
and r=x2-x1.

We have to move a total of u+r units. So the answer would be (u+r)!/u!r!
since we are counting only the distinct paths.
Each path from (x1,y1) to (x2,y2)  may be expressed as a sequence of u+r
steps consisting of U or R.
If seq[i] has U then it means we moved up at the i th step. Similarly R is
for right. The number of distinct paths would be the number of distinct
arrangements of the sequence.

On Sat, Jun 23, 2012 at 11:05 AM, Gobind Kumar Hembram gobind@gmail.com
 wrote:

 Given two positions in a 2-D matrix, say (x1, y1) and (x2, y2) where
 x2=x1 and y2=y1. Find the total number of distinct paths between
 (x1, y1) and (x2, y2). You can only move in right direction i.e.
 positive x direction (+1, 0) or in up direction i.e. positive y
 direction (0, +1) from any given position.

 Example: If the given coordinates are  (3,3)  and (5,5), the number of
 distinct paths are 6 :  one going through 3,5 ; one going through 5,3
 and four going through 4,4.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] Question asked in Amazon online test

2012-06-23 Thread Guruprasad Sridharan
Use a merge sort like procedure to count the number of inversions such that
0 appears after 1.

On Sat, Jun 23, 2012 at 11:34 AM, Gobind Kumar Hembram gobind@gmail.com
 wrote:

 Given an array containing sequence of bits (0 or 1), you have to sort
 this array in the ascending order i.e. all 0' in first part of array
 followed by all 1's.   The constraints is that you can swap only the
 adjacent elements in the array. Find the minimum number of swaps
 required to sort the given input array.

 Example:   Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps
 is 3.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] Question asked in Amazon online test

2012-06-23 Thread Guruprasad Sridharan
We need to sort as we count the inversions.

On Sat, Jun 23, 2012 at 11:56 AM, Gobind Kumar Hembram gobind@gmail.com
 wrote:

 If we use merge sort like procedure,ans will be 1 here it should be
 3.we have to swap 0s and 1s linearly.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Guruprasad Sridharan
It will work because we need to swap only adjacent elements. So we do a
sweep from left to right finding the number of ones encountered to the left
of a zero when we find a zero. We keep adding the number as we sweep the
entire length.

On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand swinyanand...@gmail.comwrote:

 @saurabh..wat array r u getting finallyis it all 1's or in sorted
 order for the input
  int a[8]={1,1,1,0,1,0,1,1};

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.