Use the quicksort algorithm: Set the swap counter to 0. Search from the
beginning of the array for the first 0, and from the end of the array for
the first 1. If the pointers cross, you are done; otherwise increment the
swap counter and continue the searches.
On Tuesday, March 29, 2016 at
needs to calculate mod((2^N)!,17) (! is the factorial symbol).
Dave
On Monday, October 5, 2015 at 10:48:11 PM UTC-5, gopi wrote:
> Little Black Panda is mad about XOR operation. Presently he has gone mad
> and he won't stop performing XOR operation on various numbers.
> Given
or via
another path on this move. Continue this way until either you reach the
solution state or you are not able to find any previously unreached
positions. In the former case, you have determined the minimum number of
moves to solve the puzzle. In the latter case, there is no solution.
Dave
terms. There are some obvious optimizations.
Dave
On Tuesday, April 8, 2014 1:06:47 PM UTC-5, kumar raja wrote:
Hi all,
I know the way to calculate value of C(n,r) using pascals identity. But i
have a different requirement.
C(n,r) = n (n-1) (n-2) ... (n-r+1) / r!
Suppose the numerator
See http://en.wikipedia.org/wiki/Partition_(number_theory).
On Saturday, March 1, 2014 10:25:57 AM UTC-6, kumar raja wrote:
Given an integer how many number of ways u can partition the number?
e.g. 3 can be written as 3,1+2,1+1+1
and 4 can be written as 4, 1+1+1+1,2+2,1+3,1+1+2
So
@Kumar: As a point of interest, the number of valid sequences of n pushes
and n pops is C(3), the third Catalan Number. See, e.g.,
http://en.wikipedia.org/wiki/Catalan_number for details.
Dave
On Thursday, February 20, 2014 12:27:35 PM UTC-6, kumar raja wrote:
Hi all,
Here
@Saurabh: No. It represents an equation with no solutions. (x - 7) + 7 =
(x + 1) - 5 reduces algebraically to 0 = -4. Since there are no values
of x for which this is a true statement, there are no solutions.
Dave
On Monday, January 27, 2014 5:32:19 AM UTC-6, Saurabh Singh_cse_20094016
wrote
this condition with k = (m+n)/2, you have to determine if a[i] or b[k-i-1]
is the final answer. The complexity is O(log m).
Dave
On Sunday, January 5, 2014 5:34:12 AM UTC-6, Sanjay Rajpal wrote:
Hi guys,
Please help me in finding median of two sorted arrays of length m and n in
minimum possible
@Don: Excellent solution. It requires little extra data to be stored, and
it is easy to implement.
Dave
On Wednesday, November 13, 2013 9:31:47 AM UTC-6, Don wrote:
The data file contains the pre-order traversal. For each node indicate the
contents of the node and two bits to indicate
See, e.g.,
http://en.wikipedia.org/wiki/Random_number_generation#Computational_methods.
The algorithm creates a 32-bit random integer. It can be reduced to the
range 0 to N with the modulus operator.
Dave
On Thursday, October 10, 2013 4:51:42 AM UTC-5, atul007 wrote:
Hello,
Given
space and O(log S) time.
Dave
On Tuesday, October 8, 2013 9:48:58 AM UTC-5, Don wrote:
Provide a function which returns a value randomly and uniformly selected
from the range 0..N-1 excluding values in the array a[S] containing sorted
values in the same range. A rejection algorithm would
they won't gain much from copying.
Probably not the solution you were looking for, but I think an effective
one.
Dave
On Saturday, July 27, 2013 1:02:11 PM UTC-5, enchantress wrote:
Given m*n matrix and k students how can they be placed such that cheatig
is minimised.
--
You received
algorithm.
Dave
On Tuesday, July 16, 2013 10:40:29 AM UTC-5, Don wrote:
It definitely complicates things. I think that I would replaced the vector
parameters with pointers to the beginning and end of each array. The
partition is tricky because you need to make sure that both subtrees end up
The highest remainder when dividing n by a number less than n is
floor((n-1)/2).
For n = 11, floor((11-1)/2) = floor(10/2) = floor(5) = 5.
For n = 17, floor((17-1)/2) = 8
For n = 23, floor((23-1)/2) = 11
For n = 12, floor((12-1)/2) = floor(11/2) = floor(5.5) = 5.
Etc.
Dave
On Wednesday
. The
conditions above are satisfied, so the greedy algorithm works.
E.g., The greedy algorithm does not work with a coin system with 1, 4, and
5 unit coins. 8 units can be made with two 4-unit coins, but the greedy
algorithm uses 5, 1, 1, and 1.
Dave
On Tuesday, May 28, 2013 9:55:01 AM UTC-5, Don wrote
@Pankaj: Can you give more details of your algorithm, including the big-O
order of time and space. It certainly is not difficult to do it in O(n log
n) time and O(n) space, as this can be accomplished by a merge-sort. For
fixed data size, O(n) time and O(n) space can be achieved by a radix
Oops. The statement int I = 1 in the above should be int k = 1. Sorry.
Dave
On Sunday, May 5, 2013 9:10:37 PM UTC-5, Dave wrote:
@Nishant: I'm assuming that you don't know the number of words in the
file, and that you don't want to store them all. Here is an algorithm that
requires you
the desired result.
Dave
On Sunday, May 5, 2013 7:44:01 AM UTC-5, Nishant Pandey wrote:
Hi Guys,
In this problem i am wondering how it will be done without extra memory
space, though we can easily do it with hashing and random funcs().
Is there any solution for this , Please help.
--
You
of n1 is the least common ancestor.
It seems that common usage is that a node is its own ancestor; see, e.g.,
http://en.wikipedia.org/wiki/Lowest_common_ancestor.
Dave
On Sunday, April 21, 2013 11:56:01 AM UTC-5, rahul sharma wrote:
int leastCommanAncestor(struct node* root, int n1, int n2
,
giving {4,4,2,2,6,6,3,5}.
Dave
On Wednesday, February 1, 2012 2:58:43 AM UTC-6, Varun wrote:
I was asked this question sometime during an interview.
WE have an array of known length. The elements in array can be repetitive.
now sort the array based on frequency of occurrence of each
it in
fractional form, and if the denominator is negative, then negate both
numerator and denominator. Then divide both numerator and denominator by
their gcd. Finally, if the denominator is 1, report the numerator as the
answer; otherwise report the fraction numerator/denominator as the answer.
Dave
track of
the state, as recursion won't allow you to do them.
Dave
On Tuesday, March 5, 2013 1:54:30 AM UTC-6, marti wrote:
Given a value , print two nodes that sum to the value in a BST and normal
tree.. time:O(n), space O(logn).
--
You received this message because you are subscribed
@Maddy: I'm a little confused because there are 8 coins in the bag but 3 +
3 + 2 + 2 = 10 coins are grouped by weight.
Dave
On Friday, March 1, 2013 1:15:03 PM UTC-6, maddy wrote:
There are 8 coins in a bag .
3 coin weights x kg
3 coins weights y kg
2 coins weights z kg
2 coins
@Marti: If you know m and k, and if m is even and k is odd, then xoring the
elements of the array will give the integer that occurs k times. But this
is not a general algorithm for arbitrary m and k.
Dave
On Sunday, February 24, 2013 1:24:23 AM UTC-6, marti wrote:
A hint is to use XOR
@Gaurav: Does it work for n = 25 or for n = 8? I think you've confused
perfect square with power of two.
Dave
On Wednesday, February 6, 2013 11:32:55 PM UTC-6, Gaurav Rana wrote:
if(n(n-1)==0)
//perfect square
On Thu, Feb 7, 2013 at 3:01 AM, Don dond...@gmail.com javascript:wrote
Does anyone have any ideas about how to generate mazes? I'd like an
algorithm that can make many different mazes, maybe using a random number
generator. Each maze should be guaranteed to have one and only one solution.
--
You received this message because you are subscribed to the Google
@Koup: No, I meant O(n^3 log k). Sorry.
Dave
On Sunday, January 20, 2013 3:09:00 AM UTC-6, Koup wrote:
I need to multiply an array A by it self. Is there an algorithm that does
array multiplication with complexity O(n^2)?Doesn't it take at least O(n^3)?
On Sun, Jan 20, 2013 at 12:44 AM
@Shady: See http://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm.
Dave
On Sunday, January 20, 2013 10:02:19 AM UTC-6, shady wrote:
How to check if polygon is simple based on given list of points ?
--
,
it may be cheaper to use matrix-vector multiplication k times; this will be
O(n^2 * k).
Dave
On Saturday, January 19, 2013 7:30:50 AM UTC-6, Guneesh wrote:
both recursive and iterative codes are O(nlogn) algos..
but memory will be more in recursion..
so we will prefer iteration
--
;
}
return ans;
}
Dave
On Saturday, January 19, 2013 5:06:25 AM UTC-6, Guneesh wrote:
consider code to find n^k where n is an integer
int power()
{
int ans=1,val=1;
while(k)
{
val=val*n;
if(k1)ans=ans*val;
k=k1;
}
return ans;
}
now if n is is a matrix all you have to do is replace
)-by-3 array, in-place. For algorithms, google in situ
matrix transposition and in place matrix transposition. I'm not sure
that an O(n)-time algorithm exists.
Dave
On Tuesday, January 15, 2013 2:08:15 PM UTC-6, pralaybi...@gmail.com wrote:
Hi,
You could try something like this.
[image
should get e(n+1) = e(n)^2 / (2*(e(n) + sqrt(a))). You can then observe
that if x(0) 0, then e(1) = 0, and if e(n) 0 then 0 e(n+1) e(n) /
2, proving convergence. You can further observe that if e(n) is small,
then convergence is quadratic: e(n+1) = O(e(n)^2).
Dave
On Monday, January 14, 2013 2
.
If the output array is empty, or if the outputted heap top is different
from the last element in the output array,
then insert the outputted heap top into the output array.
Complexity is m*n*log(m).
Dave
On Tuesday, January 8, 2013 11:59:55 AM UTC-6, Ravi Ranjan wrote:
You have a two
@Don: You did, of course, see the OP's revision in
https://groups.google.com/d/msg/algogeeks/Be3WBebCDCk/_Mb0HUQ93WoJ, did you
not?
Dave
On Thursday, January 3, 2013 3:08:40 PM UTC-6, Don wrote:
The spec says that the list is infinite, so I don't think that is
possible in finite time
@Don: HaHa. That's cute, but don't you really think the problem is to
return any node in the list with equal probability?
Dave
On Wednesday, January 2, 2013 4:48:15 PM UTC-6, Don wrote:
Why not just return the first node? That is as random as any other
node.
Don
On Dec 27 2012, 5:01
@Doom: Yes. It is necessary to go through the entire list. The code could
look like this:
int* p = head;
int k = 1;
while( head )
{
head = head - next;
k++;
if( k * (double)rand() RAND_MAX )
p = head;
}
Dave
On Sunday, December 30
@Sanjeev: Set a pointer p to the first node. Traverse the list. When at the
kth node, set p to the kth node with probability 1/k. When you reach the
end of the list, return p, which will point to a random node with uniform
probability.
Dave
On Thursday, December 27, 2012 11:18:20 PM UTC-6
), ...,
(n-1)/n. Thus, node k is selected on the kth step and then retained until
the end of the list with probability 1/k * k/(k+1) * (k+1)/(k+2) * ... *
(n-1) / n. Each denominator cancels with the succeeding numerator, so the
product collapses to 1/n.
Dave
On Friday, December 28, 2012 10:46:17 AM
should you output distinct coins (1,5,10,25,50), or repeat the
coins the required number of times (1,1,1,1,5,10,10,25,50)?
Dave
On Friday, December 21, 2012 4:01:52 PM UTC-6, shady wrote:
Given R and N, output N coins in the range from 1 to R such that average
number of coins needed
,
if I want to make 7 as (5,1,1), do I list the coins as (1,5), which is N=2,
or (1,1,5), which is N=3?
Dave
On Saturday, December 22, 2012 4:34:24 AM UTC-6, shady wrote:
We have *all kinds of denominations (1, 2, 3, R)*... therefore to
cover this range, we generally select coins like
of the heap (min element of the current top ten), then replace the root
with x and re-establish the heap condition. When you are finished with the
input, the numbers in the heap will be the largest ten numbers in the file.
Dave
On Saturday, December 1, 2012 11:54:22 AM UTC-6, vamshi vijay wrote
= (1*32 + 24) goes to 1*32 = 32, 64 (=2*32 + 0) stays at 2*32 = 64, and 127
(=3*32 + 31) goes to 3*32 = 96.
Dave
On Saturday, November 24, 2012 2:45:24 AM UTC-6, rajesh pandey wrote:
void dosomething(int num)
{
int mask=~(15-1);
int res=nummask;
printf(%d,res);
}
int main
@Pralaybi: You've got it right. Since h is proportional to the log of the
smaller number, we also can say that the complexity is O(log^2 (smaller
number)).
Dave
On Friday, November 23, 2012 2:09:01 PM UTC-6, pralaybi...@gmail.com wrote:
@Dave: Could you please correct me if am wrong here
(with C's 0-based array indexing):
int maxEqual( int n, int a[])
{
int i, sum = 0;
for( i = 0 ; i n ; ++i )
sum += a[i];
return if sum % n == 0 ? n : n - 1;
}
Dave
On Thursday, November 22, 2012 1:25:43 AM UTC-6, Ansum Baid wrote:
@Dave: Can you give a little insight on your
@Ansum: Polycarpus should start by summing the numbers. If the sum is
divisible by n, then n numbers can be made equal. If the sum is not
divisible by n, then only n-1 numbers can be made equal.
Dave
On Wednesday, November 21, 2012 12:18:54 PM UTC-6, Ansum Baid wrote:
This question has
@Bharat: See, e.g.,
http://en.wikipedia.org/wiki/Euclidean_algorithm#Algorithmic_efficiency.
Dave
On Sunday, November 18, 2012 12:03:33 AM UTC-6, bharat wrote:
@ Dave : can u pls explain the solution u gave .
How can u say fibnocci sequence produces worst case ?
On Fri, Nov 16, 2012 at 11
reduces by log_10(phi) = log_10((1+sqrt(5))/2) ~= 0.209, where phi
is the Golden Ratio, so it takes, on average, ~4.78 iterations to reduce
the numbers by 1 digit, in the worst case. But still, we can say that
Euclid's algorithm is O(log n).
Dave
On Friday, November 16, 2012 6:40:58 PM UTC-6
@All: This probably is a scam.
Dave
On Tuesday, November 13, 2012 3:32:39 AM UTC-6, Virag wrote:
Hello, I hope this e-mail reaches well. Just to let you know that I'm
presently in Spain for an Agricultural Conference but I'm in a serious fix;
I was mugged and lost all my money cards. I'm
@Don: This can be easily fixed, as there is no need to swap equal values,
so:
void swap(int a, int b)
{
if( a != b )
{
a ^= b;
b ^= a;
a ^= b;
}
}
On Monday, November 5, 2012 10:41:42 AM UTC-6, Don wrote:
Note that most of these methods fail if you try to
@Shivam: Your one-line solution violates the sequence point rule. Hence,
it is non-standard, and the result is compiler dependent.
Dave
On Monday, November 5, 2012 9:36:12 AM UTC-6, Shivam...aka Bboy
rullz... wrote:
in a single line
a^=b^=a^=b;
On 05/11/2012, atul anand atul.8
@Manish: Sure.
a = a + b;
b = a - b;
a = a - b;
In 2-s complement arithmetic, it works even if a + b overflows.
Dave
On Sunday, November 4, 2012 2:32:43 PM UTC-6, manish wrote:
Swapping two objects (not integers/chars),without using temp...?
my solution is using xor operation
@Atul: Try x = 0, a = 1, b = 2, for which (x a x b) is false, but (x
- a b - x) is true.
Dave
On Saturday, October 27, 2012 5:43:17 AM UTC-5, ATul SIngh wrote:
Thnks but i figured it out
as
( x = a x b )
or
( x = a x = b )
could be written as
x -a b - xfor first case
.
Then calculate gcd(k1,k2,...,km), e.g., by repeated applications of
Euclid's Algorithm.
Finally, n is a Trojan number if and only if gcd(k1,k2,...,km) = 1.
Dave
On Wednesday, October 24, 2012 3:37:28 AM UTC-5, Ujjwal Arora wrote:
We had to code 2 questions in 1.30 hr on codechef only
@Rahul: If d is a power of 2, say 2^k, where ^ represents exponentiation,
then the binary representation of d is a 1-bit followed by k 0-bits. Then
d-1 is the binary number comprising k 1-bits. Anding this with n keeps only
the low-order k bits of n, which you can see to be n%d.
Dave
@Bharat: 0x notation indicates hexadecimal, so 0x11 = 1*16 + 1 = 17.
Dave
On Sunday, October 14, 2012 12:48:24 AM UTC-5, bharat wrote:
@Ashok : I didn't get this answer ..
i=0x3c -- what is this address .. variables has addresses but not the
values right? we are not storing 60 any where
@Piyush: I think not. Try n = 17 = 4*4 + 1 or n = 19 = 4*4 + 3. But you can
say that n = 4 * a + b, with 0 = b = 3, is a multiple of 5 if and only if
a - b is a multiple of 5, thus reducing to a simpler problem. That's the
basis of the solution I posted earlier in this string.
Dave
.
The question may be based on that idea, or just on how to do it faster than
using division, which typically is a very slow instruction (compared to
other machine instructions).
Dave
On Thursday, October 11, 2012 4:14:17 AM UTC-5, Jaspreet Singh wrote:
Nice solution Dave sir .. but if you know can you
as (n 1) (n % 5 == 0), though.
Dave
On Wednesday, October 10, 2012 4:06:28 AM UTC-5, mohit mishra wrote:
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks
@Phoenix: If elem does not exist in the array and we did not put it in the
array, then the loop would exceed the array. But by setting arr[0] to elem,
we ensure that the loop does stop.
Dave
On Monday, October 8, 2012 6:52:27 AM UTC-5, phoenix wrote:
@Dave: Nice solution. Can you clarify
@Sanjay: This has been discussed before. See
https://groups.google.com/d/msg/algogeeks/C5oHrps8Q2o/P7tJrhj55ZcJ
for a description of the algorithm.
Dave
On Friday, October 5, 2012 12:19:40 AM UTC-5, Sanjay Rajpal wrote:
We are given 300 million 9-digit numbers and 2 MB of RAM. We have
@Icy: The problem, of course is that there are 900 million 9 digit numbers,
so you solved a restricted problem. There is a solution for the given
problem. See
https://groups.google.com/d/msg/algogeeks/C5oHrps8Q2o/P7tJrhj55ZcJ.
Dave
On Friday, October 5, 2012 4:26:32 PM UTC-5, icy` wrote
@Rafi: Try this:
int arrExsits( int* arr, int size, int elem)
{
int temp = arr[0];
arr[0] = elem;
while( arr[--size] != elem );
arr[0] = temp;
return a[size] == elem ? size : -1;
}
n+1 comparisons, and it leaves the array unaltered.
Dave
On Sunday, September 30, 2012 4:27
@Umer: I say that you forgot to increment i and decrement j in the loop.
But you don't need any loop-counting comparisons at all.
Dave
On Tuesday, October 2, 2012 3:36:58 AM UTC-5, Umer Farooq wrote:
why don't we try it from both ends ... something like this:
int i = 0; j = size-1
@Shashi: It has been discussed before, and an O(n^2 log n) solution is
outlined at
https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/CTB_p7uO8YYJ and is
given in more detail at
https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/0S0zK6HdKdMJ.
Dave
On Monday, October 1, 2012 12:00:19
@Navin: It means that given a positive integer n whose decimal
representation ends in 3, find a multiple, m*n, which is written solely
with the digit 1. E.g., 3: 37 * 3 = 111; 13: 8547 * 13 = 111,111.
Dave
On Thursday, September 20, 2012 11:56:08 PM UTC-5, Navin Kumar wrote:
@all: Please
@Navin: No problem. Just print a 1 instead of a quotient digit. That makes
the code even simpler, like this:
int n=the number that ends with 3;
int divisor=1;
printf(1);
while( divisor != 0 )
{
printf(1);
divisor = 10 * (divisor % n) + 1;
}
printf(\n);
Dave
On Friday, September 21
I thought about it some more, and realize that my code wasn't correct. Try
this:
int n = the number that ends with 3; // e.g., int n = 13;
int d = 1;
while( d % n != 0 )
{
printf(1);
d = 10 * (d % n) + 1;
}
printf(1\n);
On Friday, September 21, 2012 11:07:29 AM UTC-5, Dave wrote
@Rahul: What does this print for n = 193?
Dave
On Friday, September 21, 2012 12:14:18 AM UTC-5, Rahul Kumar Patle wrote:
here is my code:
main()
{
int n=13;
int divisor=1;
int temp;
while( divisor n )
divisor = 10 * divisor + 1;
printf(%d\n , divisor);
temp = divisor;
while(n
= 10 * divisor + 1;
while( divisor != 0 )
{
printf(%d,divisor / n);
divisor = 10 * (divisor % n) + 1;
}
printf(\n);
Dave
On Thursday, September 20, 2012 9:45:55 PM UTC-5, bharat wrote:
what is the solution(not brute force) for 8th question ?
On Fri, Sep 14, 2012 at 5:19 PM, Bhupendra
to a multiple
of x, and then adding x gives the next larger multiple of x.
Dave
On Thursday, September 13, 2012 9:03:49 AM UTC-5, bharat wrote:
the above code works only for 2,4,8,16 ...
On Thu, Sep 13, 2012 at 7:13 PM, VIHARRI P L V
vihar...@gmail.comjavascript:
wrote:
Let me give
@Rahul: You'll find a discussion of the heap method in the thread at
https://groups.google.com/d/topic/algogeeks/483lcb0FTY0/discussion.
Dave
On Saturday, September 8, 2012 11:53:44 AM UTC-5, rahul sharma wrote:
http://www.geeksforgeeks.org/archives/14873
Please explain heap method..hw
@Don: Nope. Constructing a heap can be done in O(n). See, e.g.,
http://www.diku.dk/forskning/performance-engineering/Jesper/heaplab/heapsurvey_html/node9.html
.
Dave
On Tuesday, September 4, 2012 10:24:25 AM UTC-5, Don wrote:
Constructing a max-heap is O(n*log n)
However, the problem
@Daemon: Probably no one understands what you've asked. What does it mean
to convert a number n into strigs of 1's? Doesn't that depend on what a
strig is and what operations are allowed? E.g., if one of the operations is
replacing a digit by the strig 1, the algorithm is pretty simple.
Dave
; If the sum
is greater, advance the right-to-left traversal. Quit with success when the
sum equals the given number or with failure when the two traversals have
reached the same node.
Dave
On Sunday, September 2, 2012 11:00:42 PM UTC-5, atul007 wrote:
convert BST to sorted DLL..
now it is a double
C D B DB C
SABCD
Dave
On Tuesday, August 28, 2012 11:09:47 AM UTC-5, Prem wrote:
Guys Something good to share here..
Query :- Tomorrow I am Planning to take my car for a ride of 1 ( Ten
Thousands ) Km. As the journey
generator for a variety of methods to do this.
Dave
On Sunday, August 26, 2012 9:03:21 AM UTC-5, kailash wrote:
@Dave: Can you throw some light on random() function?? How it is
generating numbers between 0.0 and 1.0, and how many digits are there after
the point...because if there is only
and the numbers at the end of the file will be selected with
slightly too low a probability.
That's why I prescribed a double precision random number generator that
generates uniformly-distributed numbers between 0 and 1, and wrote the
test i * random() 1.
Dave
On Tuesday, August 28, 2012 7:59:13 AM
@Rahul: Please tell us what you mean by a pivoted array.
Dave
On Tuesday, August 28, 2012 12:56:03 PM UTC-5, rahul sharma wrote:
plz provide me algo for this,thnx
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion
and print it out. You will have to use long long int (64 bits)
for some of the calculations, although the base-P digits of n and P will
fit in ordinary 32-bit ints.
Dave
On Sunday, August 26, 2012 6:56:19 PM UTC-5, Ankit Singh wrote:
@dave:
Can u Please elaborate your idea??
I didn't
@Ravi: That is also my understanding, so the solution involves traversing
the tree and keeping track of the values of the two largest leaf nodes.
Dave
On Monday, August 27, 2012 12:53:05 PM UTC-5, Ravi Maggon wrote:
@atul
I think he is asking for max. sum of elements between 2 leaf nodes
@Atul007: No, because a (1,4) tile will not fit on a (2,3) tile.
Dave
On Sunday, August 26, 2012 7:45:27 AM UTC-5, atul007 wrote:
@kailash : you can simply find area of each slab area=x*y ,,,store it;
then just run LIS on this area.
On 8/26/12, Kailash Bagaria kbkailas...@gmail.com
@Ankit: Apply Lucas' Theorem, which you can find written up in Wikipedia.
Dave
On Sunday, August 26, 2012 3:57:18 PM UTC-5, Ankit Singh wrote:
In mathematics, *binomial coefficients* are a family of positive integers
that occur as coefficients in the binomial theorem. [image: \tbinom
nk
.
Furthermore, assuming that rand() produces a random non-negative integer,
rand()%n is not equiprobable for all values of n. Consider n = 3. Then
since rand() takes on 2^31 values, rand()%3 cannot take on the values 0, 1,
and 2 with equal probability since 2^31 is not divisible by 3.
Dave
@MH: What happens is that it does not answer the given question.
Dave
On Wednesday, August 22, 2012 1:00:53 PM UTC-5, The Mad Hatter wrote:
On 08/14/2012 05:56 PM, ragavenderan venkatesan wrote:
Given Xor of 3 numbers, How can we derive back those 3 numbers?
Can any one explain
as the original value, so the second printf()
statement also prints the value -2^31.
I'm glad you asked this question because it is very important to understand
how quantities are stored in C and how the arithmetic works.
Dave
On Tuesday, August 21, 2012 11:25:11 AM UTC-5, wladimirufc wrote:
Somebody
@Megha: Answered in one line of code in the post
https://groups.google.com/d/msg/algogeeks/Fa-5AQR3ACU/jlmjb_nEZCsJ, which
also contains a link to an explanation of how the algorithm works.
Dave
On Tuesday, August 21, 2012 8:23:21 AM UTC-5, megha agrawal wrote:
Can anyone suggest
@Wladimirufc: As I said, this is the functional equivalent. Most computer
cpus would have a negate instruction which performs these operations in the
chip's circuitry, or achieve the same result by subtraction from zero.
Dave
On Tuesday, August 21, 2012 4:58:14 PM UTC-5, wladimirufc wrote
)
copy temp to save;
}
print save;
Dave
On Monday, August 20, 2012 12:02:54 AM UTC-5, Navin Kumar wrote:
@Dave sir, I didn't get your logic. Can you please elaborate it?
On Sun, Aug 19, 2012 at 4:08 AM, Dave dave_an...@juno.com
javascript:wrote:
@Navin: Here is the algorithm:
Save
@Navin: Here is the algorithm:
Save the first word.
For i = 2, 3, ..., n = number of words in the file
replace the saved word with the i-th word with probability 1/i.
When EOF is reached, every word in the file will have probability 1/n of
being the saved word. Print it.
Dave
@Navin: Why? No division is used.
Dave
On Thursday, August 16, 2012 9:20:03 AM UTC-5, Navin Kumar wrote:
We have to consider cases when an element is zero.
On Thu, Aug 16, 2012 at 7:07 PM, shady sin...@gmail.com javascript:wrote:
well we can do with just one array. Overwrite the answer
@Shady: You can do it with just the input array and the output array. In
the language of Atul007, put temp2 in the output array, and calculate temp1
as a scalar, i.e., one element at a time as you replace the elements of
temp2 with the result.
Dave
On Thursday, August 16, 2012 5:40:23 AM UTC
@Navin: Divide the coins into two groups of 10, and then flip all of the
coins in one of the groups. Suppose group A has x heads and 10 - x tails.
Then before you flip them, group B has 10 - x heads and x tails. After you
flip them, group B has x heads and 10 - x tails.
Dave
On Tuesday, July
@s_m154: Sort the array in O(n log n) and then compare adjacent numbers to
find the closest pair in O(n). Total: O(n log n).
Dave
On Friday, July 27, 2012 10:41:28 AM UTC-5, s_m154 wrote:
Can you please give the algo of solving it in O(nlogn)
On Friday, 27 July 2012 15:35:24 UTC+5:30
@Arun: I left out that you sort the array by absolute values and compare
absolute values of adjacent elements. The sorted array would be {-2, 4, -8,
9, 10, 12, 14, 17, -20}. Then abs(abs(-8) - abs(9)) is the smallest
difference.
Dave
Dave
On Friday, July 27, 2012 11:21:52 PM UTC-5, Arun
. Then
restart sequence 1 and iterate the two sequences simultaneously until they
agree.
Dave
On Thursday, July 26, 2012 12:39:44 PM UTC-5, Ali Ahmad Ansari wrote:
Given a number N, generate a sequence S such that
S[ 0 ] = N
S[ i+1 ] = (3 * S[ i ] + 1) / 2 if S[ i ] is odd,
= S[ i ] / 2, if S[ i
@Ruru:
int i,j,sum=100*101/2;
for( i = 1 ; i = 100 ; ++i )
{
j = i;
while( j )
{
j = 1;
sum -= j
}
}
printf(%i\n,sum);
Dave
On Tuesday, July 24, 2012 4:39:42 AM UTC-5, ruru wrote:
find no. of 1's in binary format of numbers from 1 to 100. like for
1 to 10
@Arun: The referenced algorithm solves the wrong problem. The problem given
has n-2 unique elements and 1 element repeated twice. The referenced
algorithm has n-1 elements that occur in pairs and one that is unique;
xoring will solve this problem, but it won't help solve the given one.
Dave
and
another could ask for the max and min for the last 100 days. Others seem to
assume that k is known as the data are collected.
Dave
On Saturday, July 14, 2012 2:55:48 PM UTC-5, Navin Kumar wrote:
A set of integer values are being received (1 per day). Store these values
and at any given time
@Navin: A sorted array is a heap. So use the second half of a heap sort
algorithm to produce the array in sorted order. You can store the sorted
array backwards in the original array. Then reverse the array and squeeze
out the duplicates. O(n log n).
Dave
On Saturday, July 14, 2012 3:28:29
with the head node, is searched for the last item whose date
differs from the current date by k, and similarly the list formed by the
next smaller pointers.
Dave
On Saturday, July 14, 2012 2:55:48 PM UTC-5, Navin Kumar wrote:
A set of integer values are being received (1 per day). Store
1 - 100 of 937 matches
Mail list logo