[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 manispatel...@gmail.com wrote: http://www.spoj.pl/problems/PIGBANK/ please suggest some test case where it fails ... [code] #includestdio.h main() {    int t=0,n,e,f,i,j

[algogeeks] Re: Infinite Array

2011-09-30 Thread Don
. 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 good assumption. Don On Sep

[algogeeks] Re: Sudoku

2011-10-04 Thread Don
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 second. Don On Oct 4, 9:21 am

[algogeeks] Re: recursion

2011-10-04 Thread Don
of the array. Don On Oct 1, 1:44 pm, rahul sharma rahul23111...@gmail.com 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 received this message because

[algogeeks] Re: Sudoku

2011-10-05 Thread Don
. I have implemented a Sudoku solver. C++ code follows. Don #include stdio.h #include ctype.h #include conio.h #include time.h // 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

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

2011-10-17 Thread Don
, in this one special case. Don On Oct 16, 11:17 am, sravanreddy001 sravanreddy...@gmail.com 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 rajkumar.cs...@gmail.com 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. -- Regards

[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 Algorithm

[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 17, 10

[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 ak4u2...@gmail.com 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))%p

[algogeeks] Re: Hash Table

2011-10-25 Thread Don
It can be true if the hash table is used properly. If the table becomes too full or the hash function produces too many collisions it will not be constant time. So designing the hash system well remains very important. Don On Oct 25, 12:15 am, kumar raja rajkumar.cs...@gmail.com wrote: I have

[algogeeks] Re: Dp solution for this problem?

2011-10-31 Thread Don
cost to P plus the location cost of A Insert location A into the queue Then the path cost of the source represents the cost to move from the source to the destination. The path is given by moving from the source to the adjacent location with the lowest path cost. Don On Oct 31, 7

[algogeeks] Re: How to find highest power of 2 in an integer

2011-11-14 Thread Don
in the binary representation. Don On Nov 14, 12:06 am, Ankur Goel goel.anku...@gmail.com wrote:  How to find highest power of 2 in an integer Suppose number is 1 - Highest power of 2 is 1 00011 - Highest power of 2 is 2 11000 - Highest power of 2 is 5 No loops -- You received this message because

[algogeeks] Re: spoj problem

2011-11-14 Thread Don
I solved this one with a breadth-first search. Don On Nov 14, 8:27 am, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem ishttp://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer on spoj . Plz help me to find in which case my solution give wrong answer

[algogeeks] Re: kth smallest element

2011-11-15 Thread Don
Use a binary search to find a value i in the range 1..k such that A[i] = B[k-i] and A[i] = B[k-i+1], in which case the median is A[i] or A[i] = B[k-i] and A[i+1] B[k-i], in which case B[k-i] is the median. Don On Nov 10, 10:07 am, shady sinv...@gmail.com wrote: Given two sorted arrays

[algogeeks] Re: kth smallest element

2011-11-15 Thread Don
Use a binary search to find a value i in the range 1..k such that A[i] = B[k-i] and A[i] = B[k-i+1], in which case A[i] is the result or A[i] = B[k-i] and A[i+1] B[k-i], in which case B[k-i] is the result Don On Nov 10, 10:07 am, shady sinv...@gmail.com wrote: Given two sorted arrays

[algogeeks] Re: spoj problem

2011-11-15 Thread Don
I don't think that your solution assures that the elevator stays in its bounds. Don On Nov 15, 12:49 pm, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: hi don please tell me where am i wrong in this maths in solving this question.      let x = number of times to press up button let y

[algogeeks] Re: spoj problem

2011-11-15 Thread Don
This input 100 1 5 5 91 Should output 20. Yours says Take the stairs. 100 1 5 5 89 Should output 76. Yours says Take the stairs. Don On Nov 14, 8:27 am, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem ishttp://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer

[algogeeks] Re: Interview question

2011-12-02 Thread Don
(!x || !(x^1)) !(x1) !((x|1)-1) (x*x)==x (x==(x==x))||(x==(x!=x)) etc. On Nov 29, 9:07 pm, Nitin Garg nitin.garg.i...@gmail.com wrote: *What are the different ways to say, the value of x can be either a 0 or a 1.* -- Nitin Garg Personality can open doors, but only Character can keep them

[algogeeks] Re: How random numbers are generated?

2011-12-05 Thread Don
statistical properties and often produce obvious patterns, particularly in the low-order bits. Better generators have larger state and therefore can have longer periods. Generators such as the Mersenne Twister, or George Marsaglia's multiply with carry. Don On Dec 5, 9:58 am, Prakash cegprak

[algogeeks] Re: Nice question

2011-12-13 Thread Don
The following is a dynamic programming solution to this problem. It builds up an array num[i][j] such that num[i][j] is the number of combinations of digits starting with digit j at position i. The answer is the sum of num[1][1]..num[9][1]. #include stdio.h int main(int argc, char* argv[]) {

[algogeeks] Re: Nice question

2011-12-13 Thread Don
The following is a dynamic programming solution to this problem. It builds up an array num[i][j] such that num[i][j] is the number of combinations of digits starting with digit j at position i. The answer is the sum of num[1][1]..num[9][1]. #include stdio.h int main(int argc, char* argv[]) {

[algogeeks] Re: Nice question

2011-12-13 Thread Don
One other observation: if any of the absolute differences was zero, it would print the same number more than once. Your algorithm is fine for n=5, but as n gets larger, the execution time increases exponentially. The dynamic programming algorithm is O(n). Don On Dec 13, 11:37 am, tech coder

[algogeeks] Re: Nice question

2011-12-13 Thread Don
Moheed, If n=3 and absdiff = {0,0}, your program says that there are 100 possible numbers. Can you show me at least 10 of them? Don On Dec 13, 12:24 pm, Moheed Moheed Ahmad mohe...@gmail.com wrote: To get a abs difference of 0 there are 10 ways similarly getting abs difference of 1

[algogeeks] Re: Nice question

2011-12-13 Thread Don
}, by your thinking there would be 4^9=262,144 possible numbers. In reality, the only possible numbers are 1717171717 2828282828 3939393939 6060606060 7171717171 8282828282 9393939393 If your algorithm gives an answer other than 7, keep working on it. Don On Dec 13, 1:46 pm, Gaurav Kumar gkuma

[algogeeks] Re: Nice question

2011-12-13 Thread Don
Trying the combinations is not necessary. See my solution above. Don On Dec 13, 3:59 pm, Gaurav Kumar gkuma...@gmail.com wrote: Thanks for pointing out the issue with my logic. What I am wondering is what is the general solution to finding the number of possible numbers? Is the only way

[algogeeks] Re: Return index of first mismatch bracket ( or )

2011-12-20 Thread Don
unmatched open paren. Compare the index of the first unmatched close paren and open paren and report the smaller one. Don On Dec 20, 8:40 am, zeroByZero shri.nit...@gmail.com wrote: In a given string arrary arr[] = ((()()) or any other string return index for which no match is found

[algogeeks] Re: find point lies in side circle

2012-01-05 Thread Don
Cut out the circle from the graph. The points on the cut-out circle are the answer. Don On Jan 5, 6:17 am, dabbcomputers dabbcomput...@gmail.com wrote: you are given with N points on graph. and a point A on graph and range R you have to find the points that lies within the radius of R from

[algogeeks] Re: A graph problem

2012-01-05 Thread Don
is the length of the shortest cycle. Don On Jan 5, 7:07 am, saurabh singh saurab...@gmail.com wrote: This problem is taken fromwww.codeforces.com.Whatcan be the possible approaches?? A smile house is created to raise the mood. It has *n* rooms. Some of the rooms are connected by doors. For each

[algogeeks] Re: finding all combination

2012-01-06 Thread Don
]; findSubset(i+1, sum-A[i]); --size; } } Call it like this: findSubset(4); Don On Jan 3, 5:26 am, atul anand atul.87fri...@gmail.com wrote: There is integer array like {1,2,4,5,6,1,2,4,3,5,7,2,1}. I want to find the possible combination which will sum to 4. input

