Re: [algogeeks] HOW TO CALCULATE THA size of union

2012-12-10 Thread Thanarathnam L
I THINK... D 10 C 10 B 10 A 20 SORRY I AM NOT SURE WITH THIS. On Fri, Dec 7, 2012 at 4:12 PM, zerobyzero narayan.shiv...@gmail.comwrote: what will be the size of union A ,B,C and D. also please explain the logic. * union A{* * long int y[5];* * union B{* *

Re: [algogeeks] BitWise Operations - For finding next multiple

2012-09-13 Thread VIHARRI P L V
Let me give an example. For 17 next multiple of number 5 is 20. For 20 next multiple of number 5 is 25. And give solution for this proeblem also: For 17 next nearest multiple of number 5 is 20. For 20 next nearest multiple of number 5 is 20. *VIHARRI P L

[algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread L
@aditya : I am wondering how many times 7 has occurred. Is it 1? Or is it 0? Please take a moment before posting your solution, and think whether it is write or wrong! On Jul 6, 12:11 am, aditya kumar aditya.kumar130...@gmail.com wrote: Q3. ans:7000 i guess this is also a correct answer and

[algogeeks] Re: Sorting Array

2011-06-28 Thread L
There is one way in which we can do O(n). Convert the numbers in base 'n'. [ O(n) ]. Now, there are 2-digit numbers, each digit ranging from 0 to n-1. You can call count-sort 2 times (for each digit), so, complexity is O(n +n) =O(n). On Jun 27, 12:22 am, Dan dant...@aol.com wrote: Your question

[algogeeks] Re: output plzz

2011-06-25 Thread L
This happens because 'd' is automatically cast into type 'size_t' which is basically unsigned int type. So, it compares with TOTAL_ELEMENTS. Explicitly cast it into int, if you want it to work! On Jun 25, 3:23 pm, harshit pahuja hpahuja.mn...@gmail.com wrote: #includestdio.h #define

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread L
The answer fits in 64 bit range. The calculations done are of the form D = (A*B) / C. Here {A,B,C,D} can be represented are 64 bit integers. But we cannot say that A*B will be a 64 bit integer and will cause overflows. To avoid this, Let's say G=GCD(A,C). Then the above can be written as D =

[algogeeks] Re: DE Shaw Q

2011-06-15 Thread L
The ordering of coins matter for this problem. For ex. 1 2 and 2 1 have different results. So, i don't think that there would be a direct formula for this problem. We will have to traverse all the heaps of coins determining whether the current player is in winning or losing position. On Jun 15,

[algogeeks] Re: Finding shortest path in 4-ary tree

2011-06-14 Thread L
Sorry, i confused val with weight of the edge. BFS would be a better option. On Jun 14, 5:31 pm, L prnk.bhatna...@gmail.com wrote: Any graph algorithm would work. If val is positive then use Dijkstra's algorithm, otherwise use Bellman Ford. On Jun 14, 5:07 pm, Raghavan its...@gmail.com wrote

[algogeeks] Re: Finding shortest path in 4-ary tree

2011-06-14 Thread L
Any graph algorithm would work. If val is positive then use Dijkstra's algorithm, otherwise use Bellman Ford. On Jun 14, 5:07 pm, Raghavan its...@gmail.com wrote: Hi,    How to find the shortest path in a 4-ary tree in an optimal way? Node tree{ Node *left,*right,*top,*bottom; int val; };

[algogeeks] Re: searching a number in circular sorted array

2011-06-10 Thread L
Use ternary search to find the minimum number. (In this case 1) Then you have two sorted arrays, one ascending and one descending. Now, you can apply binary search. First, check the number with the last element and the first element and chose the appropriate array for searching. Time complexity:

[algogeeks] Re: Puzzle

2011-05-27 Thread L
Ah! sorry. This combination is not possible. It will be 10,10,10,10,10,4,2,0. So, the answer is 11. On May 27, 10:10 pm, L prnk.bhatna...@gmail.com wrote: The worst case will occur when 5 teams have the same number of wins. As only 4 can qualify, one team with the same number of points

Re: [algogeeks] Sort the data from a big file.

2009-12-21 Thread Abhilash L L
linus.prob...@gmail.comwrote: If the numbers are unique you could use a bitmap-sort this way you could easily read just parts of the file at a time. If they aren't unique it gets a bit trickier. /L dinesh bansal wrote: Hi All, Suppose I have a big file (~100M) containing integer data. I want

[algogeeks] Re: what is total number of permutation

2007-07-17 Thread Karthik Singaram L
Hi, Although, I cannot give you a complete solution right now..I will give you the following relations (I am not sure If they are correct.discussions welcome) T(0, x) = 1 T(x, 0) = 1 T(1, x) = (x+1) T(x, 1) = (x+1) T(n, m) = Sum[i=0..n] { T(n-i, m-2) * (i+1) } If you are looking for a

[algogeeks] Re: need help for graph problem ...

2007-05-01 Thread Karthik Singaram L
Hi, I guess he is going by the assumption that the queries will be large enough that precomputing the all-pairs shortest paths is better. Anyways..mukesh..this is what you need.. In the place of your output while(cin.get(c) c!='\n') { cin.unget();

[algogeeks] Re: height of ternary tree

2007-05-01 Thread Karthik Singaram L
I guess it was a slight difference in terminology...you must have then phrased the question as almost complete rather than a complete tree since you are allowing the last level to be incomplete. Anyways, If the last level is going to be incomplete, then the observe this.. sum of the nodes is

[algogeeks] Re: Pumping lemma. Where I go wrong?

2007-04-06 Thread Karthik Singaram L
Read the post again... The adversary then chooses the split up, that is, the part of the string you've given him that loop you can only choose the string 'w' (=n), the adversary can only _CHOOSE X, Y and Z_ but ofcourse the adversary is restricted by the fact that he had chosen a 'n' earlier and

[algogeeks] Re: A graph problem

2007-03-30 Thread Karthik Singaram L
DFS --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more

[algogeeks] Re: prime or not

2007-03-29 Thread Karthik Singaram L
well...its simple as given in the article.. note that the numbers are all decimal numbers (not binary..in case misled by just 0 and 1 in the number) therefore if you have have k copies of 001 and k%3 == 0, then the sum of the digits is divisible by 3 hence the number is divisible by 3 - The

[algogeeks] Re: prime or not

2007-03-29 Thread Karthik Singaram L
In case you are wondering about the part of the proof for k%30, it goes like this, the given number can be written as 1 + 1000 + 100 + 10 +..and so on now if for a given k, if we choose the string of k 1s and try to find the modulus with each of the terms in the above expression, for

[algogeeks] Fwd: [algogeeks] prime or not

2007-03-29 Thread Karthik Singaram L
Oooh...I almost forgot to add this.. notice the relation between the proof for part (ii) and the discrete logarithm problem. The proof is no mere coincidence. This is the reason behind using primes in encryption schemes that rely on the hardness of the discrete logarithm problem. This will ensure

[algogeeks] Re: BST represented in array

2007-03-28 Thread Karthik Singaram L
Now in the case of non complete BSTs it may run into trouble...I never handled them. It will work for complete BSTs though as it is. Refer to a previous thread in algogeeks where i had posted the thread inplace sorting and look at the solution by atamurad for the explanation.

[algogeeks] Re: universal hashing question

2007-03-27 Thread Karthik Singaram L
Well... I think a hash function is chosen only once for each run of the program and not for each time a value is hashed. Thereby you dont have such issues at all. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[algogeeks] Re: RR*=R* ?

2007-03-27 Thread Karthik Singaram L
sorry RR* = R+ is the valid assumption --~--~-~--~~~---~--~~ 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

[algogeeks] Re: Pigeon Hole Principle

2007-03-27 Thread Karthik Singaram L
Yes...the proof is correct and this is what stone had suggested in his earlier post. Consider one red sector in the inner disk in each of the 200 different positions, it will match against exactly 100 sectors in the outer disk since there are 100 of the red sectors in the outer disk. Similarly

[algogeeks] Re: BST represented in array

2007-03-26 Thread Karthik Singaram L
An unique BST does exist for such an array if you assume the root to be 1, then automatically you will be able to fix the left and right children of the root and so on. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Pigeon Hole Principle

2007-03-25 Thread Karthik Singaram L
@alfredo: I dint get this part: 1) Lets say that we have the outer circle painted in the following manner: 1 red(C1), 1 white(C2), 1 red(C3), etc. We call this sections (RWR) 2) Then if we have that the inner circle is painted in the same way we finish. 3) if not then lets say that we have a

[algogeeks] Re: BST represented in array

2007-03-24 Thread Karthik Singaram L
#includestdio.h #includestdlib.h #includemath.h #includestring.h #define MAXN 2000 int a[MAXN]; int cnt = 0; int log2n; int n; void populatetestcase(int i) { if(i*2=n) populatetestcase(i*2); a=++cnt; if(i*2+1=n) populatetestcase(i*2+1); } int calc_x(int i) { return (int)log2l((double)i); }

[algogeeks] Re: BST represented in array

2007-03-24 Thread Karthik Singaram L
yes...but you can sort without constant space using the posted algorithm --~--~-~--~~~---~--~~ 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: Pigeon Hole Principle

2007-03-24 Thread Karthik Singaram L
yes...but that does not mean that you can assume that the 100 reds and 100 whites are contiguous blocks.It just says that the outer disk has a sum of the 100 reds and 100 whites and does not say that they are contiguous. --~--~-~--~~~---~--~~ You received this

[algogeeks] Re: BST represented in array

2007-03-24 Thread Karthik Singaram L
for(i=1; i=n; i++) { p= calc_m1(i)*calc_m2(i) + calc_m1(i)/2; if((pi a[p]a)|| (pi a[p]a)) continue; j=i; while(p!=i) { temp = a[j]; a[j] = a[p]; a[p] = temp; p = calc_m1(p)*calc_m2(p) + calc_m1(p)/2; } } Isnt this constant space (assuming that the array a is given already). Since calc_m1 and

[algogeeks] Re: BST represented in array

2007-03-24 Thread Karthik Singaram L
i am sorry that is a[i] = ++cnt I made a mistake when pasting the code... --~--~-~--~~~---~--~~ 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: count the 1 bits in integer

2007-03-21 Thread Karthik Singaram L
The standard link http://graphics.stanford.edu/~seander/bithacks.html --~--~-~--~~~---~--~~ 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: find the closest common ancestor of node u and v?

2007-03-21 Thread Karthik Singaram L
Find the longest common prefix in the path from the root to nodes u and v --~--~-~--~~~---~--~~ 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: help making regular expression

2007-03-15 Thread Karthik Singaram L
A DFA is possible I guess which is interesting, see if the following DFA works, since the existence of the DFA relates to the existence of a Regular Expression Describing the language State/Input 01 q00 q10 q01 q10 q20

[algogeeks] Re: help making regular expression

2007-03-15 Thread Karthik Singaram L
If the DFA works then it can be converted to a regular expression using standard techniques like the one described in http://www.cs.colostate.edu/~whitley/CS301/L3.pdf --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Inplace sorting

2007-03-13 Thread Karthik Singaram L
To make things more easier just assume a complete binary search tree --~--~-~--~~~---~--~~ 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: linear programming

2007-03-13 Thread Karthik Singaram L
the LP: v1 = 40 v2 = 30 v3 = 20 v1 + v2 + v3 = 60 v1*2 + v2*1 + v3*3 = 100 Maximize: v1*1000 + v2*1200 + v3*12000 Here v1, v2 and v3 are the volumes of the materials 1, 2 and 3 to be taken. --~--~-~--~~~---~--~~ You received this message because you are

[algogeeks] Re: Inplace sorting

2007-03-13 Thread Karthik Singaram L
The question is not to print out a sorted array which we can easily do by inorder traversal. The question is to store the sorted array in the same array with constant extra space. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

[algogeeks] Re: Inplace sorting

2007-03-13 Thread Karthik Singaram L
I agree with you completely but for the problem that I posted it is enough that we have O(n) in accessing the elements in order. Your solution does better by calculating every element in O(1) time. The key now is to do the actual sorting with this method

[algogeeks] Re: To find a rectangle of max sum

2007-03-12 Thread Karthik Singaram L
Another variant...(or rather wanted to say in my previous post) How do you find a maximum square of all ones in a binary matrix of 0s and 1s? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: Largest Bound rectangle in a bar graph

2007-03-12 Thread Karthik Singaram L
I give a try to start at an O(mn) algorithm (where m is the size of the longest bar) Maxrect[height][width] = --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] Re: Largest Bound rectangle in a bar graph

