Re: [algogeeks] Maximum height/depth of tree

2012-03-10 Thread Moheed Moheed Ahmad
should be 2.

-Cheers,
Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Sun, Mar 11, 2012 at 11:04 AM, rahul sharma wrote:

> http://www.geeksforgeeks.org/archives/646
>
> Plz tell that the link i have given in this mail for tree height...isn't
> the tree height is 2 in this???height is the longest path...n in path we
> include the number of edges or nodes??acc. to me its number of edges in
> longest path...plz tell..thnx in advance
>
> --
> 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] A strange doubt with cpp class. Why compile error ?

2012-03-10 Thread Moheed Moheed Ahmad
Isn't Abc() a constructor which means to construct the object. No need for
new..
-Cheers
Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Fri, Mar 9, 2012 at 9:16 PM, atul anand  wrote:

> may u r confused with java
>
> Abc a ; //  this itself is creating an object of type ABC in C++ , no need
> to use new keyword to allocate m/m.
>
> where as in C++ new keyword allocate m/m and return an address ,
> so to make it work do.
> Abc *a=new ABC();
>
> On Fri, Mar 9, 2012 at 8:28 PM, rahul sharma wrote:
>
>> on left side of new there should be pointer that should collect the
>> address of the memory allocated..
>>
>> write.
>>
>> ABC *a=new ABC();
>>
>>
>> correct if wrng...
>>
>>
>> On Fri, Mar 9, 2012 at 8:19 PM, sanjiv yadav wrote:
>>
>>> write..
>>>
>>> Abc a=Abc()
>>>
>>> it will execute...
>>>
>>>
>>> On Fri, Mar 9, 2012 at 8:15 PM, ~*~VICKY~*~ wrote:
>>>
 #include
 using namespace std;
 class Abc
 {

 public :
 int i;
 Abc(){ i = 0;}

 };
 int main()
 { Abc a = new Abc();
 cout<>>> }


 --
 Cheers,

   Vicky

  --
 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.

>>>
>>>
>>>
>>> --
>>> Regards
>>>
>>> Sanjiv Yadav
>>>
>>> MobNo.-  8050142693
>>>
>>> Email Id-  sanjiv2009...@gmail.com
>>>
>>>  --
>>> 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.
>>
>
>  --
> 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] Doubt in removing loop from linked list

2012-03-10 Thread Moheed Moheed Ahmad
@Rahul:
As Dev said:
Now start the fast pointer at the head and take m single steps with both
pointers. The fast pointer is at the beginning of the cycle, and the slow
pointer has traversed the cycle (2*t  - u) times and is back at the
beginning of the cycle.

k= (2*t-u)p -m

When fast pointer is being started from the beginning, the slow pointer has
not yet completed 2*t-u round, but m nodes less. That means if fast pointer
and slow pointer both are moved m nodes further, they will meet at
the beginning of the cycle.

Following is just a reasoning why both pointer can't meet sooner than m
step:
The pointers couldn't be equal sooner since the fast pointer is not in the
cycle after less than m steps and the slow pointer is in the cycle. "


-Cheers
Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Sat, Mar 10, 2012 at 4:02 PM, rahul sharma wrote:

> 1-2-3-4-5-6-7-8-9-10-11
> fast and slow meet at 11
>
> m=6;
> k=4
>
>
> ...i cant get last two lineswhen k= sometimes around the circle -
> m..
>
> then after that taking fast at begining and slow within circle ..i cant
> get this...@ dave plz explain with this example...will b of gr8
> help..thnx in advance..
>
>
> On Sat, Mar 10, 2012 at 3:02 PM, Kumar Vishal  wrote:
>
>> Hi
>> On Mar 9, 2012 3:48 PM, "rahul sharma"  wrote:
>>
>>>  i have 2 pointers fast and slow.now if tehy meet there is a loop...
>>>
>>> now keep one ptr at meeting point and take other one to the begining of
>>> listmove both at speed of one..they will meet at start of loophow
>>> this happens???why they meet at start..plz tell logic behind this???thnx in
>>> advance
>>>
>>> --
>>> 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.
>>
>
>  --
> 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] Practical way to check the primality in efficent time