[algogeeks] Re: finding all combination

2012-01-06 Thread Don
]; findSubset(sum-A[i], i+1); --size; } } Call it like this: findSubset(4); Don On Jan 3, 5:26 am, atul anand atul.87fri...@gmail.com wrote: There is integer array like {1,2,4,5,6,1,2,4,3,5,7,2,1}. I want to find the possible combination which will sum to 4. input

[algogeeks] Re: Binary Search Problem

2012-01-09 Thread Don
The intermediate value of start+end may be too large to store in an integer, even though start and end by themselves are in the valid range. If you know this to not be the case, you can use the simpler form. Don On Jan 8, 5:04 am, Sanjay Rajpal srn...@gmail.com wrote: In binary search, mid

[algogeeks] Re: algo qstn

2012-01-17 Thread Don
+1 Jaimedp On Jan 17, 1:05 pm, jaimedp jaim...@gmail.com wrote: 120 On Jan 17, 5:59 am, Umer Farooq the.um...@gmail.com wrote: 0 On 1/16/12, Ravi Ranjan ravi.cool2...@gmail.com wrote: An ant moves on a regular grid of squares that are coloured either black or white. The

[algogeeks] Re: probability of winning with two cards

2012-01-19 Thread Don
P= 8800/28561 ~= 0.308112461... On Jan 18, 7:40 pm, Sundi sundi...@gmail.com wrote: there are 52 cards.. there are 3 players a1,a2,a3 each player is given 2 cards each one of A=2...J=11,Q=12,K=13..a user wins if his sum of cards is greater then the other two players sum. find the probability