2007-03-12 Thread Karthik Singaram L
A shot at an O(nlgn) algorithm. Do a sweep line from top to bottom. Only look at the events when a new bar is introduced (this is accomplished by sorting the bars based on height). When a new bar arises, if there exist values immediately to the left and right of the bar just merge them into a

[algogeeks] Re: how to tell honest people

2007-03-08 Thread Karthik Singaram L
yes..thats the reasoning that i had too but let us see if anyone else sees some thing fishy in our reasoning --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Interesting Probability Question

2007-03-07 Thread Karthik Singaram L
why is it 1 - (area of triangle)/(area of Sq.)? why do we need a square since what would happen is that the 4th point can be anywhere in the space but the area of the triangle is bounded. The probability of choosing a point outside the triangle would be 1 (bound - not exact by reasoning as in

[algogeeks] Re: integers n1,n2 such that n1+n2 = x

2007-02-14 Thread Karthik Singaram L
On 2/14/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, There is a problem in the algorithm book I'm trying to digest, that I'd like to discuss a bit. So, first thing first, let me state the problem : find(A, x) sort(A) i = 1 j = n while (A[i]+A[j] != x) {

[algogeeks] Re: a data structure for phone directory

2007-02-14 Thread Karthik Singaram L
It does depend on the size of the problem you have in mind. Tries can be expensive for names depending on the sparseness of the data set, you may waste a lot of pointers. If you use B-Trees they may be good in such cases. B-trees are generally a bit better when it comes to data stored in a disk

[algogeeks] Re: Permutation with a twist ??

2007-02-02 Thread Karthik Singaram L
permutation (List resultSoFar, List remainingElements) { if(length(remainingElements)=0) return; for i = 1 to length(remainingElements) { print resultSoFar+remainingElements[i]; permutation (resultSoFar+remainingElements[i], remainingElements-remainingElements[i]);

[algogeeks] Re: Permutation with a twist ??

2007-02-02 Thread Karthik Singaram L
yes..i agree with rajiv..you seem to be generating combinations rather than permutations..the algo that i have given generates permutations --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: puzzle - Weighing marbles

2007-02-02 Thread Karthik Singaram L
Split the marbles into sets of 4 each Compare the first and second sets If both the sets are equal (the problem is in third set) { choose 2 of the marbles in the third set compare with 2 marbles from the first set(which we know are good) if comparision is equal { compare one of

[algogeeks] Re: please help me solve the exercise 14.1-8 of introduction to algorithm

2007-01-23 Thread Karthik Singaram L
Hi, You can try a similar technique... Start at an arbitrary endpoint, Set the number of open chords to zero, Set the number of intersections to zero Traverse the endpoints along the circle in one direction (made possible by sorting radially) { If the endpoint is one that closes

[algogeeks] Re: Array moving left

2006-11-19 Thread Karthik Singaram L
You could use a B-Tree or even a simple binary tree to index into the array, but the space will be doubled (it is justified if you store some other object in the array other than integers). On 11/17/06, Nik [EMAIL PROTECTED] wrote: Hi, I have an array in which elements are present . The

[algogeeks] Fwd: Graph Partitioning

2006-11-14 Thread Karthik Singaram L
-- Forwarded message -- From: Karthik Singaram L [EMAIL PROTECTED] Date: Nov 12, 2006 4:58 PM Subject: Graph Partitioning To: algogeeks@googlegroups.com Hi, I have been faced with this problem for weeks and could not find a good solution. can someone help? Given a graph

[algogeeks] Re: NP complete Partition problem.

2006-11-12 Thread Karthik Singaram L
I am not sure but an arbit way to do this would be to find (totalsum/k) and do a bin packing for each of these , of course we would be left with a few elements, we can put them in the bins with max.slack space...It would be approximately correct I guess though not sure. Hope it helps karthik On

[algogeeks] Graph Partitioning

2006-11-12 Thread Karthik Singaram L
Hi, I have been faced with this problem for weeks and could not find a good solution. can someone help? Given a graph whose nodes are bit vectors of length n (the graph contains all 2^n nodes), the edges are defined to be connecting all the pairs of nodes which differ only at one bit

[algogeeks] Re: PAIR of shortest paths...

2006-10-30 Thread Karthik Singaram L
I am not sure If I got the question right 1 4 0 3 1 2 3 1 1 0 2 2 0 3 3 2 0 2 1 2 Isn't the answer that camarade 1 talks to camarade 0 who inturn talks to 2. Isnt this shortest path algorithm? isnt Djikstra O(VlogV) which seems feasible for the problem rite? On 10/30/06, Pradeep

[algogeeks] Re: Permuatation containing given element

2006-10-26 Thread Karthik Singaram L
/* Assume inp is the given array*/static int bitmap[N][N];int lengths[N];int currentBitmap = -1;int active = 1;int lastPos;for(i=0;iN;i++){ if(inp[i]==1) { currentBitmap++; active=1; lastPos=i; } if(active==1) { if(bitmap[currentBitmap][inp[i]]==1) { active=0; lengths[currentBitmap]=(i-pos); }

[algogeeks] Re: isomorphism

2006-10-25 Thread Karthik Singaram L
Let us say we call the following with the roots of both the treesalgo: checkIsomorphism (node1, node2){ if(node1==NULL node2==NULL) return 1; if(node1==NULL) return 0; if(node2==NULL) return 0; child11=node1-left; child12=node1-right; child21=node2-left; child22=node2-right;

[algogeeks] Re: k connectivity

2006-04-25 Thread Karthik Singaram L
Hmmm.. Interesting Just in case someone does want to use BFS and does not really care about the time complexity, then you could do BFS to get all the Paths ( do not remove them as soon as you get them ) For example in the graph in the previous discussion, BFS would give S37F, S345F and

[algogeeks] Re: k connectivity

2006-04-25 Thread Karthik Singaram L
of course the time complexity could be substantially reduced using the flow model of the problem.l\ On 4/26/06, Karthik Singaram L [EMAIL PROTECTED] wrote: Hmmm.. Interesting Just in case someone does want to use BFS and does not really care about the time complexity, then you could do BFS

[algogeeks] Re: Chord Intersection

2006-04-25 Thread Karthik Singaram L
Try this variation In the previous algorithm if i am correct the complexity is O(n), that itself shows that an important step is missing somewhere. well this is my guess about the algorithm. check if it works. I do not think this is exactly the standard Bentley-Ottmann Algorithm The precondition

[algogeeks] Re: optimal assignnment of program to tapes.

2006-03-08 Thread Karthik Singaram L
This is the problem of dividing a set into two such that the sum of their differences is minimum.This can be solved using dynamic programming as follows: algo: 1. Create an array of size L say Arr[L] and initialize to zeroes 2. Put Arr[0]=1 3. For each program Pi Scan the array Arr from the right

[algogeeks] Re: An interesting problem from Code4bill second round

2006-02-04 Thread Karthik Singaram L
Exactly correct!!! But for the proof and solution to be complete, we need to analyze this for 7 the answer you have is dp[3]=3*dp[2]+1=3*[4]+1 Now can you see that for dp[2], the number of steps would be 000 010 011 That would be only 3 steps so dp[2] is only 3 . Am i correct? Regards karthik

[algogeeks] Re: An interesting problem from Code4bill second round

2006-02-01 Thread Karthik Singaram L
I solved this problem ( A very very interesting DP solution I guess )The key to the solution is First try to Prove that the last bit can be set using only 15 onesand you will get the solution.Keep thinking!!! ( A clue :- use Mathematical Induction for the Proof and the DP follows)-karthik