Re: [algogeeks] ds

2010-06-07 Thread sharad kumar
@ anand all input is in 1 array n in ur approach u hve used   2 arrays ,bt
 that is not d ques

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



Re: [algogeeks] ds

2010-06-07 Thread Anurag Sharma
@anand. Perhaps, its not correct. Does not work for larger inputs.

Anurag Sharma


On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:

 Here  is my approach is o(n).
 http://codepad.org/YAFfZpxO

 http://codepad.org/YAFfZpxO

 On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote:



 this is ques by adobe and they want inplace soln..

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



Re: [algogeeks] divisible by 3

2010-06-07 Thread jaladhi dave
how abt using FSA ?

consider state as a remainder when the given no. is divided by 3.

Then we get a FSA for any length no. as

  [image: fsa.JPG]










On Sun, Jun 6, 2010 at 12:15 AM, divya sweetdivya@gmail.com wrote:

 Find if a number is divisible my 3, without using %,/ or *. You can
 use atoi().

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

fsa.JPG

[algogeeks] Re: array question

2010-06-07 Thread souravsain
@Anand: Your solution will take huge space and can easily be made to
run out of memory!
If arr5[] = {12,12,6,6,635}, you will run into n^3 space complexity.
For arr[5]={12,12,6,6,390625} it will be n^6.

Sain


On Jun 7, 3:27 am, Anand anandut2...@gmail.com wrote:
 Here is my approch which runs in O(n).

 http://codepad.org/d3pzYQtW
 http://codepad.org/d3pzYQtW



 On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.com wrote:
  output willl be 12 12 5 6 6

  On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote:

  @divya: Does your problem require the output to be sorted also? What
  will be the output required if inout is 12,5,6,12,6? Will it be
  12,12,6,6,5 or 12,12,5,6,6,?

  Sain

  On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote:
   Given an array with some repeating numbers. Like 12,6,5,12,6

   output: 12,12,6,6,5
   12 shud come before 6 since it is earlier in list. So cant use a
   dictionary

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



Re: [algogeeks] Re: divisible by 3

2010-06-07 Thread Sundeep Singh
@Anand and @Minotaurus
The code seems to fail for 15.

Am I missing something?


On Mon, Jun 7, 2010 at 2:20 AM, Minotauraus anike...@gmail.com wrote:

 @Anand: Thanks for the code. I knew you could do it by bit
 shifting. :-)

 On Jun 5, 10:21 pm, Anand anandut2...@gmail.com wrote:
  Here is a code for it.http://codepad.org/umkh3pjf
 
 
 
  On Sat, Jun 5, 2010 at 7:14 PM, Minotauraus anike...@gmail.com wrote:
   Subtract 3 from the number until either you get 0 or a negative
   number. If you get 0, its divisible, else not.
   You can probably do this by bit shifting too.
 
   On Jun 5, 11:45 am, divya sweetdivya@gmail.com wrote:
Find if a number is divisible my 3, without using %,/ or *. You can
use atoi().
 
   --
   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
 algogeeks%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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Puzzle:

2010-06-07 Thread sharad
: Three containers are of 15,10 and 6 ltrs capacity. Initially its in
configuration (15,0,0). Make it to configuration (2,8,5)

-- 
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] Pointer to a constant

2010-06-07 Thread Raj N
Can someone tell me the difference between
1) const int i=5; 2)  int i=5;
   int *ptr=i;  const int
*ptr=i;

In the first case i can be modified via ptr i.e *ptr++ is valid. In
the second case *ptr++ is illegal. Why is that so? Aren't they same?

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



Re: [algogeeks] ds

2010-06-07 Thread Raj N
@sain: But the question demands O(n) time

On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:

 Here  is my approach is o(n).
 http://codepad.org/YAFfZpxO

 http://codepad.org/YAFfZpxO

 On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote:



 this is ques by adobe and they want inplace soln..

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



Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
Ok this is just counting now how to do the same to print all possibilities?

On Mon, Jun 7, 2010 at 1:14 PM, Raj N rajn...@gmail.com wrote:

 @Dave: Hey i'm finding little difficulty in understanding the 3rd condition

- p(*k*,*n*) = 0 if *k*  *n*

- p(*k*,*n*) = 1 if *k* = *n*


