[algogeeks] Re: probability question

2011-08-31 Thread Don
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

[algogeeks] Re: loop in link list

2011-08-31 Thread Don
@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

[algogeeks] Re: Find Max Sum Value Pairs

2011-09-01 Thread Don
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

[algogeeks] Re: How to find median of 2 sorted arrays of different length

2011-09-01 Thread Don
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

[algogeeks] Re: Hexadecimal to Decimal

2011-09-01 Thread Don
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

[algogeeks] Re: Hexadecimal to Decimal

2011-09-01 Thread Don
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

[algogeeks] Re: How to find median of 2 sorted arrays of different length

2011-09-01 Thread Don
> 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

[algogeeks] Re: Hexadecimal to Decimal

2011-09-01 Thread Don
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

[algogeeks] Re: How to find median of 2 sorted arrays of different length

2011-09-01 Thread Don
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

[algogeeks] Re: Fwd: 8 queens problem

2011-09-01 Thread Don
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

[algogeeks] Re: How to find median of 2 sorted arrays of different length

2011-09-01 Thread Don
=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

[algogeeks] Re: Hexadecimal to Decimal

2011-09-02 Thread Don
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

[algogeeks] Re: Hexadecimal to Decimal

2011-09-02 Thread Don
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

[algogeeks] Fire when ready!

2011-09-02 Thread Don
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

[algogeeks] Re: whats d problem wid using gets?

2011-09-03 Thread Don
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

[algogeeks] Re: Stack problem

2011-09-04 Thread Don
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

[algogeeks] Re: Stack problem

2011-09-05 Thread Don
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

[algogeeks] Re: problems about the puzzle "Chameleon"

2011-09-05 Thread Don
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

[algogeeks] Re: problems about the puzzle "Chameleon"

2011-09-05 Thread Don
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 > > > > > > >

[algogeeks] Re: Stack problem

2011-09-06 Thread 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

[algogeeks] Re: problems about the puzzle "Chameleon"

2011-09-06 Thread Don
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

[algogeeks] Re: Linkedlist problem

2011-09-06 Thread Don
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

[algogeeks] Re: plz help

2011-09-07 Thread Don
@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

[algogeeks] Re: plz help

2011-09-07 Thread Don
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

[algogeeks] Re: Functions

2011-09-07 Thread Don
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

[algogeeks] Re: Aps

2011-09-07 Thread Don
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.

[algogeeks] Re: Aps

2011-09-07 Thread Don
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 &

[algogeeks] Re: sorting

2011-09-08 Thread Don
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

[algogeeks] Re: Object Oriented Programming

2011-09-10 Thread Don
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

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-12 Thread Don
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

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-12 Thread Don
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

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread Don
@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

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread Don
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

[algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread Don
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

[algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread Don
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

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Don
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

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Don
// 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

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Don
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

[algogeeks] Nonuniform distribution

2011-09-14 Thread Don
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

[algogeeks] Re: complexity of recursion

2011-09-14 Thread Don
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,

[algogeeks] Re: no of elements of the array

2011-09-15 Thread Don
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

[algogeeks] Re: Math Puzzle

2011-09-15 Thread Don
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

[algogeeks] Re: Math Puzzle

2011-09-15 Thread Don
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

[algogeeks] Re: Math Puzzle

2011-09-15 Thread Don
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

[algogeeks] Re: Nonuniform distribution

2011-09-15 Thread Don
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

[algogeeks] Re: Party Lamps

2011-09-15 Thread Don
, 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

[algogeeks] Re: Party Lamps

2011-09-15 Thread Don
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

[algogeeks] Re: hash

2011-09-16 Thread Don
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

[algogeeks] Re: PLEASE HELP ME - Party Lamps

2011-09-16 Thread Don
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

[algogeeks] Re: question on algorithm

2011-09-16 Thread 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

[algogeeks] Re: Array ques based on correlation factor

2011-09-19 Thread Don
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

[algogeeks] Re: question on algorithm

2011-09-19 Thread Don
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

[algogeeks] Re: random function

2011-09-19 Thread Don
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

[algogeeks] Re: random function

2011-09-19 Thread Don
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: >

[algogeeks] Re: random function

2011-09-19 Thread Don
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

[algogeeks] Re: All valid dictionary words must be found and printed.

2011-09-19 Thread Don
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

[algogeeks] Re: stack

2011-09-20 Thread Don
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

[algogeeks] Re: stack

2011-09-20 Thread Don
} } 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? &