2012-02-11 Thread Moheed Moheed Ahmad
There are deterministic polyomial-time algorithm. [AKS-primality]
Miller-Robin primality test is a non-deterministic primality test with
almost zero
chance of error.
[All above  based on some modification/improvement on fermat's theorem]

GNU Multi Precission library can be used to handle large integers/primes.

-Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Sat, Feb 11, 2012 at 8:32 PM, shady  wrote:

> There are many, but the one i know how to code is fermat's primality test.
> How to calculate all prime numbers between a given range efficiently i
> read somewhere that we can do bit-masking to store whether a number is
> prime or not, thus saving space ?
> I generally use double prime sieve.
>
> On Sat, Feb 11, 2012 at 8:24 PM, rspr  wrote:
>
>> what are the efficient ways to check that a given number is primer
>> assuming the numbers can be large.
>>
>> --
>> 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.
>

-- 
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] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-02-11 Thread Moheed Moheed Ahmad
Yeah, its BST(given that each node's data is different from others.)
-Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Fri, Feb 10, 2012 at 5:07 PM, Manni mbd  wrote:

> are you sure u want to ask BINARY SEARCH treees and not Binary trees..
>
> On 1/29/12, Moheed Moheed Ahmad  wrote:
> > I know how to solve it programatically, can anybody pls help me to solve
> it
> > using combinatorics.
> > -Moheed
> >
> > --
> > 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.
>
>

-- 
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] Quick Sort

2012-01-29 Thread Moheed Moheed Ahmad
A typical implementation of quick sort works on quick sorting subarray and
comparison is
done in a linear manner that is a[i] is compared with pivot and then a[i+1]
and so on. Virtual memory systems employ some sort of caching. Caching
works on the principle of spatial locality of reference. That said, once a
comparison begins, after a miss in the cache, cache is fetched for the
miss(a[i]) as well as for next few more memory cells (a[i+1], a[i+2], etc).
This ensures that next 'few'(typically 3-5) iteration of the loop will be a
cache hit, there by speeding up the algorithm.


-Moheed
"I am who I am, no matter where I am or who I am with."
*
*



On Sun, Jan 29, 2012 at 12:38 AM, karthikeya s wrote:

> How QuickSort is good in Virtual Memory Enviroment ?
>
> --
> 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.



[algogeeks] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-01-29 Thread Moheed Moheed Ahmad
I know how to solve it programatically, can anybody pls help me to solve it
using combinatorics.
-Moheed

-- 
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] LINKED LIST

2011-12-26 Thread Moheed Moheed Ahmad
http://cslibrary.stanford.edu/105/LinkedListProblems.pdf

-Moheed



On Sun, Dec 25, 2011 at 11:39 PM, atul anand wrote:

