[algogeeks] Re: Ball Hole science puzzle 24 may

2011-05-24 Thread Don
Fill the pipe with water so that the ball floats out. Don On May 24, 2:22 am, Lavesh Rawat wrote: > Ball Hole science puzzle SOLUTION > * * > > ** > *Your last good ping-pong ball fell down into a narrow metal pipe imbedded > in concrete one foot deep.How can you get it out und

[algogeeks] Re: strings

2011-05-26 Thread Don
But checking the count is a good first step. If the count doesn't match the result is false. If the count does match, you need to check further. I found that my test set ran 10x faster if I checked the count first. Don On May 26, 6:11 am, sunny agrawal wrote: > @senthil > nopes,

[algogeeks] Re: Puzzle

2011-05-27 Thread Don
quarter of the grid. It is not hard to assign them so that each time wins 3 of the games, meaning that it takes 11 games to assure a spot in the semi-finals. Here is a grid of results for one such outcome: X134 1X24 12X3 423X 1234 1234 1234 1234 Don On May 12, 1:44 pm, amit

[algogeeks] Re: Sudoku verification problem

2011-05-31 Thread Don
report that there are multiple solutions and provide one example. Don On May 28, 1:23 am, Dumanshu wrote: > Given a n by n matrix. Suggest an algorithm to verify its correctness > given a configuration. User can enter numbers only between 1 to n. > I need this in 2 ways - > 1. for the n

[algogeeks] Re: c output

2011-06-01 Thread Don
That may be true, but it is not guaranteed. Having multiple side affects between sequence points is undefined by the ANSI standard. Therefore an ANSI-compliant compiler could produce an executable which causes monkeys to fly out of your nose. Don On Jun 1, 11:27 am, anuj agarwal wrote: > T

[algogeeks] Re: Finding circle areas under dust bins

2011-06-01 Thread Don
eople. Repeat until everyone is covered. That is not guaranteed to minimize the number of bins, but it should be close. Don On May 31, 3:54 pm, Logic King wrote: > If the number of people is large then putting the dustbin in hexagonal > fashion as we do in mobile networks should minimize th

[algogeeks] Re: type 'int' unexpected

2011-06-02 Thread Don
You need parentheses around "int": sizeof(int) Don On Jun 2, 2:41 pm, asit wrote: > Please consider the following code > > // dequeue.cpp : Defines the entry point for the console application. > // > > #include "stdafx.h" > #include > #include >

[algogeeks] Re: MS Q

2011-06-02 Thread Don
Are we drawing a circle on the screen? In addition to Harshal's suggestions, try putting the center off the screen, but have part of the circle on the screen: x=-10 y=-20 r=100 Don On Jun 2, 9:19 am, Ashish Goel wrote: > Given a function to draw a circle with input paramters as co-o

[algogeeks] Re: c output

2011-06-03 Thread Don
An ANSI-compliant compiler is not required to generate an error for undefined code. The code syntax is correct. ANSI doesn't say what the compiler must do for undefined code, which is why it is undefined. The compiler can do anything. It might do what you expect, or it might not. Don On Jun

[algogeeks] Re: Million Numbers

2011-06-09 Thread Don
Create a range tree, pruning out as needed to stay in the memory constraint. Don On Jun 9, 6:24 am, Dumanshu wrote: > Given a file containing roughly 300 million social security numbers(9- > digit numbers) find a 9-digit number that isnt there in the file. You > have unlimited drive

[algogeeks] Re: is it correct??

2011-06-14 Thread Don
re to free the memory before "a" goes out of scope. Don On Jun 14, 9:39 am, amit wrote: > is such a declaration correct: > cin>>x; > int a[x]; -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to

[algogeeks] Re: Intuitive Understanding of XOR Operation

2011-06-14 Thread Don
thing can be used to encrypt data. If you xor each byte by a byte produced by a stream generator based on a secret key, the recipient can repeat the process and get the original data back. Don On Jun 13, 9:18 pm, Navneet Gupta wrote: > Hello, > > I would really appreciate if someone can

[algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Don
There is no reason to use recursion to search a binary tree. Don On Jul 12, 8:28 am, anonymous procrastination wrote: > Hello, > > Suppose you have to search a particular node in a binary tree. > The code is quite simple. Pick up any traversal and see if any node > matches the v

[algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Don
// Similar to other suggestions, but without tail recursion. ptr search(ptr root, int value) { ptr result = 0; while(root && !result) { result = (root->tag == value) ? root : search(root->left, value); root = root->right; } return result; } On Jul 12, 8:28 am,

[algogeeks] Re: swapping values in C

2011-07-12 Thread Don
Undefined code can do whatever it wants to. Don On Jul 12, 3:15 pm, tendua <6fae1ce6347...@gmail.com> wrote: > # include > > void swap(int *a, int *b) >         { >         *a ^= *b ^= *a ^= *b; >         } > > int main() >         { >         int a=4

[algogeeks] Re: swapping values in C

2011-07-12 Thread Don
To make it into valid code, break it into three operations: void swap(int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; } On Jul 12, 3:25 pm, Dave wrote: > @Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence > point rule, which says that

[algogeeks] Re: questions related to C

2011-07-12 Thread Don
To check for overflow, use condition: if (b > (maxuint-a)) return error; Where maxuint is the largest value which can be stored in an unsigned integer. Don On Jul 8, 5:50 am, vikas wrote: > Q1 - write a generic macro to swap two values (int,float,double,pointers as > well

[algogeeks] Poison River

2011-07-25 Thread Don
the other side of the river. How can the conditions be met for N=4? N=6? N=7? Don -- 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, sen

[algogeeks] Re: Hashing with strings

2011-07-26 Thread Don
inary tree withing the hash "bucket", and some use a rehash which stores one of the strings somewhere else. If a hash table becomes too full, it can become much less efficient, particularly if the method of resolving collisions is not well designed. Don On Jul 26, 7:49 am, syl wrote:

[algogeeks] Re: Poison River

2011-07-26 Thread Don
e, Jul 26, 2011 at 10:02 AM, Someshwar Chandrasekaran < > > > > somseka...@gmail.com> wrote: > > On Tue, Jul 26, 2011 at 3:19 AM, Don wrote: > > > > How can the conditions be met for N=4? N=6? N=7? > > > I believe this question cannot be solved for any val

[algogeeks] Re: Poison River

2011-07-26 Thread Don
It is a *pair* of shoes, after all. Don On Jul 26, 2:16 am, subashree sridhar wrote: > i think this problem can be solved easily for any no of ppl if they > are crossin the river using one shoe at a time :D :P > > On Jul 26, 10:38 am, sunny agrawal wrote: > > > For N=3, if

[algogeeks] Re: Hashing with strings

2011-07-26 Thread Don
file, any entries with a counter value of more than one would be duplicated words. This would be far faster than searching clear through the file for each word. Don On Jul 26, 8:13 am, syl wrote: > thanks for the info...i saw a method of using 4 bytes of string > together and then add them

[algogeeks] Re: size of self referential structure

2011-07-26 Thread Don
A reasonable guess would be 28 bytes. But the size of a structure is implementation dependent, and therefore, some other result could be correct as well. Don On Jul 26, 7:40 am, Puneet Gautam wrote: > #include > #include > struct node{ >        int a; >        char *b[5]; >

[algogeeks] Re: TIC TAC TOE

2011-07-28 Thread Don
Define "Most efficient". Most time efficient: Convert the board to a 9-digit integer in base 3 and use that to index into a table with the result precomputed. Most space efficient: Eight if statements Don On Jul 28, 8:01 am, Balaji S wrote: > Given a 3X3 matrix , with 1's 0

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-28 Thread Don
A point is inside a triangle iff: for each pair of vertices of the triangle, the point is on the same side of the line defined by those points as the third vertex of the triangle. Don On Jul 28, 1:47 pm, tech rascal wrote: > -- You received this message because you are subscribed to

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-28 Thread Don
// True if point (x,y) is above line defined by two points // If line is vertical, "above" is defined as to the right bool above(double lx1, double ly1, double lx2, double ly2, double x, double y) { return (lx1 != lx2) ? (y > (ly1+(x-lx1)*(ly2-ly1)/(lx2-lx1))) : (x > lx1); } // True if point 1

[algogeeks] Re: puzzle

2011-07-28 Thread Don
. They are certain to be the same because either one is the product of all 25 elements of the upper submatrix. So the question comes down to this: How many ways can you fill the upper 5x5 submatrix? As others have said, the answer is 2^((n-1)^2) or 33,545,432. Don On Jul 27, 11:57 pm, vetri

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Don
That should work, but I'd bet that my method is faster. Don On Jul 29, 6:02 am, Udit Gupta wrote: > Join the given point with all the vertices of the triangle and calculate the > area of each of the three sub-triangles thus formed > now compare the area of original triangle with

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Don
; (b < a*epsilon); } (Note that this assumes positive values.) Don On Jul 29, 1:21 pm, prashant bhutani wrote: > Yeah, the comparison of two floats will be a problem as the behaviour is > undefined and depends on the machine architecture and compiler. > > Thanks & Regards, > P

[algogeeks] Re: random generation

2011-08-01 Thread Don
a pseudo-random stream of output in the range 0..65535 using Marsaglia's "multiply with carry" algorithm. unsigned int mwc() { static unsigned int x = time(0); x = 63663 * (x&65535) + (x>>16); return x&65535; } Don On Jul 31, 4:39 am, Puneet Gautam wrote: >

[algogeeks] Re: random generation

2011-08-01 Thread Don
is something I doubt that most commercially produced Yahtzee programs can claim. Similar things could be done for card games to shuffle the deck. You could have the deck for the next game shuffling while the current game is being played. Don On Jul 31, 4:39 am, Puneet Gautam wrote: > Can we w

[algogeeks] Re: Algorithm complexity

2011-08-03 Thread Don
int main() { double n; printf("Enter n:"); scanf("%lf", &n); while(n > 1.0) n = log(log(n)); return 0; } On Aug 3, 9:41 am, Ajai Sathyan wrote: > Can u suggest a program with complexity O( log log n ) ? -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Tug of War

2011-08-04 Thread Don
As some have said, this is NP, so for larger values of N it takes a very long time. For N=20 it runs quite quickly. // True if some set of strengths from s[n] sum to t bool divide(unsigned int *s, int n, int t) { if (t == 0) return true; // We reached the goal if (n =

[algogeeks] Re: Circle

2011-08-05 Thread Don
// Draw a circle with center (x,y) and radius r circle(int x, int y, int r) { int a = 0; int b = r; while(a <= b) { // Draw the current location in all 4 quadrants plot(x+a, y+b); plot(x-a, y+b); plot(x+a, y-b); plot(x-a, y-b); plot(x+b, y+a); plot(x-b, y+a);

[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 wrote: > I have read that Hash ta

[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
the binary representation. Don On Nov 14, 12:06 am, Ankur Goel 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 t

[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 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. > > * > #inclu

[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 wrote: > Given two sorted arra

[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 wrote: > Given two sorted arra

[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 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 wrote: > problem ishttp://www.spoj.pl/problems/ELEVTRBL/ > and my solution is give wrong an

[algogeeks] Re: Interview question

2011-12-02 Thread Don
(!x || !(x^1)) !(x>>1) !((x|1)-1) (x*x)==x (x==(x==x))||(x==(x!=x)) etc. On Nov 29, 9:07 pm, Nitin Garg 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 open" -- You r

[algogeeks] Re: How random numbers are generated?

2011-12-05 Thread Don
on and have bad 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:5

[algogeeks] Re: Find Largest number in log(n)

2011-12-12 Thread Don
No. To find the largest number in an unsorted array requires looking at each number, which is order n by definition. Don On Dec 12, 10:02 am, sagar pareek wrote: > Hi every one. > > Can we find largest number from an unsorted array in log(n) ? > > -- > **Regards > SAGAR PARE

[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 int main(int argc, char* argv[]) { int

[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 int main(int argc, char* argv[]) { int

[algogeeks] Re: Nice question

2011-12-13 Thread Don
There should be 39 combinations with that input. You are missing numbers which include the digit zero, such as 14610, 30278, and 52056. Don On Dec 13, 11:37 am, tech coder wrote: > I tried the problem and written the code for it . it is in java. it is > printing all the possible numbers &

[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 wrote: > To get a abs difference of 0 there are 10 ways > similarly getting abs difference of 1 there are 9x2 w

[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 wrote:

[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 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 is to

[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 wrote: > In a given string arrary arr[] = "((()())" or any other string return > index for which no match is found as for this ex

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

[algogeeks] Re: A graph problem

2012-01-05 Thread Don
length of the shortest cycle. Don On Jan 5, 7:07 am, saurabh singh 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

[algogeeks] Re: finding all combination

2012-01-06 Thread Don
= A[i]; findSubset(i+1, sum-A[i]); --size; } } Call it like this: findSubset(4); Don On Jan 3, 5:26 am, atul anand 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 : {1,2,4,5,6,

[algogeeks] Re: finding all combination

2012-01-06 Thread Don
= A[i]; findSubset(sum-A[i], i+1); --size; } } Call it like this: findSubset(4); Don On Jan 3, 5:26 am, atul anand 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 : {1,2,4,5,6,

[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 wrote: > In binary search, > > mid = sta

[algogeeks] Re: algo qstn

2012-01-17 Thread Don
+1 Jaimedp On Jan 17, 1:05 pm, jaimedp wrote: > 120 > > On Jan 17, 5:59 am, Umer Farooq wrote: > > > > > 0 > > > On 1/16/12, Ravi Ranjan wrote: > > > > An ant moves on a regular grid of squares that are coloured either black > > > or > > > white. > > > The ant is always oriented in one of 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 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 of a1 being t

[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

[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 wrote: > @correction: > > Probalilty (a1 wins) = 24575/474552 = .051786 > > On Jan 20, 1:30 am, Lucifer wrote: > > > > > hoping that the ca

[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 wrote: > @sundi.. > > Lets put is this way.. > > Probability of (

[algogeeks] Re: probability of winning with two cards

2012-01-23 Thread Don
ing. Thus P(p1 wins) = 0.30850919745967... Don On Jan 23, 7:34 am, Lucifer wrote: > @Don and Sundi.. > > As Don pointed out, all we are looking for is: >  sum of a1 > sum of a2 >  sum of a1 > sum of a3 > > Assumption: > 1) The 2 cards picked for a particular p

[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 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
thout ever comparing one element in the array to another (ie < or >). Don On Jan 23, 10:49 pm, atul anand 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 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 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 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 > ret

[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 wrote: > Given an ar

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

2012-01-27 Thread Don
get to the end. Don On Jan 27, 12:23 pm, sravanreddy001 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, > > but.. i

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

2012-01-30 Thread Don
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 wrote: > @Mihir : actually you are using linked listso you are keep on adding > the nodes but not removing it..hence...you are getting wrong output.. >

[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 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&quo

[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" wrote: > hi, > > can anyone tell me how i can convert exe back to

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

2012-02-01 Thread Don
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 wrote: > I was asked this question sometime during an interview. > > WE have an array of known length. The elements in array can be repetitive. > now sort the array based

[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 wrote: > #include > > int main() > { > float x=0.3, y=0.7; > &g

[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 wrote: > Hii to all > > If client want to make a functio

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

2012-02-08 Thread Don
look 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 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 can &

[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 wrote: > @Don: > > I had the similar approach, but I didn't think of "dividing by (n-1)!" > Why is this needed? -- I think th

[algogeeks] Re: Binary Search Tree Question

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

[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 wrote: > How come it just reversed the root? I still dont get it! > > Rahul > > On Feb 9, 7:57 pm, Don wrote: > > > > &g

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

2012-02-09 Thread Don
have 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 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 is pre

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

2012-02-13 Thread Don
used 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 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 So int

[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 wrote: > hi, > > I need t

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

2012-02-14 Thread Don
/ntl/ Don On Feb 11, 8:52 am, rspr wrote: > How can we check for the primality for very large number like 10^20 or > more. It is not stored in integer So integer operation would not work > on it. -- You received this message because you are subscribed to the Google Groups "Algorith

[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 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
re 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 wrote: > Supraja, > > I think that your solution will work, but it does more work than is &g

[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 wrote: > @Don: Aren't you assuming a binary _search_ tree? Only a binary tree > was specifie

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

[algogeeks] Re: Finding closest double in a Btree

2012-02-21 Thread Don
piler would accept that. Putting main inside a class will not work either. Don On Feb 20, 5:24 am, Supraja Jayakumar 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 ab

[algogeeks] Re: MODULUS

2012-02-21 Thread Don
n extended precision library such as NTL. Don On Feb 21, 8:40 am, Anurag Gupta 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 becaus

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

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

2012-02-21 Thread Don
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 wrote: > Problem link <http://www.spoj.pl/ABACUS12/status/

[algogeeks] Re: Longest Path in A Graph

2012-02-22 Thread Don
Beware of cycles. Don On Feb 22, 6:05 am, krishna kishore 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: it should

[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 wrote: > struct node* SortedMerge(struct node* a, struct node* b) > { >   struct node* result = NULL; > >   /* Base cases */ >   if (a == NULL) >      r

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

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

[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 wrote: > hi guys i am a final y

[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 wrote: > tails needs to be updated in while loop also > > Best Regards > Ashish Goel > "Think positive and find fuel in failure"

  1   2   3   4   5   6   >