main line train is 0.841666...
Don
On Aug 31, 8:37 am, swetha rahul wrote:
> In a railway station, there are two trains going. One in the harbour line
> and one in the main line, each having a frequency of 10 minutes. The main
> line service starts at 5 o'clock and the harbour line sta
@Rahul
The problem is to determine if there is a loop. That means there might
not be. And if there isn't, you really shouldn't dump core.
Don
On Aug 31, 10:17 pm, Siddhartha Banerjee
wrote:
> how can head2->next be null in a linked list witha loop???
> i mean it would just g
Start with pair (A(i), B(j)) where i and j are both n.
Then the next largest pair will either be (A(i-1), B(n)) or (A(n),
B(j-1)). Whichever sum is larger, set i and j to those values. Repeat
as desired.
Don
On Sep 1, 3:45 am, Navneet Gupta wrote:
> Given two sorted positive integer arrays
ray.
You'll need some logic at the end to determine if the median is in A
or in B.
Don
On Sep 1, 10:31 am, Ankur Garg wrote:
> Can anybody explain logic ?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this g
sscanf(string, "%x", &n);
On Sep 1, 11:34 am, rShetty wrote:
> Given a Hexadecimal value as a string, give a C Code to convert it
> into decimal value?
> If 0xff then output should be 255.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To
int n;
char *string = "0xff"; // Or whatever
sscanf(string, "%x", &n);
printf("%d\n", n);
On Sep 1, 11:34 am, rShetty wrote:
> Given a Hexadecimal value as a string, give a C Code to convert it
> into decimal value?
> If 0xff then output should be 255.
--
You received this message because you
> A[i]) min = i+1;
else if (B[j+1] < A[i]) max = i-1;
else break;
}
printf("Median is %d\n", (A[i] > B[j]) ? A[i] : B[j]);
Don
On Sep 1, 1:01 pm, Rahul Verma wrote:
> how we find the median, if we don't have sufficient memory to merge them.
--
You received this m
Of course there are other methods, but why duplicate functionality
already provided by the language?
Don
On Sep 1, 11:34 am, rShetty wrote:
> Given a Hexadecimal value as a string, give a C Code to convert it
> into decimal value?
> If 0xff then output should be 255.
--
You rece
ianPos-i;
if (B[j] > A[i]) min = i+1;
else if (B[j+1] < A[i]) max = i-1;
else break;
}
printf("Median is %d\n", (A[i] > B[j]) ? A[i] : B[j]);
Don
On Sep 1, 10:31 am, Ankur Garg wrote:
> Can anybody explain logic ?
--
You received this message because you are sub
urns false.
Below is working code.
Don
// Solve 8 queens problem. queens[i] will contain the column of the
queen in row i.
bool placeQueens(int row, int *queens)
{
if (row == 8) return true;
// Look for locations to place queen on current row
for(queens[row] = 0; queens[row] < 8; ++queens[row
=sizeB
startB = (sizeA/SizeB)/2;
endB = startB + sizeA;
Assuming that sizeA <= sizeB, we know that if the median is in B, it
will be in that range.
Don
On Sep 1, 2:27 pm, Jay Mahadeokar wrote:
> As you can see, each time, we are either discarding 1st half of A or second
> half of A. S
x27;0';
else if ((string[i] >= 'a') && (string[i] <= 'f'))
x = (x*16) + string[i] - 'a' + 10;
}
return x;
}
On Sep 1, 11:56 am, rajeev bharshetty wrote:
> @Don : Thanks , are there any other methods
>
>
>
> On Thursd
7;a') && (string[i] <= 'f'))
x = (x*16) + string[i] - 'a' + 10;
}
return x;
}
Don
On Sep 1, 11:56 am, rajeev bharshetty wrote:
> @Don : Thanks , are there any other methods
>
>
>
> On Thursday, September 1, 2011, Don wrote:
> &g
the "Fire
when ready" command and the soldiers firing, but all soldiers must
transition to "Fire" in the same interval. The algorithm must work
regardless of the value of N, and the soldiers do not know the value
of N. Each one knows only his own state and the states of hi
Use fgets instead. It allows you to limit the length of the string. In
general, writing a program which a user can crash or cause to
malfunction by typing too long of an input string is a bad thing.
Don
On Sep 3, 1:37 pm, Shashank Jain wrote:
> Shashank Jain
> IIIrd year
> Computer En
Each element in the stack will contain not only its own value, but the
min value at that depth of the stack:
struct stackItemStruct
{
int value;
int min;
struct stackItemStruct *next;
};
typedef struct stackItemStruct stackItem;
class stack
{
public:
stack();
void push(int v);
int po
that value is still in the stack.
For instance:
Push: 20 1 3 1 8 1 10 1 12 1
Pop
Min() will now return 20, even though 20 is the largest item in the
stack.
Don
On Sep 5, 11:49 am, teja bala wrote:
> You can implement this by having each node in the stack keep track of the
> minimum be
No, f(15,14,16) = 5.
Don
On Sep 5, 8:33 pm, wujin chen wrote:
> hi all, i encountered this puzzle (http://www.crackpuzzles.com/?p=236):
>
> At one point, a remote island's population of chameleons was divided as
> follows:
> - 13 red chameleons
> - 15 green chameleons
chameleons can never be the same color, but I
agree that his "proof" is not valid.
Don
On Sep 5, 9:08 pm, wujin chen wrote:
> hi Don, i think f(15,14,16) =|15-14|+|14-16|+|16-15| = 1+2+1=4, hou do you
> get f(15,14,16) = 5?
>
> 2011/9/6 Don
>
>
>
>
>
>
>
@HARISH:
Push 20 1 3 1 5 1 6 1 2 1
Pop
Now in your algorithm min will return 20, even though 1 and 3 and
other smaller numbers are still in the stack.
Don
On Sep 6, 6:25 am, "HARISH S.C" wrote:
> Have a separate stack for minimum. While pushing, insert the number in
> minimum s
have 45 of any one color. Code
follows.
Don
int main(int argc, char* argv[])
{
int r,g,b;
int possible[46][46] = {{0}};
possible[13][15] = 1;
int prevPossible, numPossible = 1;
do
{
prevPossible = numPossible;
for(r
If you set that flag, the list accessors can skip over that node when
traversing the list. The list can later be cleaned up and deleted
nodes removed.
Don
On Sep 5, 6:59 am, "$hr! k@nth" wrote:
> Hi guyz,
>
> *Given only a pointer to a node to be deleted in a singly linked lis
@Rahul: You are OBVIOUSLY wrong. Obviously.
On Sep 7, 8:16 am, rahul vatsa wrote:
>
> @dave, no of days & no of paintings required are 25. And we need to find out
> how many ppl r required for this. obviously it will be 1 only.
> if there will be more than 1 guy, the work will be finished before
Figure out the man days per painting:
5/2 artists working for 5/2 days is 25/4 man days.
They produce 5/2 paintings, so that is 5/2 man days per painting.
Thus to make 25 paintings will require 25*5/2 man days.
To complete that work in 25 days will require 5/2 painters.
Don
On Sep 7, 7:15 am
core a move looking ahead to the requested depth
I could be missing something. Anything else that would be necessary or
useful?
Don
On Sep 7, 2:17 am, guna sekaran wrote:
> Funtions that should be used to implemnt chess board movements which
> covers all concepts of cpp( no need o
Clearly you are sitting still looking at a "Route 66" sign.
Don
On Sep 7, 10:09 am, Mani Bharathi wrote:
> While traveling at uniform speed. U read a two digit no. after one hr
> the number is reversed order. After another hour the number read is same
> two digit number.
But 106 is neither the same as 16 nor is 106 a two-digit number.
Mani, if you are going to repost something we've already discussed to
death, please at least state the problem correctly.
Don
On Sep 7, 10:12 am, "gmagog...@gmail.com" wrote:
> First number: 16
> second : 61
&
Best for what?
Don
On Sep 8, 12:41 pm, aayush jain wrote:
> which is best sorting tec. n why???
--
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 fr
Head First Design Patterns
On Sep 10, 2:12 pm, Brijesh wrote:
> Guys please suggest me any good book for object oriented programming..which
> have lots of example of good design pattern.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To po
For particular values of p we might be able to do better, but for
unknown values of p, I can't think of anything better than this:
int g(double p)
{
int n = 0;
for(int i = 0; i < 30; ++i)
n += n+f();
return n > (int)(p*1073741824.0);
}
On Sep 12, 9:55 am, JITESH KUMAR wrote:
> Hi
> You
It uses 30 random bits from f() to build a 30-digit number which will
be in the range 0..2^30. 2^30 is 1,073,741,824. p*2^32 is the number
of values in that range which should produce the result 0.
Don
On Sep 12, 10:48 am, siddharth srivastava wrote:
> On 12 September 2011 20:49, Don wr
@Dave: Very nice.
Don
On Sep 12, 10:51 pm, Dave wrote:
> Here's another way, using a rejection technique on the bits of the
> mantissa of p. Each iteration of the do-while loop exposes another
> high-order bit of p, and the do-while loop iterates as long as the
> random bits pr
probabilities sum to 1. Initialization of the generator may require
time O(n) and the generator may require memory of O(n), but generation
of each output must be constant time (O(1)).
Don
On Sep 12, 9:55 am, JITESH KUMAR wrote:
> Hi
> You are given a function f() that returns either 0 or 1 with
You could do a depth-first search limited to depth 2. If that fails,
do it to depth 3. Then 4, etc. It is very space efficient, and you
will be spending 99% of your time at the deepest level, so the time
penalty compared to breadth first is not all that bad.
Don
On Sep 13, 9:57 am, JITESH KUMAR
e time and look for a friend common
to both search trees.
Don
On Sep 13, 9:57 am, JITESH KUMAR wrote:
> Depth is not mentioned, it can be any.
> This question was asked from me in the telephonic interview of DE Shaw.
> The interviewer told me reduce space complexity.
>
> On Tue, S
Scanf with a %d flag will ignore anything that is not a decimal
number, until it finds a decimal number.
Don
On Sep 13, 5:23 am, Avinash Dharan wrote:
> #include
> void main()
> {
> while(1)
> {
> int opt;
> scanf("%d",&a
// If bits i and j are equal, result is just n
// Otherwise, toggle bits i and j
int bitExchange(int n, int i, int j)
{
return (((n>>i)&1) == ((n>>j)&1)) ? n : n ^ ((1< wrote:
> Suppose a number 'n' is given and two bits positions i,j present in binary
> representation of n .
>
> Then how to ex
Yes, good catch. It should be the bitwise or.
Don
On Sep 13, 3:37 pm, Dave wrote:
> @Don. Very nice. I think you meant | where you wrote ||. This is so
> short that you could even do it as a #define:
>
> #define bitExchange(n,i,j) (n)>>(i))&1)==(((n)>>(j))&a
on any draw). Initialization of the
generator may be of time complexity O(N) and the generator may have
memory use of O(N), but each draw must be constant time O(1).
Don
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to
The complexity of a simple recursive implementation to find the
fibonacci series is exponential complexity.
But there are faster ways to compute the fibonacci series which are
not exponential, so you really can't say that the complexity of the
fibonacci series is exponential.
Don
On Sep 14,
would not recommend it for any code which someone may someday have to
maintain.
Don
On Sep 15, 10:59 am, rahul vatsa wrote:
> if i pass an int array to a function, is it possible to find out the no of
> elements in the called function ?
--
You received this message because you are subscri
It might be 3, but it doesn't have to be 3.
Don
On Sep 14, 11:56 pm, NAGARAJAN SIVARAMAN wrote:
> if P+Q+R= 0 then P2 /QR + Q2/PR + R2/PQ = ??
>
> how to solve this??
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" grou
No, not at all. Here is a trivial counterexample:
P = Q = R = 0
Don
On Sep 15, 11:46 am, abhinav gupta wrote:
> Shut up...its 3,,
>
>
>
> On Thu, Sep 15, 2011 at 9:43 AM, Don wrote:
> > It might be 3, but it doesn't have to be 3.
> > Don
>
> > On Sep
constraint where the expression
is not equal to 3.
Don
On Sep 15, 11:57 am, abhinav gupta wrote:
> u cnt divide a number by 0..that thing is self undrstod
>
> On Thu, Sep 15, 2011 at 9:49 AM, Piyush Grover
> wrote:
>
>
>
> > Don is right
>
> > if R
s in simulation applications involving hundreds or even
thousands of possible events, and it works very nicely.
Don
On Sep 14, 9:32 am, Don wrote:
> Given a pseudo-random generator which produces a uniform distribution
> from the range 0..2^32-1, build a generator which produces discrete
> sam
, and the order of the button presses does not matter.
Don
On Sep 15, 10:26 pm, Mohammad Reza Rahmani
wrote:
> just 2^4??? why???
> we have 4^1 states and it's about 10^6000...This value is very big
> to perform complete search...Is it True?
>
> thank's
>
> On 9
rest.
Don
On Sep 15, 11:58 pm, Mohammad Reza Rahmani
wrote:
> I did'nt exactly what you say
> why 6 adjacent lamps
> it just depend on the buttons not on lamps...
>
> "you just need to know if a certain button has been pushed..." you're
> true...and it
e. You are better off, when possible, picking the right
size to start with.
There are many schools of thought on hashing, and many ways to tailor
a hashing system to a particular need. Think about the requirements of
your application and look for the best way to accomplish your specific
task.
I
8, 14, 20, etc. You just need
to try the 16 possible combinations of odd/even button pushes. At most
eight of them will be possible based on the value of C. Determine the
final state of lamps 1-6, and then determine if that is consistent
with the given final states. If so, output that result.
Don
solution is so simple.
Don
int result = 0;
for(int quarters = 0; quarters <= n; quarters += 25)
for(int dimes = 0; (quarters+dimes) <= n; dimes += 10)
result += 1 + (n-quarters-dimes) / 5;
On Sep 16, 1:35 pm, prasanth n wrote:
> Given an infinite number of quarters
This depends on rnd being a good pseudo-random generator. I don't
suggest using the RNG built into many compilers. Instead use something
like the Mersenne Twister which produces much better results with an
extremely long period. My Random class has a "gen" method which
returns an integer in the ran
ult in one step
instead.
Don
On Sep 17, 8:08 am, bharatkumar bagana
wrote:
> @don:
> will u pls explain why divided by 5 is used
>
>
>
> On Fri, Sep 16, 2011 at 3:44 PM, prasanth n wrote:
> > @Don:
> > thanks a lot
>
> > On Sat, Sep 17, 2011 at 12:28
You mean a pseudo-random generator.
Without special hardware you won't get a real random generator.
Use Mersenne Twister.
Don
On Sep 19, 9:43 am, prasanth n wrote:
> anyone give an algorithm of how to generate a random number..probability of
> occurrence of each no should
The most common way that it works would be that random(n) returns the
equivalent of a random integer mod n, so 0<=x wrote:
> @don:
> suppose if give like random(5)-> it must give any number between 0 and 5..
>
>
>
> On Mon, Sep 19, 2011 at 8:22 PM, Don wrote:
>
The "rand()" functions built into many compilers are notoriously bad.
If the quality of the random series doesn't matter much, it might be
ok. If you are doing any kind of simulation, use Mersenne Twister.
Don
On Sep 19, 10:48 am, abhinav gupta wrote:
> for that u have ra
Assuming that findword is O(n) for words of size n, this will be an
O(n^3) algorithm. If you had a better interface to the dictionary, it
could be O(n). That's another example of why interfaces should be
designed for the intended task.
Don
On Sep 19, 9:50 am, Sangeeta wrote:
> given an
Does the call stack count as a stack?
Don
On Sep 20, 12:27 pm, prasanth n wrote:
> In the classic problem of the Towers of Hanoi, you have 3 rods and N disks
> of different sizes which can slide onto any tower. The puzzle starts with
> disks sorted in ascending order of size from top
}
}
int main(int argc, char* argv[])
{
const int n = 5;
move(n, 1, 2, 3);
return 0;
}
On Sep 20, 12:37 pm, prasanth n wrote:
> @don:
> yes it think
>
>
>
> On Tue, Sep 20, 2011 at 11:00 PM, Don wrote:
> > Does the call stack count as a stack?
&
@Dave: Beautiful.
Don
On Sep 20, 11:53 am, Dave wrote:
> I am missing a couple of parentheses. So make that
>
> N = (N & ~((2 << j) - (1 << i))) | (M << i);
>
> And to make up for the extra post to get it right, I'll explain it:
> 2< 1< The d
This is untested, but you should get the general idea.
Don
#include
struct h
{
int n, from, to, use;
};
typedef struct h stackEle;
int main(int argc, char* argv[])
{
stack s;
stackEle se;
se.n = 5;
se.from = 1;
se.to=3;
se.use = 2
delete se;
}
return 0;
}
On Sep 20, 12:52 pm, prasanth n wrote:
> @don:
> if call stack does not count as stack??..
>
>
>
> On Tue, Sep 20, 2011 at 11:13 PM, Don wrote:
> > #include
>
> > void move(int n, int from, int to, int use)
> > {
> > if (n ==
If the value of the expression is not being used, ++n is preferred.
Most coding standards used by big companies require the prefix
operator to be used unless the pre-incremented value is required.
Don
On Sep 22, 7:54 am, Sahil Garg wrote:
> n=n+1
>
> n++
>
> ++n
>
> which o
Give us some help. What is the error? Syntax error? Logic error?
Runtime error?
On Sep 22, 10:47 am, Rajesh Kumar wrote:
> how we can remove error ?
> #include
> using namespace std;
> class time
> {
> int m;
> int h;
> public:
> void set(int,int);
> void sum(time,time,time);
> void display();};
Realloc will resize a block of memory larger or smaller. If it
requires that the block be moved, it will copy the contents of the old
memory into the new location and free the old memory.
Don
On Sep 22, 12:01 pm, Ankuj Gupta wrote:
> Hi
>
> I have a doubt in functioning of realloc. C
,n,p+1,k-1);
}
a[p] = tmp;
}
}
To generate permutations of the array, call permute(A, n, n);
Complexity is O(n!), which is the same as the size of the output.
Don
On Sep 22, 2:53 pm, kumar raja wrote:
> (1) What is the efficient approach to generate permutations of a given
&g
,p+1,k-1);
}
a[p] = tmp;
}
}
To generate permutations of the array, call permute(A, n);
Complexity is O(n!), which is the same as the size of the output.
Don
On Sep 22, 2:53 pm, kumar raja wrote:
> (1) What is the efficient approach to generate permutations of a given
> sequence o
permute(a,n,p+1,k-1);
a[i] = a[p];
}
a[p] = tmp;
}
}
To generate permutations of the array, call permute(A, n);
Complexity is O(n!), which is the same as the size of the output.
Don
On Sep 22, 2:53 pm, kumar raja wrote:
> (1) What is the efficient approach to generate permut
Given an undirected graph in which each edge has a capacity, find the
maximum capacity from node A to node B.
Given a directed graph where each edge has a cost, find the lowest
cost path from node A to node B.
Find the minimal spanning tree of a weighted, connected graph.
On Sep 22, 2:03 pm, Ank
2^31-1
On Sep 23, 8:55 am, amrit harry wrote:
> solve it.
--
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...@
search on that interval.
Don
On Sep 29, 6:59 am, pooja wrote:
> Given a sorted Array of infinite length.. what is the most optimum way
> to search for an element. We hane no idea about its length..
--
You received this message because you are subscribed to the Google Groups
"Algorithm G
can see that a^16 will require 4 multiplications, which is
log2(16), but a^15 will require 6 multiplications (an alternative
algorithm could do it in 4 multiplications and a division).
Also note that the function above is only correct for b > 0.
Don
On Sep 29, 12:54 pm, Ankuj Gupta wrote:
>
I think that it will fail if the value of the coins can be more than
50001.
Don
On Sep 29, 12:35 pm, manish patel wrote:
> http://www.spoj.pl/problems/PIGBANK/
>
> please suggest some test case where it fails ...
>
> [code]
> #include
> main()
> { int t=0,n,e,f,i,j;
&g
n do a binary search. To find that
index, you could start at i=1 and double i until A[i] >= the value you
are searching for. My method uses something like Newton's Method which
will converge more quickly in some cases. It assumes that the slope is
fairly consistent, which may or may not be a g
neither method above filled in any cells, then do the
following:
Pick the empty cell with the fewest possible values
Try the possible values in that cell until you find one which
allows the puzzle to be completed
If the puzzle is solvable, this will solve it in a fraction of a
secon
crement affected the local instance of the array.
Don
On Oct 1, 1:44 pm, rahul sharma wrote:
> as we know in recursion new set of variables are created for every
> recurrsive call...if i have array in recursion,then does a new array created
> for every recursive call???
--
You re
.
I have implemented a Sudoku solver. C++ code follows.
Don
#include
#include
#include
#include
// The contents of the 81 cells
int board[81];
// The rows, columns, and squares which must each
// contain a permutation of the digits 1-9
int groups[27][9] = {
{ 0, 1, 2, 3, 4, 5, 6, 7
*ptr1 = 0;
Don
On Oct 11, 3:41 pm, prasad jondhale wrote:
> *ptr1=*ptr2=string;
> for(i=0;i if(*str==' ')
> ptr2++;
> else
> {
> *ptr1=*ptr2;
> ptr1++;
> ptr2++;
> }
>
> hey guys if anything wrong in this code pls let me
ksort, in this one special case.
Don
On Oct 16, 11:17 am, sravanreddy001 wrote:
> OK..
> what is expected?
>
> its again sort problem, unless the amount of distortion is constant, in
> which a Binary search or Insertion sort can be employed to do in O(n) time.
> Didn't give
Could be done by a self-modifying program.
Don
On Oct 15, 5:26 am, kumar raja wrote:
> you have to write a program which tell about how many times it has run.
> ex:
> if you run first time it will print 1.
> if you run second time it will print 2.
> like this.
>
> --
&
Given a cost matrix with N columns and M rows such that M>=N, find the
K lowest total cost ways to select one item from each column, with the
restriction that only one item may be selected from any row.
Don
--
You received this message because you are subscribed to the Google Groups
"A
It depends on the language.
If is is a scripted or interpreted language then you can just change
the source code.
If it is a compiled language you would change the binary code where
the output value is stored.
I'm not saying that it is a recommended approach, but it is possible.
Don
On Oct 1
Use NTL's ZZ extended integer type.
Don
On Oct 21, 12:26 pm, Aamir Khan wrote:
> Lets say n,m and p are three long long integers.
>
> i want to calculate (n*m)%p.
>
> If (n*m) overflows the limit of long long then the answer would be wrong.
> Moreover if i do ((n%p)*(m%p
I meant postfix, of course.
Don
On Apr 4, 10:32 am, Don wrote:
> Use a backtracking search to build a prefix expression. If there are
> two more operands than operators in the expression, the next item
> could be either an operand or an operator. Otherwise, it must be an
> operand.
I like that solution better than the one I suggested.
Don
On Apr 4, 4:45 pm, Dave wrote:
> @Kumar0746: Technically, you can't solve an _expression_; you can solve an
> _equation_, which is a statement of the form expression = expression, which
> is what you have.
>
> Don
"head" is not even declared, so I doubt that it would compile.
I believe that you want to free head, not next.
On Apr 9, 11:31 am, rahul sharma wrote:
> Is the following code correct for linked list deletion or i need to copy
> head in some tem. pointer and dlete and theninitialize head to NULL
e where head is pointing to
a node which has already been deallocated.
Don
On Apr 9, 2:22 pm, rahul sharma wrote:
> sory..following is correct code
> void deleteList(struct node** head)
> {
> /* deref head_ref to get the real head */
> struct node* next;
>
, at which
point it will crash.
Don
On Apr 9, 2:29 pm, rahul sharma wrote:
> A = {5, 3, 8, 9, 16}
> After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
> After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
> Given an array, return sum after n iterations
>
> my sol/
>
d unnecessary.
For bonus points, can you determine how this problem relates to
Pascal's Triangle.
Don
On Apr 9, 2:43 pm, rahul sharma wrote:
> If you have any other solution ..please post that...i thnik recursion is ok
> with base case...we need to scan again after first iteration
Reformatting to make it easier to see:
11000
01001
10011
0
10101
In this case an "island" is any set of "1's" which are connected
vertically, horizontally, or diagonally.
So the five islands are
11000
01002
10022
0
30405
Don
On Apr 10, 4:3
M is a matrix, not a number. M is NxN, so the algorithm is O(N^3) as
stated in the text.
On Apr 10, 4:19 pm, rahul sharma wrote:
> isnt the complexity should be o(m*n*n) instead of (n*n*n) as m can be
> greater than n..plz comment
>
> On Wed, Apr 10, 2013 at 10:11 PM, rahul sharma wrote:
>
>
>
>
index.html for more information.
Don
On Apr 14, 1:16 pm, payel roy wrote:
> You are to test whether a number if prime or not.
>
> Digit of that number can be as large as 1000. How do you do that?
>
> I was thinking of basic idea.
>
> a) First I shall calculate all primes which
For numbers larger than what can be stored in your computer's native
integer types, you should use an extended precision math library. NTL
is one such option. It provides a type called ZZ which supports
integer operations where the size is limited only by your computer's
memory and speed
send the request to
another processor. Alternatively, fault recovery can be achieved by
redundancy, sending every request to two processors and using the
first response. This should improve worst case response time, but
obviously it requires twice as many processors.
Don
On Apr 15, 5:09 am, &quo
I have not tested this, but it should get you started:
struct item
{
int val;
int freq;
int index;
};
// Compare function for qsort.
// Returns 1 if a occurs with greater frequency than b
// Returns -1 if b occurs with greater frequency than a
// Otherwise returns 1 if a is encountered b
processing unit is known at node A ,whether it
> is up or down.
>
>
>
>
>
>
>
> On Tue, Apr 16, 2013 at 12:23 AM, Don wrote:
> > I think that is called a load leveler. It needs to keep track of the
> > status of the resources, and the capacity of each one, when
like words not on the
list. When "words in attempt" equals n, the saved index is the result.
Don
On Apr 18, 12:04 am, marti wrote:
> Given a list of words wordlist on 1st line (no of words <= 100) and a
> string qstr of len <= 1 million on 2nd line, print the index
Yes, you can use mid+2 there.
On Apr 17, 1:23 pm, rahul sharma wrote:
> following is logn soln
> int ceilSearch(int arr[], int low, int high, int x)
> {
> int mid;
>
> /* If x is smaller than or equal to the first element,
> then return the first element */
> if(x <= arr[low])
> ret
There is no need to use recursion here. Tail recursion is essentially
using recursion as an expensive loop.
int leastCommonAncestor(struct node *root, int n1, int n2)
{
while(root)
{
if ((root->data == n1) || (root->data == n2) || ((root->data >
n1) != (root->data > n2)))
retu
B[j] > A[i]) min = i+1;
else if (B[j+1] < A[i]) max = i-1;
else break;
}
printf("Median is %d\n", (A[i] > B[j]) ? A[i] : B[j]);
Don
On Apr 24, 1:19 pm, rahul sharma wrote:
> IS this code correct?
>
> float findMedianUtil( int A[], int N, int B[], int M )
>
The complexity is still O(ROWS*COLS) because each location in the
matrix will be visited once by the loop and once by DFS. Once a
location has been visited by DFS, it is marked as visited and can't be
visited again.
Don
On Apr 25, 5:11 pm, rahul sharma wrote:
> What will be complexit
301 - 400 of 533 matches
Mail list logo