[algogeeks] Re: question at K10

2011-02-15 Thread Don
void change() { printf(10); while(1) {} } On Feb 15, 10:17 am, Balaji S balaji.ceg...@gmail.com wrote: Insert only one line in the function change() so that the output of the program is 10. You are not allowed to use exit(). You are not allowed to edit the function main() or to pass the

[algogeeks] Re: question at K10

2011-02-15 Thread Don
A semicolon is valid in the middle of a line in C or C++. For instance, no one says that for(i = 0; i 10; ++i) is three lines of code. Don On Feb 15, 11:31 am, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: after termination of semicolon , that will be considered a separate line i guess

[algogeeks] Re: Help

2011-02-15 Thread Don
Mike Johnson wrote: Plesae rite a program for me to find prime nummers. It should be recursive prorgram. What duz that mean? If u type a nummer like 10 it should say 1 is prime, 2 is prime, 3 is prime, 4 is not prime up to 10. This iz not homewurk I just thout of it myself. Lol. /* Sure

[algogeeks] Re: General Sorting Header File Adobe

2011-02-16 Thread Don
templateclass Iterator, class Compare void sort(Iterator first, Iterator last, Compare cmp); On Feb 16, 5:57 am, bittu shashank7andr...@gmail.com wrote: write header file for sorting general element. it can sort any type of object(int,float,complex number, objects) Thanks Shashank -- You

[algogeeks] Re: Puzzle For Puzzled Minds - Robots

2011-02-16 Thread Don
Fast: RIGHT // Move at speed of 1 space every other turn GOTO Fast Both robots will move to the right, but the one on the left will eventually find the oil left by the other robot and begin moving faster, eventually catching up with the other robot. Don -- You received this message because you

[algogeeks] Re: Maze labyrinth Solve Puzzle WAP Efficiently

2011-03-02 Thread Don
class coord { public: int x; int y; }; class SolveMaze { public: SolveMaze() { location.x = location.y = 0; } bool Explore(); private: listcoord visited; coord location; }; bool Explore() { // Determine if we've already been here if (visited.found(location)) return false;

[algogeeks] Re: Tough Problem of Probability ..Surely Will Stuck ..So Think More More

2011-03-02 Thread Don
Game 2 is better if p 0.5. P(win game 1) = p P(win game 2) = p^3 + 3(p^2 * (1-p)) To find the solution, solve for p when p^3 + 3(p^2 * (1-p)) p Which simplifies to 3p - 2p^2 1 Which is true when p 0.5 On Mar 1, 5:15 pm, bittu shashank7andr...@gmail.com wrote: You have a basketball hoop

[algogeeks] Re: brain teaser

2011-03-03 Thread Don
or even, as indicated by the previous prisoner. Each prisoner in line must keep track of the current state, odd or even, which changes each time someone behind him indicates having a red hat. Don On Mar 3, 2:18 am, freecoder rajuljain...@gmail.com wrote: You are one of 20 prisoners on death row

[algogeeks] Re: Maze labyrinth Solve Puzzle WAP Efficiently

2011-03-03 Thread Don
The problem with BFS is that you have to remember how to get from where you are to every other point you have explored. Of course, the problem with a depth-first search is that in an unbounded maze, you may never reach a point even if it is very close to your starting point. Don On Mar 3, 1:31

[algogeeks] Re: A Billion Number Question

2011-03-17 Thread Don
This only works if the file is sorted. If the file starts out with values 5,7,6,... and never contains another 7, the result will be 7, which is in the file. On Mar 17, 12:19 pm, arpit.gupta arpitg1...@gmail.com wrote: read the first no. . now ans= first no +1; if now ans is encountered while

[algogeeks] Re: random number generator

2011-03-17 Thread Don
bool uniform() { static bool state = true; state = !state; return state ^ nonuniform(); } On Mar 17, 9:24 am, saurabh agrawal saurabh...@gmail.com wrote: Given a  function which returns true 60% time and false 40% time. Using this function you have to write a function which returns true

[algogeeks] Re: random number generator

2011-03-22 Thread Don
There is no upper bound on the runtime of this function. On Mar 20, 4:33 pm, Jammy xujiayiy...@gmail.com wrote: clearly the prob. of getting true|false and false|true are equal to 0.6*0.4. Therefore the following code works, bool uniform(){    bool f1;    bool f2;    do{        f1 =

[algogeeks] Re: subgraph

2011-03-24 Thread Don
edges from your current location by traversing the linked list. This should take about 15 megabytes of memory, which most computers can handle easily. Don On Mar 24, 11:21 am, snehal jain learner@gmail.com wrote: You have to create a graph in most efficient way from relationship of nodes

[algogeeks] Re: predominant colour

2011-03-24 Thread Don
Even if N is one? On Mar 24, 12:25 pm, balaji a peshwa.bal...@gmail.com wrote: i think its red On Thu, Mar 24, 2011 at 10:44 PM, snehal jain learner@gmail.com wrote: You are given a blue segment S of length n. There are n points p_i (0 = i n) distributed uniformly at random. You

[algogeeks] Re: finds a pair of close numbers

2011-04-06 Thread Don
// O(n) solution using binning findClose(int n, double A[n]) { // Find min and max min = max = A[0]; for(i = 1; i n; ++i) { if (A[i] max) max = A[i]; if (A[i] min) min = A[i]; } // Set up bins int bins = n-1; double binWidth = (max - min) / bins; double binTable[bins]

[algogeeks] Re: Please help in verifying the speed of this algorithm - factorizing or prime finder.

2011-04-06 Thread Don
The General Number Field Sieve is the fastest known method of factoring large numbers, but the elliptic curve method may be faster in some cases. Either one is much faster than your method. Don On Apr 6, 12:58 pm, harish hareeshgn...@gmail.com wrote: Hi all, I have developed an algorithm

[algogeeks] Re: C puzzle

2011-04-06 Thread Don
In fn, ptr is a local variable passed by value. Changing ptr in the function does not change anything in main. Don On Mar 31, 10:35 pm, navin navin.myhr...@gmail.com wrote: see this c code. #includestdio.h void fn (int *ptr) {        const int val=100;        ptr=val;} void fn1(int *ptr

[algogeeks] Re: Please help in verifying the speed of this algorithm - factorizing or prime finder.

2011-04-08 Thread Don
on trial division would take longer than your computer will last. Don On Apr 7, 9:11 am, harish hareeshgn...@gmail.com wrote: Hi All, I got a reply at another forum; here is the link for thathttp://stackoverflow.com/questions/5581040/i-have-a-new-algorithm-to-... .. Don i believe you

[algogeeks] Re: Permutation of a string

2011-04-12 Thread Don
int main(int argc, char* argv[]) { char string[13]; char tmp[13]; int len, i, j, k, n; printf(Length of string: ); fgets(string, 13, stdin); sscanf(string, %d, len); if (len 12) len = 12; printf(Enter string: );

[algogeeks] Re: Permutation of a string

2011-04-12 Thread Don
int main(int argc, char* argv[]) { char string[13]; char tmp[13]; int len, i, j, k, n=1; printf(Length of string: ); fgets(string, 13, stdin); sscanf(string, %d, len); if (len 12) len = 12; printf(Enter string: );

[algogeeks] Re: finding n numbers having particular sum

2011-04-18 Thread Don
const int setSize = 20; int set[setSize] = { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; const int sum = 150; int rec[setSize]; int recCount = 0; int subset=0; void search(int *set, int setSize, int sum) { int i; if (sum == 0) { printf(Subset %d:

[algogeeks] Re: Basic Algorithms!!

2011-04-19 Thread Don
Knuth, The Art of Computer Programming On Apr 19, 4:06 am, Vishnutej mylavarapu.vishnu...@gmail.com wrote: Hello everyone, Wat according to u are the basic algorithms that a programmer should know for sure? If possible just let me know of the resource in which it is best explained. Thanks

[algogeeks] Re: JigSaw Puzzle

2011-04-25 Thread Don
First you need a Piece class to represent one piece of a puzzle. Each piece has four sides, each one with a unique outline which will only connect to one other piece. Edge sides have an edge outline. Each side also has a piece id attribute called adjacent to store the value of the piece it

[algogeeks] Re: sort in minimum cost

2011-04-25 Thread Don
I don't understand your example. If the input has only one 3, and the output has more than one, you have not sorted the elements. Do you mean alter the elements to make the array non-decreasing? Don On Apr 25, 4:21 am, snehal jain learner@gmail.com wrote: Given n elements, sort the elements

[algogeeks] Re: Stroustrup C++ BOOK

2011-04-27 Thread Don
I have the first edition signed by Stroustrup. I know that doesn't help you, but it is kind of cool, at least if you are an Algorithm Geek. Don On Apr 23, 8:31 am, UMESH KUMAR kumar.umesh...@gmail.com wrote: hi. Do you have anybody C++ by Stroustrup e-book please send on group. Thanks

[algogeeks] Re: N queen problem in 3D I want guidelines to solve problem

2011-04-27 Thread Don
of the rows already contain a queen. When you place a queen you must update (increment) all of the rows for that location, and when you remove it, you must decrement the counts. Don On Apr 27, 3:08 am, ARM1610 ashishrmod...@gmail.com wrote: Hello all,          I'm not getting how to solve a 3 d

[algogeeks] Re: A SIMPLE C++ PROGRAM.

2011-05-03 Thread Don
such code. Don On Apr 29, 3:31 am, MANNU manishkr2...@gmail.com wrote: *Can anyone please explain me the output of this program:* int x=1; int y=x++ + ++x + ++x + x++; couty; coutx; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

[algogeeks] Run for a google years

2011-05-06 Thread Don
What is the shortest single line in a C program which will take more than a google years to execute, but will eventually complete? You are permitted to have code before or after the line, but execution of the code must remain on that line, meaning no function calls, etc. Assume a processor which

[algogeeks] Re: Run for a google years

2011-05-09 Thread Don
for(; p n; p = ++a[p] ? 0 : p + 1); return 0; } The array of 49 bytes provides 392 bits of state, which will take more than the 2^387 cycles available in a google years. If the processor takes 9 operations to execute the loop, a value of n=48 would be sufficient. Don On May 7, 12:24 pm, Dave

[algogeeks] Re: Test Cases

2011-05-10 Thread Don
with integers, the case 4 below is good, given r b. Don On May 10, 11:12 am, Praveen Kumar praveen97...@gmail.com wrote: cases would be: 1. division by 0 raises an appropriate Exception 2. dividing 0 by any number should result in 0 3. dividing any number by 1 should give the same number 4. a = b*q + r

[algogeeks] Re: Run for a google years

2011-05-11 Thread Don
certainly meets the requirements of the problem, even if it is excessive. Don On May 11, 7:11 am, Aamir Khan ak4u2...@gmail.com wrote: On Mon, May 9, 2011 at 8:31 PM, Don dondod...@gmail.com wrote: That would do it if you have a 64-bit type, which most implementations have, but the standard does

[algogeeks] Re: Problem

2011-05-11 Thread Don
. Then try to divide the number by small primes. Then use one of the factoring algorithms such as the General Number Field Sieve to find factors. Don On May 11, 8:55 am, Harshit Gangal harshit.gan...@gmail.com wrote: How can we calculate the number of divisors a number have in minimum time

[algogeeks] Re: prim problem

2011-05-16 Thread Don
No idea. It would help to tell us what it is intended to do and what it is actually doing, and maybe include the main function so we can see how it is called and how the global variables are initialized. On May 15, 1:45 pm, Edu edu.cv...@gmail.com wrote: Hi, this should be working, where is the

[algogeeks] Re: how to find a smallest prime bigger than a given number

2011-05-18 Thread Don
Yes. Use a sieve. Don On May 17, 11:36 pm, wujin chen wujinchen...@gmail.com wrote: @Dave, thanks for your reply. i know that, i can only check from 6*n - 1 and 6*n + 1.. assume that, n=1 , and we begin from k=1667, the number needed to check is 10001,10003 but to determin 10001

[algogeeks] Re: strings

2011-05-19 Thread Don
bool interleaved(char *s1, char *s2, char *s3) { return (!*s1 !*s2 !*s3) || // Base case, all strings are empty (*s1 (*s1 == *s3) interleaved(s1+1,s2,s3+1)) || // First character of s1 is next in s3 (*s2 (*s2 == *s3) interleaved(s1,s2+1,s3+1));// First character of s2 is next in

[algogeeks] Re: strings

2011-05-19 Thread Don
bool interleaved(char *s1, char *s2, char *s3) { // Base case, all strings are empty return (!s1[0] !s2[0] !s3[0]) || // First character of s1 is next in s3 (s1[0] (s1[0] == s3[0]) interleaved(s1+1,s2,s3+1)) || // First character of s2 is next in s3 (s2[0] (s2[0] == s3[0])

[algogeeks] Re: strings

2011-05-20 Thread Don
This is the same algorithm as my previous solution. Both produce the correct result, but this one does not have tail recursion, so it will run faster. bool interleaved2(char *s1, char *s2, char *s3) { while(1) { if (!s1[0] !s2[0] !s3[0]) return true; if (s1[0] == s3[0]) {

[algogeeks] Re: strings

2011-05-20 Thread Don
= aa s3 = aaab Adding code at the beginning to be sure that s3 has the same number of instances of each character as s1 and s2 would be quick and would make that case much faster. Don On May 20, 10:12 am, Don dondod

[algogeeks] Re: strings

2011-05-20 Thread Don
Your iterative solution does not work in cases where both s1 and s2 have the next character in s3, but only choosing the s2 character next will result in correct interleaving. s1 = ab s2 = axb s3 = axabb Your iterative solution will say that these are not interleaved, but they really are. Don

[algogeeks] Find closest point

2011-05-23 Thread Don
If I have a big database of points on the surface of the earth, each one represented as a latitude and longitude, provide an efficient algorithm to find the point closest to a requested location. Be sure to consider angle wrap. Don -- You received this message because you are subscribed

[algogeeks] Re: Find closest point

2011-05-24 Thread Don
I'm more interested in finding a good data structure to store the points so that it is quick to narrow down the search to the points which are fairly close. Think of a database with millions of points, and there is not time to compute a distance to each one. Don On May 24, 8:15 am

[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 lavesh.ra...@gmail.com 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

[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 sunny816.i...@gmail.com wrote: @senthil

[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
, or report that there are multiple solutions and provide one example. Don On May 28, 1:23 am, Dumanshu duman...@gmail.com 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

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

[algogeeks] Re: Finding circle areas under dust bins

2011-06-01 Thread Don
. 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 crazy.logic.k...@gmail.com wrote: If the number of people is large then putting the dustbin in hexagonal fashion as we do in mobile networks should

[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 lipu...@gmail.com wrote: Please consider the following code // dequeue.cpp : Defines the entry point for the console application. // #include stdafx.h #include iostream #include deque #include algorithm using

[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 ashg...@gmail.com wrote: Given a function to draw a circle with input paramters

[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 1, 1

[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 duman...@gmail.com 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

[algogeeks] Re: is it correct??

2011-06-14 Thread Don
a goes out of scope. Don On Jun 14, 9:39 am, amit amitthecoo...@gmail.com wrote: is such a declaration correct: cinx; int a[x]; -- 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

[algogeeks] Re: Intuitive Understanding of XOR Operation

2011-06-14 Thread Don
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 navneetn...@gmail.com wrote: Hello, I would really appreciate if someone can help me get an intuitive understanding

[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 opamp1...@gmail.com 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

[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 stdio.h void swap(int *a, int *b)         {         *a ^= *b ^= *a ^= *b;         } int main()         {         int a=45, b= 56; //      a ^= b ^= a ^= b;         swap

[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 dave_and_da...@juno.com wrote: @Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence point

[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 mehta...@gmail.com wrote: Q1 - write a generic macro to swap two values (int,float,double,pointers as well

[algogeeks] Poison River

2011-07-25 Thread Don
on 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, send email

[algogeeks] Re: Hashing with strings

2011-07-26 Thread Don
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 abeygau...@gmail.com wrote: can

[algogeeks] Re: Poison River

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

[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 subashreesrid...@gmail.com 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 sunny816.i...@gmail.com

[algogeeks] Re: Hashing with strings

2011-07-26 Thread Don
, 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 abeygau...@gmail.com wrote: thanks for the info...i saw a method of using 4 bytes of string together and then add

[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 puneet.nsi...@gmail.com wrote: #includestdio.h #includestddef.h struct node{        int

[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 techrascal...@gmail.com wrote: -- You received this message because you

[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 uditgupta...@gmail.com 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

[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 this assumes positive values.) Don On Jul 29, 1:21 pm, prashant bhutani prashantbhutani2...@gmail.com 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, Prashant Bhutani Senior

[algogeeks] Re: random generation

2011-08-01 Thread Don
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 * (x65535) + (x16); return x65535; } Don On Jul 31, 4:39 am, Puneet Gautam puneet.nsi...@gmail.com wrote: Can we write a code to generate

[algogeeks] Re: random generation

2011-08-01 Thread Don
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 puneet.nsi...@gmail.com wrote: Can we write

[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 ajaisath...@gmail.com wrote: Can u suggest a program with complexity O( log log n ) ? -- You received this message because you are subscribed to the

[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: Probability Puzzle

2011-08-08 Thread Don
The answer is 17 in 18, because flipping 5 heads in a row is evidence that the probability is high that we have the coin with two heads. Don On Aug 7, 12:34 pm, Algo Lover algolear...@gmail.com wrote: A bag contains 5 coins. Four of them are fair and one has heads on both sides. You randomly

[algogeeks] Re: Probability Puzzle

2011-08-08 Thread Don
coins, for a total of 72 outcomes. 68 of those are heads, so the answer to the puzzle is 68 of 72, or 17 of 18. Don On Aug 8, 2:36 am, Shachindra A C sachindr...@gmail.com wrote: @brijesh *first five times* is mentioned intentionally to mislead i think. I vote for 3/5. Moreover, 17/80 doesn't

[algogeeks] Re: what is complexity of func(p)

2011-08-09 Thread Don
I don't think that this function is doing what you want it to do. If you ask for a^b, it returns a^1 in most cases. Try this instead. int power(int a, int b) { int result = 1; if (b == 1) result = a; else if (b1) { result = power(a,b/2); result *= result; if (b%2) result *=

[algogeeks] Re: need a pgm pls help me

2011-08-09 Thread Don
#include stdio.h #include stdlib.h int main() { char inFileName[80]; char outFileName[80]; int numSegments; int bytesPerSegment; printf(Enter file name:); fgets(inFileName,80,stdin); printf(Enter number of segments:); scanf(%d, numSegments); FILE *f = fopen(inFileName, rb);

[algogeeks] Re: Closest ancestor of two nodes

2011-08-09 Thread Don
tree closestSharedAncestor(tree root, tree node1, tree node2, int result) { tree returnValue = 0; if (root) { if (root == node1) result += 1; if (root == node2) result += 2; int sum = 0; tree returnLeft = closestSharedAncestor(root-left, node1, node2, sum); if

[algogeeks] Re: suggest simple code for

2011-08-10 Thread Don
int depth(node *root) { return root ? max(depth(root-left), depth(root-right)) : 0; } On Aug 8, 8:03 am, jagrati verma jagrativermamn...@gmail.com wrote:  finding the depth or height of a tree. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: suggest simple code for

2011-08-10 Thread Don
int depth(node *root) { return root ? 1+max(depth(root-left), depth(root-right)) : 0; } On Aug 8, 8:03 am, jagrati verma jagrativermamn...@gmail.com wrote:  finding the depth or height of a tree. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: suggest simple code for

2011-08-10 Thread Don
I do love functions that start with return. Don On Aug 10, 10:09 am, Dave dave_and_da...@juno.com wrote: @Don: Beautiful! Dave On Aug 10, 10:03 am, Don dondod...@gmail.com wrote: int depth(node *root) {   return root ? 1+max(depth(root-left), depth(root-right)) : 0; } On Aug 8

[algogeeks] Re: Problems on Linked List

2011-08-10 Thread Don
Q1: The function below reverses a linked list in place. Call it on one of the lists, compare the resulting list to the other list. Then call it again to put the list back in its original order. list Reverse(list head) { list T, prv, nxt; prv = head; for(T = head-next; T; T = nxt) {

[algogeeks] Re: Design a concurrent hash table

2011-08-11 Thread Don
interface. The write interface would attempt to get the semaphore, and if successful, write the data and then release the semaphore. If it failed, it would return a failure notice to the caller. The read interface would check the semaphore and if it was open, get the data. Don On Aug 11, 5:15 am, Navneet

[algogeeks] Re: Jumping Puzzle

2011-08-11 Thread Don
int A[100]; int dist[100]; int N; void findDist(int p, int d) { if (d dist[p]) { dist[p] = d; for(int i = 0; i p; ++i) if ((i+A[i]) = p) findDist(i,d+1); } } int main(int argc, char*

[algogeeks] Re: reverse

2011-08-11 Thread Don
What exactly do you mean by reverse a number? Please define what that means and give an example. Don On Aug 11, 12:13 pm, Rajeshwar Patra rajeshwarpa...@gmail.com wrote: how can we reverse a number using bitwise operators? -- *Rajeshwar Patra,* *MCA final year,* *Nit Durgapur* -- You

[algogeeks] Re: Math Quiz

2011-08-11 Thread Don
2 On Aug 11, 1:26 pm, Mani Bharathi manibharat...@gmail.com wrote: ABCD is a parallelogram and E is the middle point of side AD EC meets BD at O. If the area if the parallelogram is 24 units then the area of  EOD is ? -- You received this message because you are subscribed to the Google

[algogeeks] Re: Hash

2011-08-11 Thread Don
Yes. Linear probing, if done in the usual way, will end up at 2 if the hash function returned values 1,2,7,8, 9, or 10. That is 6 of the 10 possible values, so if each one is equally likely, the probability is 0.6. Don On Aug 11, 3:04 pm, aditi garg aditi.garg.6...@gmail.com wrote: cud u xplain

[algogeeks] Re: Non recursive preorder and postorder

2011-08-15 Thread Don
It can be done without using a stack, by using the pointers in the node to keep track of the path back up the tree. The algorithm will temporarily modify the tree, but when completed the tree will be restored to its original state. Don On Aug 15, 8:07 am, rohit raman.u...@gmail.com wrote: Can

[algogeeks] Re: program puzzle

2011-08-15 Thread Don
#include ctype.h #include string.h int main(int argc, char* argv[]) { char line[500]; char tmp[500]; char *words[100]; int wordCount = 0; char *p, *wordStart=0; printf(Enter string:); fgets(line,500,stdin); for(p = line; *p; ++p)

[algogeeks] Prime numbers

2011-08-16 Thread Don
I wrote a program to print prime numbers, but it is not very fast. Can someone help me figure out why? #include stdio.h /* This program implements a blindingly fast algorithm to find prime numbers, using an elegant recursive method. */ int _(int n, int m, int d, int t=0) { int r; if

[algogeeks] Re: Prime numbers

2011-08-17 Thread Don
I wrote it. Can you figure out how it works? Don On Aug 17, 1:25 am, Nitin Nizhawan nitin.nizha...@gmail.com wrote: Hi Dod,   Could you pls expalin what this algorithm is doing and from where you got it. Thanks Nitin On Wed, Aug 17, 2011 at 2:56 AM, Don dondod...@gmail.com wrote: I

[algogeeks] Re: Prime numbers

2011-08-17 Thread Don
of recursive calls to determine that 6 is not prime. Don On Aug 17, 10:33 am, Sanjay Rajpal srn...@gmail.com wrote: @Don : can you plz explain it ? Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India

[algogeeks] Re: an amazing amazon question!

2011-08-17 Thread Don
Actually you are all wrong. His uniform speed was zero, and he was sitting by milestone 44 the whole time. On Aug 17, 11:58 am, priya ramesh love.for.programm...@gmail.com wrote: A car is traveling at a uniform speed.The driver sees a milestone showing a 2-digit number. After traveling for an

[algogeeks] Re: brain teaser

2011-08-17 Thread Don
are interchangeable: 1 and 5. And j is 9. 2442+1442+5442=9326 Don On Aug 17, 1:23 pm, priya ramesh love.for.programm...@gmail.com wrote:    noon + moon + soon = june find the values of the alphabets to satisfy this equation -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: apti! solve this!

2011-08-17 Thread Don
Are we assuming a flat earth? On Aug 17, 9:13 am, priya ramesh love.for.programm...@gmail.com wrote:  A moves 3 kms east from his starting point . He then travels 5 kms north. From that point he moves 8 kms to the east.How far is A from his starting point? -- You received this message

[algogeeks] Re: Need to Hire an algorithm expert for a one time assignment

2011-08-18 Thread Don
Why not post your questions, one per thread, and let people discuss it? Don On Aug 18, 7:41 am, maxpayne aquarian.thun...@gmail.com wrote: Hi, I need help from some one who is really good at algorithms to finish an assignment. I am a freelancer (not a student, so don't expect homework

[algogeeks] Re: knight's tour - variant

2011-08-18 Thread Don
1.0. A knight's only legal move is to remain on the board. On Aug 17, 10:27 am, Seshumadhav Chaturvedula seshumad...@gmail.com wrote: what is the probability that a knight will stay on a K X K chess board after 'n' steps ? -- You received this message because you are subscribed to the Google

[algogeeks] Re: calculate a/b without using ‘*’, ‘/’’ and ‘%’

2011-08-18 Thread Don
exp(ln(a)-ln(b)) On Aug 18, 8:56 am, radha krishnan radhakrishnance...@gmail.com wrote: how to do using BIT manipulation ? -- 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

[algogeeks] Re: question on fork()

2011-08-22 Thread Don
// DO NOT RUN THIS! By inspection, how many times will it print Hello world? // If you find out by running it, that is cheating. Don't do it! int main() { int i=0, j=0; for(i = 0; i*j 20; ++i) { if (fork() 0) ++j; else i = j = 0; printf(Hello world\n); } return 0; } --

  1   2   3   4   5   6   >