Re: [algogeeks] Sorting a very large number of intergers

2013-06-14 Thread Avi Dullu
Hint 1: If taken the assumption that you have ~6GB RAM (out of this 3.7GB is for the input itself) you do not need any external sorting to do this. Hint 2: 1,000,000,000 (2 30) Hint 3: Read this http://en.wikipedia.org/wiki/Bit_array#Sorting up On Thu, Jun 13, 2013 at 2:06 AM, MAC

Re: [algogeeks] Re: Google Interview Question: In how many intervals does a number exists

2013-06-11 Thread Avi Dullu
Can you tell the 'size' of your array 'f' if the intervals are [0, 10], [10, 9223372036854775808] ? Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones

Re: [algogeeks] Google Interview Question: In how many intervals does a number exists

2013-06-09 Thread Avi Dullu
Read up on Interval trees http://en.wikipedia.org/wiki/Interval_tree. Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight

Re: [algogeeks] Infinite stream , identify distinct k kintegers

2013-06-02 Thread Avi Dullu
(For very large k case only) Keep as many elements in the hash_map as you can. Once the map capacity is exhausted, sort all the elements in the hash_map and write them to disk and build a bloom filter. Keep this bloom filterhttp://en.wikipedia.org/wiki/Bloom_filterin memory, empty the hash_map

Re: [algogeeks] amazon f2f round question ..

2013-05-24 Thread Avi Dullu
and then start with the vertices whose in degree is 1. Veni Vedi Slumber ! On Fri, May 24, 2013 at 6:19 AM, MAC macatad...@gmail.com wrote: kindly explain visualizing a balanced BST as a graph and unable to underdstand your point thanks --mac On Fri, May 24, 2013 at 6:04 AM, Avi

Re: [algogeeks] stack. Mid element in o(1)

2013-05-23 Thread Avi Dullu
Code is here http://codebin.org/view/30e9f2c0. Logic is made clear by the variable names. Idea is similar to the one which is used to build a queue using 2 stacks. On Wed, May 22, 2013 at 8:45 AM, MAC macatad...@gmail.com wrote: I think this is only possible if you make sure that at push you

Re: [algogeeks] amazon f2f round question ..

2013-05-23 Thread Avi Dullu
On Sat, May 11, 2013 at 10:29 AM, Aman Jain pureama...@gmail.com wrote: 2. from this no*de u*, again apply* dfs* to find longest distant node from this node.Let us say that node is v. Small doubt about the solution. Consider this graph a - b - c - d You randomly choose vertex 'b' and do a

Re: [algogeeks] Re: Taking Input

2011-07-02 Thread Avi Dullu
#include stdio.h #include string.h #include stdlib.h int main() { int n, num, i; scanf(%d, n); for (i = 0; i n; ++i) { char ch = '#'; printf(scanned from %d line: , i + 1); while (ch != '\n') { scanf(%d%c, num, ch); printf(%d , num); } printf(\n); }

Re: [algogeeks] null macro

2011-07-02 Thread Avi Dullu
#include cstdio #define NULL1 (void *)0 #define NULL2 0 int main() { int* p = NULL1; // void* being assigned to a int*, C++ complains. int* q = NULL2; return 0; } Veni Vedi Slumber ! On Sat, Jul 2, 2011 at 10:28 PM, Decipher ankurseth...@gmail.com wrote: Hey I was asked this question

Re: [algogeeks] Re: help..

2011-07-02 Thread Avi Dullu
Another alternative soln. int rec_cut(int l, int k) { if (l == k) return 0; int tmp = k - (l1); return 1 + rec_cut(l1, tmp = 0 ? k : tmp); } int main() { int l, k; scanf(%d%d, l, k); printf(%d\n, rec_cut(l, k)); return 0; } Veni Vedi Slumber ! On Sat, Jul 2, 2011 at 9:47 PM,

Re: [algogeeks] C++ Doubt

2011-01-20 Thread Avi Dullu
extending the above example Base B; DerivedClasses D1, D2; B's content - {content_of_B } D1's content - { content_of_B, D1_specific_data_and_functions} D2's content - { content_of_B, D2_specific_data_and_functions} Can you see the reason now? The above is a very simplified example, think of

Re: [algogeeks] Re: Microsoft - DP problem