- p(*k*+1,*n*)+p(*k*,*n*-*k*) otherwise

 Can you explain me p(k+1,n) partition. I understood p(k,n-k)


 On Mon, Jun 7, 2010 at 6:16 AM, Dave dave_and_da...@juno.com wrote:

 In number theory, a partition of a positive integer n is a way of
 writing n as a sum of positive integers. Two sums that differ only in
 the order of their summands are considered to be the same partition;
 if order matters then the sum becomes a composition. The number of
 partitions of n is given by the partition function p(n). You can
 compute p(n) recursively. See
 http://en.wikipedia.org/wiki/Partition_(number_theory)http://en.wikipedia.org/wiki/Partition_%28number_theory%29
 .

 Dave

 On Jun 6, 2:05 pm, Raj N rajn...@gmail.com wrote:
  How do you count the number of ways a number can be expressed as a sum
  of 2 or more numbers?
  For eg. if the number is 5 , count=3 i.e 1+1+1+1+1, 4+1, 3+2
  note 2+3 is same as 3+2

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



Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
@Dave: Hey i'm finding little difficulty in understanding the 3rd condition

   - p(*k*,*n*) = 0 if *k*  *n*

   - p(*k*,*n*) = 1 if *k* = *n*


   - p(*k*+1,*n*)+p(*k*,*n*-*k*) otherwise

Can you explain me p(k+1,n) partition. I understood p(k,n-k)


On Mon, Jun 7, 2010 at 6:16 AM, Dave dave_and_da...@juno.com wrote:

 In number theory, a partition of a positive integer n is a way of
 writing n as a sum of positive integers. Two sums that differ only in
 the order of their summands are considered to be the same partition;
 if order matters then the sum becomes a composition. The number of
 partitions of n is given by the partition function p(n). You can
 compute p(n) recursively. See
 http://en.wikipedia.org/wiki/Partition_(number_theory)http://en.wikipedia.org/wiki/Partition_%28number_theory%29
 .

 Dave

 On Jun 6, 2:05 pm, Raj N rajn...@gmail.com wrote:
  How do you count the number of ways a number can be expressed as a sum
  of 2 or more numbers?
  For eg. if the number is 5 , count=3 i.e 1+1+1+1+1, 4+1, 3+2
  note 2+3 is same as 3+2

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



Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
@Dave: Thanks it really helped !!

On Mon, Jun 7, 2010 at 6:16 AM, Dave dave_and_da...@juno.com wrote:

 In number theory, a partition of a positive integer n is a way of
 writing n as a sum of positive integers. Two sums that differ only in
 the order of their summands are considered to be the same partition;
 if order matters then the sum becomes a composition. The number of
 partitions of n is given by the partition function p(n). You can
 compute p(n) recursively. See
 http://en.wikipedia.org/wiki/Partition_(number_theory)http://en.wikipedia.org/wiki/Partition_%28number_theory%29
 .

 Dave

 On Jun 6, 2:05 pm, Raj N rajn...@gmail.com wrote:
  How do you count the number of ways a number can be expressed as a sum
  of 2 or more numbers?
  For eg. if the number is 5 , count=3 i.e 1+1+1+1+1, 4+1, 3+2
  note 2+3 is same as 3+2

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



Re: [algogeeks] Explain the output

2010-06-07 Thread Jitendra Kushwaha
changing vfork with fork gives the correct output but in case of vfork the
loop behaviour is unpredictable

@harit : I guess the child is simply reading the value of i from the same
data area of the parent.
First time it showed a garbage, after which it shows the value
inputted in the parent.

If i am not wrong the child uses text and data area of parent till a exec is
not been called in the child.
Here in the program parent and child are  not doing any tweak with the text
area then how can we explain the loop behaviour of the program.

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



Re: [algogeeks] Re: array question

2010-06-07 Thread Raj N
@Anand :Your approach will turn out very crude if elements are something
like 1000, 2000
keeping an array i.e count[1000] is not feasible. I think souravsain's
approach is better.

On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote:

 Here is my approch which runs in O(n).

 http://codepad.org/d3pzYQtW
 http://codepad.org/d3pzYQtW

 On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.comwrote:

 output willl be 12 12 5 6 6


 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote:

 @divya: Does your problem require the output to be sorted also? What
 will be the output required if inout is 12,5,6,12,6? Will it be
 12,12,6,6,5 or 12,12,5,6,6,?

 Sain

 On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote:
  Given an array with some repeating numbers. Like 12,6,5,12,6
 
  output: 12,12,6,6,5
  12 shud come before 6 since it is earlier in list. So cant use a
  dictionary

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


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