[algogeeks] Re: algo qstn

2012-01-19 Thread Don
int grid[200][200] = {{0}}; int x=100; int y=100; int d = 0; int count = 0; for(int i = 0; i 1018; ++i) { x += BCBA[d] - 'B'; y += CBAB[d] - 'B'; count += CA[grid[x][y]] - 'B'; d = (grid[x][y] ? BCDA[d] : DABC[d]) - 'A'; grid[x][y] ^= 1; } printf(%d\n, count); On Jan 18, 4:28 am, Ravi

[algogeeks] Re: probability of winning with two cards

2012-01-19 Thread Don
You are saying that a1 wins roughly 1 in 20 times? How does that make any sence? Don On Jan 19, 2:35 pm, Lucifer sourabhd2...@gmail.com wrote: @correction: Probalilty (a1 wins) = 24575/474552 = .051786 On Jan 20, 1:30 am, Lucifer sourabhd2...@gmail.com wrote: hoping that the cards

[algogeeks] Re: probability of winning with two cards

2012-01-22 Thread Don
I think that you are misreading the problem. A1 wins if his sum is larger than A2's sum and larger than A3's sum. A1's sum doesn't have to be larger than A2+A3. Don On Jan 22, 5:18 pm, Lucifer sourabhd2...@gmail.com wrote: @sundi.. Lets put is this way.. Probability of (a1 wins + a1 draws

[algogeeks] Re: Doubt regarding complexity (if comparison based sorting algorithm used)

2012-01-23 Thread Don
The Dutch Flag problem falls into the same category as radix sort, which is not a comparison-based sorting algorithm. Don On Jan 23, 1:26 am, atul anand atul.87fri...@gmail.com wrote: Hi all,     as we all know that any sorting algorithm based on comparison model has lower bound of nlogn i.e

[algogeeks] Re: Doubt regarding complexity (if comparison based sorting algorithm used)

2012-01-24 Thread Don
ever comparing one element in the array to another (ie or ). Don On Jan 23, 10:49 pm, atul anand atul.87fri...@gmail.com wrote: @Don : if i am not wrong ... American flag problem is closely related to radix sort not dutch flag. On Mon, Jan 23, 2012 at 11:16 PM, Don dondod...@gmail.com wrote

[algogeeks] Re: algo for number of Hamiltonian (undirected) cycles on the circulant graph C_n(1,2).

2012-01-25 Thread Don
@Dave: Can you tell us how you got there from the problem description? On Jan 25, 11:02 am, Dave dave_and_da...@juno.com wrote: @Manish: Let b(n) = a(n) - 2. Then b(n) = b(n-1) + b(n-2) - b(n-5). We can write this recurrence as a matrix multiplication as follows: --         --     --          

[algogeeks] Re: Minimum number of jumps to reach end

2012-01-26 Thread Don
From position i, move n such that n = arr[i] and n+arr[i+n] is maximized. Don On Jan 25, 11:03 pm, Sanjay Rajpal sanjay.raj...@live.in wrote: Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return

[algogeeks] Re: Minimum number of jumps to reach end

2012-01-27 Thread Don
Can anyone show me a case where the following greedy algorithm does not produce the optimal result: From position i, if you can move to the end, do it Otherwise make the legal move to location j which maximizes j+arr[j]. Don On Jan 25, 11:03 pm, Sanjay Rajpal sanjay.raj...@live.in wrote: Given

[algogeeks] Re: Minimum number of jumps to reach end

2012-01-27 Thread Don
to get to the end. Don On Jan 27, 12:23 pm, sravanreddy001 sravanreddy...@gmail.com wrote: @Don: The solution looks good... I can see that the greedy choice property is holding.. and its optimal too... max (j+a[J]) maximizing is leading us to the farthest possible position

[algogeeks] Re: Can anyone tell algorithm for solving sudoku

2012-01-30 Thread Don
to guess. Pick the cell with the smallest number of possible values. Plug them in one by one and try to solve from there. If it leads to a contradiction, back that guess out and try another. I think I posted code which does this a few months back. You can search for it if you are interested. Don On Jan

[algogeeks] Re: JAVA: Print all paths from root to leaf

2012-01-30 Thread Don
Right idea. But you only need to remove the last item once, right at the end of the function. Don On Jan 30, 1:01 am, atul anand atul.87fri...@gmail.com wrote: @Mihir : actually you are using linked listso you are keep on adding the nodes but not removing it..hence...you are getting wrong

[algogeeks] Re: kth largest element in two sorted arrays

2012-01-31 Thread Don
to determine if a[i] or b[k-i-1] is the final answer. Don On Jan 30, 1:45 pm, Ashish Goel ashg...@gmail.com wrote: Hi, I am trying to write code for this problem but having issues. Can you help Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652

[algogeeks] Re: Reverse Engg.

2012-01-31 Thread Don
. Without that, it is not even possible to recover c source which does the same thing as the executable, let along get back to anything which looks like the original code. Don On Jan 30, 11:20 am, Karthikeyan V.B kartmu...@gmail.com wrote: hi, can anyone tell me how i can convert exe back to c

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

2012-02-01 Thread Don
in the array. All steps are O(n) except for the sort, so the overall complexity is O(n*log n). Don On Feb 1, 2:58 am, Varun tewari.va...@gmail.com 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

[algogeeks] Re:

2012-02-02 Thread Don
It seems that it ought to print NONE but its actual behavior may be different due to rounding error. Was there something in particular you were asking about? Don On Feb 2, 12:24 pm, apurva gupta apurvagup...@gmail.com wrote: #includestdio.h int main() { float x=0.3, y=0.7; if(x0.3

[algogeeks] Re: Function Name Mismatch

2012-02-07 Thread Don
Provide an interface class for the client to access. The client needs to know the name of the method in the interface, but only the interface needs to know the name of the function in the server. Don On Feb 7, 8:38 am, Aman Kumar amanas...@gmail.com wrote: Hii to all If client want to make

[algogeeks] Re: How many ways n points can be connected

2012-02-08 Thread Don
for the pattern in the number of ways the edges can be selected and multiply it out. Don On Feb 7, 10:03 pm, rspr ravishanker@gmail.com wrote: Hi All, can there be a formulato which we can estimate how many ways (n-1) lines can connect n points in the same way how many ways n lines

[algogeeks] Re: How many ways n points can be connected

2012-02-08 Thread Don
set of edges can be generated, so to get the number of unique sets of edges, you have to divide by (n-1)!. Don On Feb 8, 11:43 am, sravanreddy001 sravanreddy...@gmail.com wrote: @Don: I had the similar approach, but I didn't think of dividing by (n-1)! Why is this needed? -- I think

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
, or change the second one from Right to Left. Don On Feb 9, 8:38 am, Rahul Menon menonrahul1...@gmail.com wrote: What does this function do? void function(Node **node){         if(*node!=NULL){                 function((*node)-Left);                 Node *temp;                 temp = (*node)-Left

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
Because it reverses one side twice and the other side not at all. It does a lot of work to accomplish nothing. Don On Feb 9, 9:06 am, Rahul Menon menonrahul1...@gmail.com wrote: How come it just reversed the root? I still dont get it! Rahul On Feb 9, 7:57 pm, Don dondod...@gmail.com wrote

[algogeeks] Re: determining if frequency is greater than n/2

2012-02-09 Thread Don
to examine at least n/2 elements to reach a conclusion. In some cases you must examine all n elements. Don On Feb 8, 1:45 pm, Prakhar Jain jprakha...@gmail.com wrote: Hello everyone, suppose we have an array of size n and a number, say x, and we have to determine whether the number x

[algogeeks] Re: how can we check for primality for very large number

2012-02-13 Thread Don
it for numbers up to 10^3000, but others have gone well beyond that. http://www.ellipsa.net/ Don On Feb 11, 8:52 am, rspr ravishanker@gmail.com wrote: How can we check for the primality fhttp://www.alpertron.com.ar/ECM.HTMor very large number like 10^20 or more. It is not stored in integer

[algogeeks] Re: suggestions?

2012-02-13 Thread Don
How about a program to play a game such as Othello. Each processor can work on scoring different moves, looking ahead several moves, and then the final scores can be compared to select the best move for the computer. Don On Feb 12, 9:58 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: hi, I

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

2012-02-14 Thread Don
, 343059613650, 1289904147324, 4861946401452, 18367353072152, 69533550916004, 263747951750360, 1002242216651368, 3814986502092304 Don On Jan 29, 3:58 am, Moheed Moheed Ahmad mohe...@gmail.com wrote: I know how to solve it programatically, can anybody pls help me to solve it using combinatorics

[algogeeks] Re: Finding closest double in a Btree

2012-02-20 Thread Don
Supraja, I think that your solution will work, but it does more work than is necessary. You don't need to traverse the entire tree. node findClosest(node root, double k) { node result = root; double diff = fabs(root-value - k); for(node loc = root; loc; loc = (loc-value k) ? loc-left :

[algogeeks] Re: Finding closest double in a Btree

2012-02-20 Thread Don
there is always a single path to follow, and recursion is not required. The iterative solution is O(depth of tree). On average, for a tree with n elements, that is O(log n). Don On Feb 20, 10:44 am, Don dondod...@gmail.com wrote: Supraja, I think that your solution will work, but it does more work than

[algogeeks] Re: Finding closest double in a Btree

2012-02-20 Thread Don
Yes, I am assuming a binary search tree. The problem is trivial otherwise. If it is just a binary tree, you visit each node and keep track of the closest. Don On Feb 20, 5:02 pm, Dave dave_and_da...@juno.com wrote: @Don: Aren't you assuming a binary _search_ tree? Only a binary tree

[algogeeks] Re: Finding closest double in a Btree

2012-02-21 Thread Don
, but in industry that is called anticipating the customer's needs. Don On Feb 20, 6:28 pm, Dave dave_and_da...@juno.com wrote: @Don: By that measure, it also is trivial if the tree is a BST. You just find the largest node x and the smallest one x and choose between them. But since

[algogeeks] Re: Finding closest double in a Btree

2012-02-21 Thread Don
would accept that. Putting main inside a class will not work either. Don On Feb 20, 5:24 am, Supraja Jayakumar suprajasank...@gmail.com wrote: Hi Question is given a binary tree and a key K, code to find the node with the closest value. I'd be happy to receive some feedback about my

[algogeeks] Re: MODULUS

2012-02-21 Thread Don
precision library such as NTL. Don On Feb 21, 8:40 am, Anurag Gupta anurag.gupta...@gmail.com wrote: how can we take mod by a very large number for example 100283 int mod = 100283; ans % mod is not working Please Help -- You received this message because you are subscribed

[algogeeks] Re: use of sentinel in linked list

2012-02-21 Thread Don
What are you using the sentinel for? A marker for the end of the list? A common way to implement a linked list is to use a sentinal as the head of a circularly linked list. Thus, an empty list is a pointer to the sentinal which is linked to itsself. The advantage is that there are fewer special

[algogeeks] Re: Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread Don
of the 2 adjacent balloons and downheap. Then the range at the top of the heap is the kth smallest contiguous sum. This is O(k * log n). Since k can be n*(n+1)/2, in the worst case this is O(n^2 log n). Don On Feb 21, 11:32 am, shady sinv...@gmail.com wrote: Problem link http://www.spoj.pl/ABACUS12

[algogeeks] Re: Longest Path in A Graph

2012-02-22 Thread Don
Beware of cycles. Don On Feb 22, 6:05 am, krishna kishore kknarenkris...@gmail.com wrote: Hi Gentle Men, Can any Please let me know How to Find a LONGEST PATH in a Graph ( directed or Undirected but unweighted ). INPUT: we have to give the Source vertex and Destination Vertex. OUTPUT

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Why are you using tail recursion when an iterative approach would be more efficient? Don On Feb 23, 3:41 am, rahul sharma rahul23111...@gmail.com wrote: struct node* SortedMerge(struct node* a, struct node* b) {   struct node* result = NULL;   /* Base cases */   if (a == NULL)      return

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
// Iterative merge struct node* SortedMerge(struct node* a, struct node* b) { struct node* head, tail; // Select first node if (a-data b-data) { head = tail = a; a = a-next; } else { head = tail = b; b = b-next; } // Merge lists while(a b) { if (a-data

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Is the desired behavior to remove duplicates? On Feb 23, 5:14 am, Karthikeyan V.B kartmu...@gmail.com wrote: Hi, this logic generates 10 10 20 25 .. and so on it doesn delete the duplicates in the result list -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Code to stop students from navigating during online examination

2012-02-24 Thread Don
This is not an algorithm question. I suggest announcing that any student who uses any electronic device to do anything other than take the test will fail the class. Have a TA or two sit in the back of the room and watch. Don On Feb 24, 4:04 am, Jasveen Singh jasveen.sing...@gmail.com wrote: hi

[algogeeks] Re: merge two sorted list

2012-02-24 Thread Don
You're right. I needed tail = tail-next; Before the closing } of the while loop. Good catch. Don On Feb 23, 10:25 pm, Ashish Goel ashg...@gmail.com wrote: tails needs to be updated in while loop also Best Regards Ashish Goel Think positive and find fuel in failure +919985813081

[algogeeks] Re: Code to stop students from navigating during online examination

2012-02-24 Thread Don
phone which can send and receive text messages there is still the potential to cheat. Don On Feb 24, 8:25 am, Jasveen Singh jasveen.sing...@gmail.com wrote: i agree it can be done but like in company training and GATE exam and even certification exams when the test starts everything else gets

[algogeeks] Re: Longest Path in A Graph

2012-02-24 Thread Don
// Assuming that the graph with n nodes is specified by an adjacency matrix edges[n][n] // where edges[i][j] is true if an edge exists from i to j // Implements depth-first search with restriction that each // node may only be visited once. int longestPath(int from, int to, int depth=0) { //

[algogeeks] Re: Longest Path in A Graph

2012-02-24 Thread Don
; } } Don On Feb 24, 9:42 am, Don dondod...@gmail.com wrote: // Assuming that the graph with n nodes is specified by an adjacency matrix edges[n][n] // where edges[i][j] is true if an edge exists from i to j // Implements depth-first search with restriction that each // node may only be visited

[algogeeks] Re: difference b/w static global variables and global variables

2012-02-27 Thread Don
In addition to the difference in scope, the standard requires that static variables be initialized to zero by default. Global variables are not required to be initialized by default. Don On Feb 25, 10:51 am, AMAN AGARWAL mnnit.a...@gmail.com wrote: Hi , Is there any difference b/w static

[algogeeks] Re: Pbm with rand() function

2012-02-27 Thread Don
-random integer in the range 0..n-1 int randRange(int n) { int result, div = RANDMAX / n; do { result = rand() / div; } while(result = n); return result; } Don On Feb 26, 10:10 am, karthikeya s karthikeya.a...@gmail.com wrote: RAND() func  returns value between 1 to INTMAX, as we know

[algogeeks] Re: Pbm with rand() function

2012-02-28 Thread Don
Use Mersenne Twister to generate 32-bit integers and do something like this: long long x = MT.gen(); x = (x32) + MT.gen(); Don On Feb 27, 5:58 pm, Prakash D cegprak...@gmail.com wrote: i've another doubt. what to do when I need to generate a random long long? On Mon, Feb 27, 2012 at 9:07

[algogeeks] Buying candy

2012-02-28 Thread Don
Little Bob likes candy, and he wants to buy all the candy he can get for the smallest price. At the store there is a big table with candy arranged in an NxN grid. Each candy has a price, Pij where i is the row and j is the column in which the candy is located. The store owner gives Bob N tags

[algogeeks] Re: Buying candy

2012-02-28 Thread Don
Yes, the tags constrain him to buy exactly one candy from each row and each column. There is a slightly better algorithm than Hungarian. Don On Feb 28, 11:33 am, Dave dave_and_da...@juno.com wrote: @Don: Based on your example, there seems to be an unstated requirement that Bob can and must buy

[algogeeks] Re: Buying candy

2012-02-28 Thread Don
to find the best solution, which is not true of any ad hoc or greedy algorithm. For years, the Munkres algorithm was the best known solution, but JVC is significantly faster than Munkres. Don On Feb 28, 11:39 am, Don dondod...@gmail.com wrote: Yes, the tags constrain him to buy exactly one candy from

[algogeeks] Re: Buying candy

2012-03-05 Thread Don
. Castanon, M.S. Bellovin. Comparison of 2-D Assignment for Sparse, Rect- angular, Floating Point, Cost Matrix. Journal of the SDI Panels on Tracking, Institute for Defense Analyses, Issue No.4, 1990, pp.4-81 to 4-97. On Mar 3, 10:15 pm, Dave dave_and_da...@juno.com wrote: @Don: I've looked

[algogeeks] Re: Suggest some Data Structure appropriate to the problem

2012-03-05 Thread Don
I want constant time sort, but I can't have that either. Don On Mar 5, 3:27 pm, Sehaj Singh Kalra sehaj...@gmail.com wrote: I want insertion , deletion, find (any general element) and min_element - all 4 operations in constant time order. Is there any data structure that can help me do

[algogeeks] Re: Suggest some Data Structure appropriate to the problem

2012-03-06 Thread Don
it into the minStack if it is less than or equal to the top value on the stack. When and item is deleted, pop the top value from the stack if it equals the value deleted. Then the minimum value is always on top of the stack. Don On Mar 5, 4:33 pm, Sehaj Singh Kalra sehaj...@gmail.com wrote: @SAMM : Nice

[algogeeks] Re: Math Question

2012-03-07 Thread Don
Theorem: In any set of (n+1) distinct integers there exists two who difference is divisible by n. Proof: Each of these integers leaves a remainder between 0 and n-1 inclusive upon division by n. Since there are n possible remainders and (n+1) integers that means there exist two which have the

[algogeeks] Re: Math Question

2012-03-07 Thread Don
Theorem: In any set of (n+1) distinct integers there exists two whose difference is divisible by n. Proof: Each of these integers leaves a remainder between 0 and n-1 inclusive upon division by n. Since there are n possible remainders and (n+1) integers that means there exist two which have the

[algogeeks] Re: Print all permutation of string

2012-03-10 Thread Don
not be the correct answer. If your string is Hello, the output will include Helol Helol I actually swapped the l's. You didn't notice, did you? If you don't want to include the same string twice I will leave it up to you to figure out how to avoid that. Don On Saturday, March 10, 2012 7:27:08 AM

[algogeeks] Re: Vertical Sum in a given Binary Tree

2012-03-20 Thread Don
// Assuming a vector container template class which allocates space as needed and allows negative index values vectorint result = {0}; void verticalSum(tree *root, int dist=0) { if (root) { result[dist] += root-val; verticalSum(tree-left, dist-1); verticalSum(tree-right, dist+1);

[algogeeks] Re: Check if one tree is sub tree of other

2012-03-20 Thread Don
would ultimately find no matching sub tree. If they are binary search trees, it could be more efficient. Did you mean to ask about binary search trees? Don On Mar 20, 7:24 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: How to check if one binary tree is a sub tree of other? Any Solution

[algogeeks] Re: MS QUESTION_LINKED LIST

2012-03-23 Thread Don
@Abhishek: What sorting algorithm are you going to use? On Mar 23, 3:02 pm, Abhishek Sharma jkabhishe...@gmail.com wrote: It is basically sorting the linked list. Do not change the first pointer of nodes and use the second pointer for sorting. return the pointer to the smallest element. That's

[algogeeks] Re: MS QUESTION_LINKED LIST

2012-03-23 Thread Don
A merge sort will be O(n*log n) and not use the extra memory required for a heap. Don On Mar 23, 3:11 pm, Ashish Goel ashg...@gmail.com wrote: actually, multimap can be avoided, each element of heap is key,value where key is the element and value is address and build heap on key. Best Regards

[algogeeks] Re: Find the maximum boxes which can fit each other?

2012-03-24 Thread Don
Build a graph in which each box is a vertex and there is an edge from A to B if B can fit inside A. Then use the longest path algorithm to find the solution. Don On Mar 24, 1:55 am, Ratan success.rata...@gmail.com wrote: You are given a lot of cuboid boxes with different length, breadth

[algogeeks] Re: Find the maximum boxes which can fit each other?

2012-03-24 Thread Don
There is more to it than a longest increasing subsequence because the greater than relationship is not transitive. Don On Mar 24, 3:05 am, atul anand atul.87fri...@gmail.com wrote: ok you need to put box into a box... so first requirnment willl be to sort on the basis of area of box. after

[algogeeks] Re: POW function in C++/C

2012-03-26 Thread Don
Why use pow to compute a square when * is significantly faster? Don On Mar 26, 6:09 am, shady sinv...@gmail.com wrote: Hi,  i am using pow() function in C++ to calculate square of 99937, but to my amazement it is giving one less than actual value. Since it returns double, i am adding 10e

[algogeeks] Re: [Directi] Two most distant element in tree

2012-03-26 Thread Don
If the longest path passes through the root of the tree, then the length of the path is the depth of the left subtree plus the depth of the right subtree. If the longest path does not pass through the root, then it is the max of the longest path in the left subtree or the right subtree. int

[algogeeks] Re: Google Question Invoice -bills

2012-03-27 Thread Don
a lot. Don On Mar 26, 11:32 pm, atul anand atul.87fri...@gmail.com wrote: @ankush: i told one approach above , but may i want clear . i am not saying this is the best approach to do so but it is one naive soln i came up with. so find all possible combination for each invoice and save it in some

[algogeeks] Re: need suggestions

2012-03-28 Thread Don
the best one. Don On Mar 27, 10:47 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, I am planning to implement a parallel version of the 0-1 knapsack problem. I tried reading up a bit and there are few suggestions here and there. However I would like to know if anyone has an idea

[algogeeks] Re: need suggestions

2012-03-28 Thread Don
. This would work better if you don't have a power of 2 number of processors. It also would reduce the tendancy for some processors to finish early and sit idle while one or two take longer to finish their portion of the work. Don On Mar 28, 9:51 am, Arun Vishwanathan aaron.nar...@gmail.com wrote

[algogeeks] Re: Adobe Noida Interview Question

2012-03-31 Thread Don
be formed from the matrix. Q2) Use a state machine to match the string. If using strstr is a requirement, I'll call it once, after I find the string, just to meet that technicality. Don On Mar 30, 10:47 am, Decipher ankurseth...@gmail.com wrote: This was asked from my friend in January for MTS

[algogeeks] Re: water-jug problem

2012-04-02 Thread Don
+1. You'll end up with a table of all states reachable with the set of buckets, and the minimum number of steps to reach each state. Don On Apr 1, 12:57 pm, bharat b bagana.bharatku...@gmail.com wrote:    A common puzzle asked during interviews is how to measure 4 liters of    water with just

<    1   2   3   4   5   6   >