[algogeeks] Re: Question -->

2011-09-20 Thread Don
@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

[algogeeks] Re: stack

2011-09-20 Thread Don
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

[algogeeks] Re: stack

2011-09-20 Thread Don
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 ==

[algogeeks] Re: which is better?

2011-09-22 Thread Don
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

[algogeeks] Re: error in c++ program

2011-09-22 Thread Don
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();};

[algogeeks] Re: Doubts about realloc

2011-09-22 Thread Don
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

[algogeeks] Re: Permuations and Combinations

2011-09-22 Thread Don
,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

[algogeeks] Re: Permuations and Combinations

2011-09-22 Thread Don
,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

[algogeeks] Re: Permuations and Combinations

2011-09-22 Thread Don
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

[algogeeks] Re: Questions on Graphs

2011-09-22 Thread Don
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

[algogeeks] Re: What is the maximum no. of arguments that can be given in a command line in C...??

2011-09-23 Thread Don
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...@

[algogeeks] Re: Infinite Array

2011-09-29 Thread Don
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

[algogeeks] Re: Number of Multiplications

2011-09-29 Thread Don
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: >

[algogeeks] Re: SPOJ PIGBANK Problem

2011-09-29 Thread Don
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

[algogeeks] Re: Infinite Array

2011-09-30 Thread Don
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

[algogeeks] Re: Sudoku

2011-10-04 Thread Don
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

[algogeeks] Re: recursion

2011-10-04 Thread Don
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

[algogeeks] Re: Sudoku

2011-10-05 Thread Don
. 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

[algogeeks] Re: Given a String with unnecessary spaces, compact it in place

2011-10-13 Thread Don
*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

[algogeeks] Re: Sorting a array which is already sorted but has some disorder

2011-10-17 Thread Don
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

[algogeeks] Re: Code it...

2011-10-17 Thread Don
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. > > -- &

[algogeeks] K-best assignment problem

2011-10-17 Thread Don
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

[algogeeks] Re: Code it...

2011-10-18 Thread Don
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

[algogeeks] Re: Modular arithmetic

2011-10-21 Thread Don
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

[algogeeks] Re: Get Target

2013-04-04 Thread Don
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.

[algogeeks] Re: how to solve this?

2013-04-04 Thread Don
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&#x

[algogeeks] Re: Dlete Linked List

2013-04-09 Thread 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

[algogeeks] Re: Dlete Linked List

2013-04-09 Thread Don
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; >

[algogeeks] Re: Amazon interview question

2013-04-09 Thread Don
, 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/ >

[algogeeks] Re: Amazon interview question

2013-04-09 Thread Don
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

[algogeeks] Re: Find the number of islands/connected components

2013-04-10 Thread Don
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

[algogeeks] Re: Interview question

2013-04-10 Thread Don
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: > > > >

[algogeeks] Re: Primality testing

2013-04-15 Thread Don
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

[algogeeks] Re: Primality testing

2013-04-15 Thread Don
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

[algogeeks] Re:

2013-04-15 Thread Don
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

[algogeeks] Re: algorithm to sort based on frequency.

2013-04-16 Thread Don
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

[algogeeks] Re:

2013-04-17 Thread Don
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

[algogeeks] Re: Find words in string

2013-04-18 Thread Don
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

[algogeeks] Re: Ceil in sorted array

2013-04-18 Thread Don
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

[algogeeks] Re: least common ancestore bst

2013-04-22 Thread Don
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

[algogeeks] Re: Median of two sorted arrays of different sizes

2013-04-24 Thread Don
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 ) >

[algogeeks] Re: Find the number of islands/connected components

2013-04-25 Thread Don
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

<    1   2   3   4   5   6   >