Re: [algogeeks] Re: sorted 2-d array

2010-06-07 Thread Senthilnathan Maadasamy
We can do it in O(n * log n) by individually binary-searching for zero on
each of the rows.  Once we get the index of the first position where zero
appears, counting the number of negative number is straight-forward.

Here is an even better O(N) algorithm which is very elegant:
Consider the bottom-left element of the given 2-D array.
If it is negative, the whole of first-column is negative.  So we can add
that count and ignore that column from then onwards.
If it is non-negative, the whole of last-row is non-negative.  So we can
ignore that row without changing the count.
Therefore, by just doing one comparison we are able to eliminate one row
or one column.
We can iteratively follow this approach and it will terminate in exactly 2*N
steps.

-- 
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] constraints satisfied?

2010-06-07 Thread divya
Here's a problem that occurs in automatic program analysis. For a set
of variables x1; .. ; xn, you are given some equality constraints,
of the form xi = xj and some dis equality constraints, of the form
xi != xj Is it possible to satisfy all of them? Give an efficient
algorithm that takes as input m constraints over n variables and
decides whether the constraints can be satisfied.

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



Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-07 Thread saurabh gupta
it might be referring to no of sequences (say T(n) ) with no consecutive 1's
for n = 3, ans would be 5 viz.
000, 001, 010, 100, 101

T(n) =  fib(n+2)
where fib = Fibonacci series
which is interesting.

On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote:

 @sharad: What about 101 even it doesn't have two 1's in a row


 On Sat, Jun 5, 2010 at 8:59 AM, sharad kumar aryansmit3...@gmail.comwrote:

 @rajn.can it be subsequence doesnt have one's too.hence 000,001,010,100 is
 required answer.


 On Sat, Jun 5, 2010 at 12:13 AM, Raj N rajn...@gmail.com wrote:

 Hi,
 I came across this question to find the number of sequences of n
 binary digits that don't contain 2 1's in a row. I wanted to know what
 exactly this means. Is it like if n=3 then compute all binary numbers
 having 3 digits which don't have consecutive 1's 110, 011, 111 ??
 If not help me understanding it.
 Thanks!!

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




 --
 yezhu malai vaasa venkataramana Govinda Govinda

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




-- 
Man goes to doctor. Says he's depressed. Says life seems harsh and cruel.
Says he feels all alone in a threatening world where what lies ahead is
vague and uncertain. Doctor says Treatment is simple. Great clown
Pagliacci is in town tonight. Go and see him. That should pick you up. Man
bursts into tears. Says But, doctor...I am Pagliacci.

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



Re: [algogeeks] Re: array question

2010-06-07 Thread Dheeraj Jain
The link http://geeksforgeeks.org/?p=1488 has many different solutions and
implementation of hashing method.

On Mon, Jun 7, 2010 at 12:59 AM, Raj N rajn...@gmail.com wrote:

 @Anand :Your approach will turn out very crude if elements are something
 like 1000, 2000
 keeping an array i.e count[1000] is not feasible. I think souravsain's
 approach is better.


 On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote:

 Here is my approch which runs in O(n).

 http://codepad.org/d3pzYQtW
  http://codepad.org/d3pzYQtW

 On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.comwrote:

 output willl be 12 12 5 6 6


 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote:

 @divya: Does your problem require the output to be sorted also? What
 will be the output required if inout is 12,5,6,12,6? Will it be
 12,12,6,6,5 or 12,12,5,6,6,?

 Sain

 On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote:
  Given an array with some repeating numbers. Like 12,6,5,12,6
 
  output: 12,12,6,6,5
  12 shud come before 6 since it is earlier in list. So cant use a
  dictionary

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


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



Re: [algogeeks] matix flipping