> @ashish : please provide link for that page
>
> On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel  wrote:
>
>> refer stanford page
>> 1,2,3,4,5,6
>>
>> will become
>>
>> 5,3,1
>> 6,4,2
>>
>> void MoveNode(struct node** destRef, struct node** sourceRef) {
>> struct node* newNode = *sourceRef; // the front source node
>> assert(newNode != NULL);
>> *sourceRef = newNode->next; // Advance the source pointer
>> newNode->next = *destRef; // Link the old dest off the new node
>> *destRef = newNode; // Move dest to point to the new node
>> }
>>
>> void AlternatingSplit(struct node* source,
>> struct node** aRef, struct node** bRef) {
>> struct node* a = NULL; // Split the nodes to these 'a' and 'b' lists
>> struct node* b = NULL;
>> struct node* current = source;
>> while (current != NULL) {
>> MoveNode(&a, ¤t); // Move a node to 'a'
>> if (current != NULL) {
>> MoveNode(&b, ¤t); // Move a node to 'b'
>> }
>> }
>> *aRef = a;
>> *bRef = b;
>> }
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>>
>> On Sat, Dec 24, 2011 at 11:37 PM, atul anand wrote:
>>
>>> because you are doing odd=odd->next; and even=even->next;
>>> you will lose head pointers for the two linked list formed once you come
>>> out of the loop.
>>>
>>>
>>>
>>> void segregate(node* head)
>>> {
>>> node *temp,*odd,*even;
>>> toggle=1;
>>> if(head==NULL)
>>> {
>>>  return;
>>> }
>>> odd=head;
>>>
>>> if(head->next==NULL)
>>> {
>>>
>>>  return;
>>> }
>>> even=head->next;
>>>
>>> if(even->next==NULL)
>>> {
>>>   return;
>>> }
>>> else
>>> {
>>>   temp=even->next;
>>> }
>>> node *otemp,*etemp;
>>> otemp=odd;
>>> etemp=even;
>>>
>>> while(temp!=NULL)
>>> {
>>>
>>> if( toggle == 1)
>>> {
>>>
>>>   otemp->next=temp;
>>>   otemp=otemp->next;
>>>
>>>   temp=temp->next;
>>>   otemp->next=NULL;
>>>
>>>   toggle=0;
>>> }
>>> else
>>> {
>>>   etemp->next=temp;
>>>   etemp=etemp->next;
>>>
>>>   temp=temp->next;
>>>   etemp->next=NULL;
>>>
>>>   toggle=1;
>>>
>>> }
>>>
>>>
>>>
>>> }
>>>
>>>
>>> }
>>>
>>> On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B 
>>> wrote:
>>>
 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2->3->1->9->7->5
 The output should be two separate lists
 2->1->7
 3->9->5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head->next;
 node *odd=head,*even=head->next;
 while(even)
 {
 if(i%2)
 {
 odd->next=even->next;
 even->next=NULL;
 odd=odd->next;
 if(!odd->next) break;
 }
 else
 {
 even->next=odd->next;
 odd->next=NULL;
 even=even->next;
 if(!even->next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 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.
>>>
>>
>>  --
>> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Moheed Moheed Ahmad
Thanks Don for pointing it out. It will not work [the second and
consecutive abs-diffs are not mutually exclusive].
However, here are the 10 possible numbers that will work for n=3 and
absdiff={0,0}:
0 0 0
1 1 1
2 2 2
--
8 8 8
9 9 9

-Moheed
'If a man neglects education, he walks lame to the end of his life.'



On Wed, Dec 14, 2011 at 12:17 AM, Don  wrote:

> Moheed,
> If n=3 and absdiff = {0,0}, your program says that there are 100
> possible numbers. Can you show me at least 10 of them?
> Don
>
> On Dec 13, 12:24 pm, Moheed Moheed Ahmad  wrote:
> > To get a abs difference of 0 there are 10 ways
> > similarly getting abs difference of 1 there are 9x2 ways(w1)
> > for 2 its 8x2 (say w(2)
> > for 3 its 7x2
> > .
> > for 9 its 1x2(w9)
> > let w(i) represents the number of ways to get abs diff of i.
> > So total numbers that are possible from the given abs diff   i j k l m
> ...
> > (w(i) x w(j) x w(k) x w(l) x.)
> >
> > Now algo will be to scan the given abs diff and multiply the w(i) for
> each
> > absdiff .
> >
> > int calculate_possible_nums(int absdiff[], int len){
> > int ways[]={10, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1};
> > int numways=1;
> > for ( i=0; i < len; i++){
> >  numways = numways * ways[absdiff[i]];
> > }
> >  return numways;}
> >
> > -Moheed
> > 'If a man neglects education, he walks lame to the end of his life.'
> >
> > On Tue, Dec 13, 2011 at 11:20 PM, Don  wrote:
> > > There should be 39 combinations with that input. You are missing
> > > numbers which include the digit zero, such as 14610, 30278, and 52056.
> >
> > > Don
> >
> > > On Dec 13, 11:37 am, tech coder  wrote:
> > > > I tried the problem and written the code for it . it is in java. it
> is
> > > > printing all the possible numbers
> > > > I  am treating the differences ans an array of integers.
> >
> > > > here is the code
> >
> > > > public class Main {
> >
> > > > public static void main(String[] args)
> > > > {
> > > >int digit[]={3,2,5,1};// array of absolute differences
> >
> > > > int digit[]={3,2,5,1};
> > > >for(int num=1;num<=9;num++) // call with all possible
> initial
> > > > numbers
> > > >findNumber(digit,4,num,0,num);
> > > > }
> >
> > > > public static void findNumber(int digit[],int n,int num,int i,int
> > > > oldDigit)
> > > > {
> > > > if(i==n)
> > > > {
> > > > System.out.print(num+"  ");
> > > > return;
> > > > }
> >
> > > > {
> > > > int o=digit[i]+oldDigit;
> > > > if(o<10)
> > > > findNumber(digit,n,10*num+o,i+1,o);
> > > > o=oldDigit-digit[i];
> > > > if(o>0)
> > > > findNumber(digit,n,10*num+o,i+1,o);
> >
> > > > }
> > > > }
> >
> > > > }
> >
> > > > and here is the output
> >
> > > > 14612  14278  14276  25723  25721  25389  25387  36834  36832  36498
> > >  47945
> > > >  47943  41389  41387  58612  52498  69723  69721  63167  63165  74612
> > > >  74278  74276  85723  85721  85389  85387  96834  96832  96498
> > > > BUILD SUCCESSFUL (total time: 0 seconds)
> >
> > > > On Tue, Dec 13, 2011 at 11:11 PM, Dave 
> wrote:
> > > > > @Amir: Presumably, since these are digits in a number, they are
> > > > > bounded on the bottom by 0 and on the top by radix-1. So in
> decimal,
> > > > > if a digit is 7 and the absolute difference between it and the next
> > > > > digit is 3, there is only one possibility for the next digit, 7-3
> = 4,
> > > > > since 7+3 is too large. So only some subset of the 2^(n-1)
> > > > > combinations of addition and subtraction may be possible.
> >
> > > > > Dave
> >
> > > > > On Dec 13, 4:15 am, Amir hossein Shahriari
> > > > >  wrote:
> > > > > > actually there are infinite number of sequences that match it
> > > > > > for example if the absolute differences are 3 2 5 1
> > > > > > one possible sequence is 6 3 5 0 1 one other is 7 4 6 1 2 or 8 5
>

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Moheed Moheed Ahmad
To get a abs difference of 0 there are 10 ways
similarly getting abs difference of 1 there are 9x2 ways(w1)
for 2 its 8x2 (say w(2)
for 3 its 7x2
.
for 9 its 1x2(w9)
let w(i) represents the number of ways to get abs diff of i.
So total numbers that are possible from the given abs diff   i j k l m ...
(w(i) x w(j) x w(k) x w(l) x.)

Now algo will be to scan the given abs diff and multiply the w(i) for each
absdiff .

int calculate_possible_nums(int absdiff[], int len){
int ways[]={10, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1};
int numways=1;
for ( i=0; i < len; i++){
 numways = numways * ways[absdiff[i]];
}
 return numways;
}
-Moheed
'If a man neglects education, he walks lame to the end of his life.'



On Tue, Dec 13, 2011 at 11:20 PM, Don  wrote:

> There should be 39 combinations with that input. You are missing
> numbers which include the digit zero, such as 14610, 30278, and 52056.
>
> Don
>
> On Dec 13, 11:37 am, tech coder  wrote:
> > I tried the problem and written the code for it . it is in java. it is
> > printing all the possible numbers
> > I  am treating the differences ans an array of integers.
> >
> > here is the code
> >
> > public class Main {
> >
> > public static void main(String[] args)
> > {
> >int digit[]={3,2,5,1};// array of absolute differences
> >
> > int digit[]={3,2,5,1};
> >for(int num=1;num<=9;num++) // call with all possible initial
> > numbers
> >findNumber(digit,4,num,0,num);
> > }
> >
> > public static void findNumber(int digit[],int n,int num,int i,int
> > oldDigit)
> > {
> > if(i==n)
> > {
> > System.out.print(num+"  ");
> > return;
> > }
> >
> > {
> > int o=digit[i]+oldDigit;
> > if(o<10)
> > findNumber(digit,n,10*num+o,i+1,o);
> > o=oldDigit-digit[i];
> > if(o>0)
> > findNumber(digit,n,10*num+o,i+1,o);
> >
> > }
> > }
> >
> > }
> >
> > and here is the output
> >
> > 14612  14278  14276  25723  25721  25389  25387  36834  36832  36498
>  47945
> >  47943  41389  41387  58612  52498  69723  69721  63167  63165  74612
> >  74278  74276  85723  85721  85389  85387  96834  96832  96498
> > BUILD SUCCESSFUL (total time: 0 seconds)
> >
> >
> >
> > On Tue, Dec 13, 2011 at 11:11 PM, Dave  wrote:
> > > @Amir: Presumably, since these are digits in a number, they are
> > > bounded on the bottom by 0 and on the top by radix-1. So in decimal,
> > > if a digit is 7 and the absolute difference between it and the next
> > > digit is 3, there is only one possibility for the next digit, 7-3 = 4,
> > > since 7+3 is too large. So only some subset of the 2^(n-1)
> > > combinations of addition and subtraction may be possible.
> >
> > > Dave
> >
> > > On Dec 13, 4:15 am, Amir hossein Shahriari
> > >  wrote:
> > > > actually there are infinite number of sequences that match it
> > > > for example if the absolute differences are 3 2 5 1
> > > > one possible sequence is 6 3 5 0 1 one other is 7 4 6 1 2 or 8 5 7 2
> 3
> > > > and you can add any integer value to all elements and the result will
> > > still
> > > > be valid
> > > > actually you can start with any number and and then the second number
> > > will
> > > > be equal to the first number that you chose plus/minus the first
> absolute
> > > > difference and so on
> >
> > > > so if we are given the first element of the sequence there are
> 2^(n-1)
> > > ways
> > > > to find a valid sequence because for each absolute difference we can
> > > either
> > > > add the absolute difference to the last sequence element or subtract
> the
> > > > absolute difference from it
> >
> > > > On Mon, Dec 12, 2011 at 9:01 PM, KAY 
> > > wrote:
> > > > > If for a number n digits long, the absolute difference between
> > > > > adjacent digits is given, how to find out the number of different
> > > > > numbers with these absolute differences ?
> >
> > > > > for eg,
> > > > > if n=5
> > > > > and the absolute differences are
> > > > > 3 2 5 1
> > > > > then 1 possible number is
> > > > > 6 3 5 0 1(because |6-3|=3,|3-5|=2 and so on...)
> >
> > > > > How many such numbers will be there?
> >
> > > > > --
> > > > > 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, visi