2011-01-20 Thread Avi Dullu
@^ Just check ur solution for boundary case ( n = 2) .. M$ is *generally* very strict about such mistakes :) Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-16 Thread Avi Dullu
at index 1, 2 and 3... go greedy on f(index) = index + array[index] so f(1) = 1 + 5 = 6 f(2) = 2 + 3 = 5 f(3) = 3 + 4 = 7 plainly, if u define ur greedy criteria right, u go for index 3... On Jan 15, 11:15 pm, Avi Dullu avi.du...@gmail.com wrote: The greedy will always chose

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-16 Thread Avi Dullu
initially said greedy would make wrong choices 3-5-4 and hence give wrong minimum number of jumps while DP would give 3-4... hence i responded saying that if we go greedy on a different function, greedy will yield the right result as well... and in a shorter time On Jan 16, 12:28 pm, Avi Dullu

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-15 Thread Avi Dullu
and jump there. This greedy approach works in 0(n^2) and i believe it works. If not can someone give me a counter example ? On Sat, Jan 15, 2011 at 3:30 AM, Avi Dullu avi.du...@gmail.com wrote: @jammy Even I felt the same, but the greedy 'algo' u suggest is actually IMHO

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-15 Thread Avi Dullu
move forward... On Jan 15, 12:54 pm, Avi Dullu avi.du...@gmail.com wrote: @jammy Thanx for the elongated description :) Yes, I feel I probably gave a DP solution wrongly to the Greedy approach. But just to clarify, Greedy does not solve any subproblems, it just makes a locally optimal

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-14 Thread Avi Dullu
I guess u got confused with the comment I wrote, I have added 2 print statements and now I guess it should be clear to you as to why the code is O(n). The comment means that each element of the min_steps_dp will be ACCESSED only ONCE over the execution of the entire program. Hence the outer loop

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-14 Thread Avi Dullu
since you can't ensure the choice is locally optimum. Consider 3,9,2,1,8,3. Using greedy alg. would give you 3,1,8,3 while otherwise DP would give you 3,9,3. On Jan 14, 6:11 am, Avi Dullu avi.du...@gmail.com wrote: I guess u got confused with the comment I wrote, I have added 2 print

Re: [algogeeks] Re: MICROSOFT IDC

2011-01-12 Thread Avi Dullu
SO .. u guys propose that 'sorting' is an O(1) space ? Won't the sorting algo swap elements of the list so making it a O(n) space algo ? (Just proposing :) ) Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the

Re: [algogeeks] Re: MICROSOFT IDC

2011-01-12 Thread Avi Dullu
Sure, I raised concern about 'sorting'. Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight to read and interpret the

Re: [algogeeks] Re: Amazon Interview - Algorithms

2011-01-12 Thread Avi Dullu
@juver++ : what is the greedy approach one could take here? I know it would be wrong, but I tried to come up with a test case for greedy failure, but realized the greedy policy here will be equivalent to the dp. @Decipher: your's seems to be a O(n^2) solution. Here in the O(n) version of it.

Re: [algogeeks] Re: Adobe - Algorithm

2011-01-09 Thread Avi Dullu
Hey guys .. saw this discussion and wanted to add something .. I wrote the below program in college .. and I kindof have forgotten wat was the logic (see the problem with badly written code :P ), It works on a pattern which I found in this problem, I checked it and feel it works in order O(n) as

Re: [algogeeks] Re: floating point

2011-01-08 Thread Avi Dullu
to add to @Dave's reply. He explained it elaborately in thishttp://groups.google.com/group/algogeeks/browse_thread/thread/20af6e098297d413thread Programmers should realize their critical importance and responsibility in a world gone digital. They are in many ways similar to the priests and monks

Re: [algogeeks] BT

2011-01-08 Thread Avi Dullu
One approach would be to convert both the trees to well formed flat-tree representation and then reduce the problem to a substring matching one (can use KMP/Boyer-Moore/Rabin-Karp for it). eg. 1 2 3 4 5 is flattened to (using postorder traversal) (1 (2 4 .) (3 . 5)) Programmers

Re: [algogeeks] Re: double and int

2011-01-07 Thread Avi Dullu
correct and recommended way is missing an absolute value: assert(abs(d1 + d2 - d3) 1.0e-5); // given you assume precision of 1e-5 is the correct and recommended way. Dave On Jan 6, 4:19 pm, Avi Dullu avi.du...@gmail.com wrote: Just to mention, floating point numbers r always compared

Re: [algogeeks] Re: double and int

2011-01-07 Thread Avi Dullu
depends in part on whether you want to say that 0.2 == 0.29 because they differ by less than 1.0e-5, even though they differ by 45%. Applying your philosophical boilerplate, you have to use some intelligence even in this type of thing. Dave On Jan 7, 12:51 pm, Avi Dullu avi.du...@gmail.com

Re: [algogeeks] Re: Adobe - Coding

2011-01-07 Thread Avi Dullu
@Decipher As far as I understand the problem it says returns the 5 most common occuring strings in a list, and the example u give is of a character array, when u go to a list of strings with len_of_each_string 1, u wil have to *hash* them, which is when u will run into problems with count sort.

Re: [algogeeks] How to search for the presence of a file in Linux?

2011-01-06 Thread Avi Dullu
Hey, Remembered of my OS assignment and wanted to fix it :). Though do not appreciate the design of the program :D, and not having the enthu to redesign it, I have fixed the program with minimal possible changes. Please reply in case of any issues. Thnx for posting :) #include iostream #include

Re: [algogeeks] Re: double and int

2011-01-06 Thread Avi Dullu
Just to mention, floating point numbers r always compared *for equality* like double d1 = 90.0; double d2 = 90.0; assert(d1 == d2); // might fail, and Wrong way to do !! assert(d1 - d2 1e-5); // given u assume precision of 1e-5, is the correct and recommended way. Programmers should realize