2010-06-07 Thread Amit Jaspal
#includeiostream
using namespace std;
int main(){
int a[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
int i=0,j,n=3,l=0,m=n;
j=n;

while(i=n){
int i1=i,j1=j,k=0,l=n;
for(;kj1;i1++,j1--){
swap(a[k][i1],a[j1][l]);
if(i!=0){
swap(a[i1][k],a[l][j1]);
}
k++;
l--;
}
i++;
j--;
}

for(i=0;i4;i++){
for(j=0;j4;j++){
couta[i][j] ;
}
coutendl;
}

return 0;
}

On Mon, Jun 7, 2010 at 8:26 AM, sharad sharad20073...@gmail.com wrote:

 write a c routine to flip an nXn matrix about its non major diagnol


 3   4   5
 6   7   9
 1   2   8

 Transpose is:
 8   9   5
 2   7   4
 1   6   3

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



Re: [algogeeks] ds

2010-06-07 Thread vadivel selvaraj
Hi guys d soln z quite easy by swapping the variables..
consider a1a2a3a4b1b2b3b4
In the first iteration, swap (a2,b1),(a4,b3) giving a1b1a3b3a2b2a4b4
In the second iteration, swap (a3b3,a2b2) which gives d soln...
a1b1a2b2a3b3a4b4...

Any comments on dis??



On Mon, Jun 7, 2010 at 1:51 PM, Raj N rajn...@gmail.com wrote:

 @sain: But the question demands O(n) time

 On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:

 Here  is my approach is o(n).
 http://codepad.org/YAFfZpxO

 http://codepad.org/YAFfZpxO

 On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote:



 this is ques by adobe and they want inplace soln..

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




-- 
Simplicity is prerequisite for reliability.
– Edsger W. Dijkstra

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



Re: [algogeeks] matix flipping

2010-06-07 Thread mohit ranjan
@Sharad,

3   4   5
 A=   6   7   9
1   2   8


If B[i,j] = A[n-j, n-i]

then
---
   8   9   5
B =  2   7   4
   1   6   3


Mohit Ranjan


On Mon, Jun 7, 2010 at 8:26 AM, sharad sharad20073...@gmail.com wrote:

 write a c routine to flip an nXn matrix about its non major diagnol


 3   4   5
 6   7   9
 1   2   8

 Transpose is:
 8   9   5
 2   7   4
 1   6   3

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



Re: [algogeeks] Puzzle:

2010-06-07 Thread mohit ranjan
is it possible ?

if we say nth state is [2, 8, 5]

I could not find possible (n-1)th state


Mohit Ranjan


On Mon, Jun 7, 2010 at 2:02 PM, sharad sharad20073...@gmail.com wrote:

 : Three containers are of 15,10 and 6 ltrs capacity. Initially its in
 configuration (15,0,0). Make it to configuration (2,8,5)

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



[algogeeks] Knapsack - 0-1 - Brute force

2010-06-07 Thread Jean Carlo Mendes
Hello Guys

 

Anyone have a implementation of knapsack 0-1 using brute force approach ?

Or. Do you have some link with a sample in C language?

 

Thanks

 

jean

-- 
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] min no of policemen

2010-06-07 Thread divya
consider a tree. policemen is to be placed such that for each edge of
tree, there is a policeman on atleast one side of each edge. tell the
min no. of policemen and their locatn in time O(n)

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



Re: [algogeeks] matix flipping

2010-06-07 Thread divya jain
let a[n][n] be the input array nd b[][] be the output

for(i=0;in;i++)
 for(j=0;jn;j++)
 b[i][j]=a[n-j-1][n-i-1]


On 7 June 2010 08:26, sharad sharad20073...@gmail.com wrote:

 write a c routine to flip an nXn matrix about its non major diagnol


 3   4   5
 6   7   9
 1   2   8

 Transpose is:
 8   9   5
 2   7   4
 1   6   3

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



Re: [algogeeks] Re: divisible by 3

2010-06-07 Thread Anand
Here is another approach.
Example: 23 (00..10111)
1) Get count of all set bits at odd positions (For 23 it’s 3).
2) Get count of all set bits at even positions (For 23 it’s 1).
3) If difference of above two counts is a multiple of 3 then number is also
a multiple of 3.

(For 23 it’s 2 so 23 is not a multiple of 3)
Code for it:
http://codepad.org/eKI8ggs4



On Mon, Jun 7, 2010 at 1:12 AM, Raj N rajn...@gmail.com wrote:

 Dave's logic is working fine.


 On Mon, Jun 7, 2010 at 1:35 PM, Raj N rajn...@gmail.com wrote:

 @Anand: The code you've sent is not correct. It doesn't work for numbers
 15,12 etc.


 On Mon, Jun 7, 2010 at 2:20 AM, Minotauraus anike...@gmail.com wrote:

 @Anand: Thanks for the code. I knew you could do it by bit
 shifting. :-)

 On Jun 5, 10:21 pm, Anand anandut2...@gmail.com wrote:
  Here is a code for it.http://codepad.org/umkh3pjf
 
 
 
  On Sat, Jun 5, 2010 at 7:14 PM, Minotauraus anike...@gmail.com
 wrote:
   Subtract 3 from the number until either you get 0 or a negative
   number. If you get 0, its divisible, else not.
   You can probably do this by bit shifting too.
 
   On Jun 5, 11:45 am, divya sweetdivya@gmail.com wrote:
Find if a number is divisible my 3, without using %,/ or *. You can
use atoi().
 
   --
   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
 algogeeks%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.


-- 
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] circularly sorted array

2010-06-07 Thread divya
u r given  a circularly sorted array of n integers ie the array was
1st sorted nd then left or right shifted any no. of times. search for
a given integer k in the array in O(logn) time

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



Re: [algogeeks] Pointer to a constant

2010-06-07 Thread mohit ranjan
@Raj,

no they are not same


case 1: i is const
case 2: ptr is const

and whatever is const cann't be modified

Mohit Ranjan


On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:

 Can someone tell me the difference between
 1) const int i=5; 2)  int i=5;
   int *ptr=i;  const int
 *ptr=i;

 In the first case i can be modified via ptr i.e *ptr++ is valid. In
 the second case *ptr++ is illegal. Why is that so? Aren't they same?

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



[algogeeks] binary nos

2010-06-07 Thread divya
write an efficient algo to compute no. of sequences of n binary digits
that do not contain 2 1's in a row. eg 111 is invalid whereas
1001001 is valid..

-- 
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] Veer: Kth element in binary tree

2010-06-07 Thread Veer Sharma
Given a Binary Search Tree, write a program to print the kth smallest
element without using any static/global variable. You can’t
pass the value k to any function also

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



Re: [algogeeks] Pointer to a constant

2010-06-07 Thread Raj N
1) const int i=5;2)  int i=5;
  int *ptr=i;  const
int*ptr=i;


On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:

 Can someone tell me the difference between
 1) const int i=5; 2)  int i=5;
   int *ptr=i;  const int*ptr=i;

 In the first case i can be modified via ptr i.e *ptr++ is valid. In
 the second case *ptr++ is illegal. Why is that so? Aren't they same?

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



Re: [algogeeks] Re: array question

2010-06-07 Thread Anand
@souravsain :Your approach works really well..

Here is the Implementation:
http://codepad.org/ricAcQtu



On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote:

 @divya:go through the elements and keep inserting them in a BST. While
 inserting if elements already exists in BST, increase its frequency
 (Node of BST has element a nd frequency). Also if elemengs is newly
 inserted then also place it in a seperate array. So this array (say
 Array M) will become something like 12,5,6. This array will give order
 of first occurance of numbers. This whole process will take nlogn (BST
 creation assuming worst case that all elements are uinque in the input
 array).

 Once done, scan through each element in array M, find its
 corrosponding element in BST (logn) which will give the frequency.
 Fill those many indexes in input array with array M[i]. If all
 elements are uinque, this will also take nlogn. Else if input array
 has m distince elements, which will require us to look into BST for m
 times.

 hence entire process has time compelxity: O(nlogn + nlogn)= O(2nlogn)
 Space complexity: O(2n) [1 for BST and 1 for array M, worst case when
 all elements are unique in inpur array).

 Let me know your comments if any or any better appraoch as this once
 may have improvements.

 On Jun 6, 7:47 pm, divya jain sweetdivya@gmail.com wrote:
  output willl be 12 12 5 6 6
 
  On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote:
 
 
 
   @divya: Does your problem require the output to be sorted also? What
   will be the output required if inout is 12,5,6,12,6? Will it be
   12,12,6,6,5 or 12,12,5,6,6,?
 
   Sain
 
   On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote:
Given an array with some repeating numbers. Like 12,6,5,12,6
 
output: 12,12,6,6,5
12 shud come before 6 since it is earlier in list. So cant use a
dictionary
 
   --
   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
 algogeeks%2bunsubscr...@googlegroups­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- 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.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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] binary nos

2010-06-07 Thread Rohit Saraf
So u want efficient algo for fibonacci numbers?

-- 
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

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



Re: [algogeeks] constraints satisfied?

2010-06-07 Thread Rohit Saraf
A simple solution :

Use the union find data structure and add notes for x1...xn and the negation
of all these.
Every constraint makes one union.

Finally check if for any i , xi and !xi are connected.

It is worst case O(n lg n) for sure where n is the number of equations.
Average case is much better.

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

-- 
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: binary nos

2010-06-07 Thread Dave
Hmmm. The first few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21,
34, 55, ...
Of these, 3, 13, and 55 have binary representations with two 1-bits in
a row.
And 9, 10, 17, 18, etc are not included. So what was your question?

Dave

On Jun 7, 9:28 pm, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
 So u want efficient algo for fibonacci numbers?

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14

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



Re: [algogeeks] Re: array question

2010-06-07 Thread Mayur
@Anand
Depending upon the sequence of data in the input, an insertion/search into
the (unbalanced) BST will take O(n) time causing the overall complexity to
shoot up to O(n^2) for each element counted once. Sourav's approach requires
a balanced binary search tree.


@Divya..
If you know something about the numbers, one could do better. For example,
if you knew that they're all positive short integers, Anand's original
approach (of using an array indexed by the numbers themselves) will be great
(for a storage cost of about 64KB). This is sometimes more acceptable, for
example, if your original input is like a million integers.








On Tue, Jun 8, 2010 at 5:48 AM, Anand anandut2...@gmail.com wrote:

 @souravsain :Your approach works really well..

 Here is the Implementation:
 http://codepad.org/ricAcQtu



 On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote:

 @divya:go through the elements and keep inserting them in a BST. While
 inserting if elements already exists in BST, increase its frequency
 (Node of BST has element a nd frequency). Also if elemengs is newly
 inserted then also place it in a seperate array. So this array (say
 Array M) will become something like 12,5,6. This array will give order
 of first occurance of numbers. This whole process will take nlogn (BST
 creation assuming worst case that all elements are uinque in the input
 array).

 Once done, scan through each element in array M, find its
 corrosponding element in BST (logn) which will give the frequency.
 Fill those many indexes in input array with array M[i]. If all
 elements are uinque, this will also take nlogn. Else if input array
 has m distince elements, which will require us to look into BST for m
 times.

 hence entire process has time compelxity: O(nlogn + nlogn)= O(2nlogn)
 Space complexity: O(2n) [1 for BST and 1 for array M, worst case when
 all elements are unique in inpur array).

 Let me know your comments if any or any better appraoch as this once
 may have improvements.

 On Jun 6, 7:47 pm, divya jain sweetdivya@gmail.com wrote:
  output willl be 12 12 5 6 6
 
  On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote:
 
 
 
   @divya: Does your problem require the output to be sorted also? What
   will be the output required if inout is 12,5,6,12,6? Will it be
   12,12,6,6,5 or 12,12,5,6,6,?
 
   Sain
 
   On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote:
Given an array with some repeating numbers. Like 12,6,5,12,6
 
output: 12,12,6,6,5
12 shud come before 6 since it is earlier in list. So cant use a
dictionary
 
   --
   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
 algogeeks%2bunsubscr...@googlegroups­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- 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.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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: binary nos

2010-06-07 Thread Rohit Saraf
getting fibonacci nos is trivial using matrix multiplication in almost
constant time.

--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

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



Re: [algogeeks] ds

2010-06-07 Thread Rohit Saraf
Of course you should do it via swappings.. why would one think of anything
else :)
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Mon, Jun 7, 2010 at 10:39 PM, vadivel selvaraj gct.vadi...@gmail.comwrote:

 Hi guys d soln z quite easy by swapping the variables..
 consider a1a2a3a4b1b2b3b4
 In the first iteration, swap (a2,b1),(a4,b3) giving a1b1a3b3a2b2a4b4
 In the second iteration, swap (a3b3,a2b2) which gives d soln...
 a1b1a2b2a3b3a4b4...

 Any comments on dis??




 On Mon, Jun 7, 2010 at 1:51 PM, Raj N rajn...@gmail.com wrote:

 @sain: But the question demands O(n) time

 On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:

 Here  is my approach is o(n).
 http://codepad.org/YAFfZpxO

 http://codepad.org/YAFfZpxO

 On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar 
 sharad20073...@gmail.comwrote:



 this is ques by adobe and they want inplace soln..

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




 --
 Simplicity is prerequisite for reliability.
 – Edsger W. Dijkstra

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