Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
Number exponentiation On Fri, Jan 21, 2011 at 1:05 PM, snehal jain learner@gmail.com wrote: Given M, find if M = 3^x for some positive integer x efficiently. DO NOT think of log, pow etc -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

[algogeeks] Number Placement Problem.......

2011-01-21 Thread Gaurav_K_Singh
* Place N number from 1 to N, in 2N positions in such a way so that there are Exactly “a” number of cells between two placed locations of number “a”. Write a program to display numbers placed in this way. Example:- (1) One of the possible placement for 7 numbers in 14 positions is : 5 7 2 3

[algogeeks] Distance in a dictionary

2011-01-21 Thread snehal jain
You have a dictionary of N words each of 3 chars. Given 2 words you have to find the optimum path between the 2 words. The optimum path contains the words in the dictionary each word at a distance of 1 from the previous word. for eg source = cat , target = sun path is cat - bat - but - bun - sun

[algogeeks] Find the path in two nodes of a binary search tree

2011-01-21 Thread snehal jain
Suppose you have a tree. A binary tree (for something like simplicity :p). You are traversing it (using infix, postfix or prefix) to search for a node. You find your required node. You just realized that you need to know the path from this node back to the root node (and/or vice versa). Given the

[algogeeks] Re: pairwise sum

2011-01-21 Thread juver++
Here is solution from Igor Naverniouk(Google): http://shygypsy.com/tools/pairsums.cpp -- 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

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
binary search on the answer and then fast exponentiation. -- 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

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
The most well done solution is to store possible powers of 3 in a table (this table will be small), and then try to find number M. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] power of 3

2011-01-21 Thread snehal jain
@ above m nt getting binary search and fast exponentiation .. please elaborate. On Fri, Jan 21, 2011 at 2:07 PM, juver++ avpostni...@gmail.com wrote: The most well done solution is to store possible powers of 3 in a table (this table will be small), and then try to find number M. -- You

Re: [algogeeks] Re: pairwise sum

2011-01-21 Thread snehal jain
@ above cn u please explain your logic. On Fri, Jan 21, 2011 at 2:02 PM, juver++ avpostni...@gmail.com wrote: Here is solution from Igor Naverniouk(Google): http://shygypsy.com/tools/pairsums.cpp -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] top search queries

2011-01-21 Thread snehal jain
Magy! receives a huge amount of queries everyday. They don’t want to store all of them, since many of the queries are unique (submitted just one time by just one user). Anyway, for caching reason they want to understand what are the queries whose frequency exceed s=0.1%. How do you solve the

[algogeeks] Finding elements near the median

2011-01-21 Thread snehal jain
Given an unsorted array A of n distinct numbers and an integer k where 1 = k = n, design an algorithm that finds the k numbers in A that are closest in value to the median of A in O(n) time. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Minimum positive-sum subarray

2011-01-21 Thread snehal jain
In this variation of the Maximum-Sum Subarray Problem, you are given a one-dimensional array A[1 : n] of positive or negative numbers, and you are asked to find a subarray A[i : j] such that the sum of its elements is (1) strictly greater than zero, and (2) minimum. In other words, you want to

[algogeeks] merging 2 search trees

2011-01-21 Thread snehal jain
You are given two height balanced binary search trees T and T’, storing m and n elements respectively. Every element of tree T is smaller than every element of tree T’. Every node u also stores height of the subtree rooted at it. Using this extra information how can you merge the two trees in time

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
int l = 0, r = ...; while (l r) { int m = (l + r) / 2; int p = power(3, m); if (p M) r = m - 1; else if (p M) l = m + 1; else print 3^m = M; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: pairwise sum

2011-01-21 Thread juver++
http://www.topcoder.com/tc?module=Staticd1=match_editorialsd2=srm182 -- 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

[algogeeks] array

2011-01-21 Thread snehal jain
Given an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times. please give if you have solution other than hashing and sorting.. -- You received this message because you are subscribed

Re: [algogeeks] power of 3

2011-01-21 Thread abhijith reddy
Below is code for modular exponentation in general // (a^b)%c int modexp(int a,int b,int c) { int ans=1; while(b) { if(b1) ans=(ans*a)%c; a=(a*a)%c; b=1; } return ans; } On Fri, Jan 21, 2011 at 3:27 PM, juver++ avpostni...@gmail.com wrote: int l = 0, r = ...;

Re: [algogeeks] zig zag

2011-01-21 Thread nishaanth
How about this dp solution? Let dp[i][j][k] be the lookup table. It is defined as the longest zigzag sequence in the range i and j. k is either 0 or 1. 0- if the sequence ends with a positive difference, i.e last element is greater than the last to one. 1- if the sequence ends with a negative

Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
this will be O(log(n) * log(n)) solution On Fri, Jan 21, 2011 at 4:29 PM, abhijith reddy abhijith200...@gmail.comwrote: Below is code for modular exponentation in general // (a^b)%c int modexp(int a,int b,int c) { int ans=1; while(b) { if(b1) ans=(ans*a)%c;

Re: [algogeeks] power of 3

2011-01-21 Thread snehal jain
@juvir++ it was mentioned in question not to use log or power. isnt there any approach using bitwise operators On Fri, Jan 21, 2011 at 5:24 PM, Manmeet Singh mans.aus...@gmail.comwrote: this will be O(log(n) * log(n)) solution On Fri, Jan 21, 2011 at 4:29 PM, abhijith reddy

Re: [algogeeks] power of 3

2011-01-21 Thread abhijith reddy
O(lg(n)*lg(n)) is the complexity of the solution ! Not the solution. M=3^x We binary search on x and then compute 3^x in log(x) time using exponentiation. Hence the complexity. On Fri, Jan 21, 2011 at 5:50 PM, snehal jain learner@gmail.com wrote: @juvir++ it was mentioned in question not

Re: [algogeeks] power of 3

2011-01-21 Thread abhijith reddy
@snehal .. misread it .. my apologies. On Fri, Jan 21, 2011 at 5:56 PM, abhijith reddy abhijith200...@gmail.comwrote: O(lg(n)*lg(n)) is the complexity of the solution ! Not the solution. M=3^x We binary search on x and then compute 3^x in log(x) time using exponentiation. Hence the

Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
@snehal : YUP On Fri, Jan 21, 2011 at 5:57 PM, abhijith reddy abhijith200...@gmail.comwrote: @snehal .. misread it .. my apologies. On Fri, Jan 21, 2011 at 5:56 PM, abhijith reddy abhijith200...@gmail.comwrote: O(lg(n)*lg(n)) is the complexity of the solution ! Not the solution. M=3^x

Re: [algogeeks] merging 2 search trees

2011-01-21 Thread nishaanth
Find the node in T which is the maximum(which is either the root or the rightmost in the right subtree). After finding this node, just make the right child of this node point to the root of T'. Correct me if i am wrong On Fri, Jan 21, 2011 at 2:43 PM, snehal jain learner@gmail.com wrote:

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
@above it's a user-defined function using fast exponentiation -- 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

Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
@juver++ : the above is a user defined function. but its possible to the problem using bit wise operators. On Fri, Jan 21, 2011 at 7:29 PM, juver++ avpostni...@gmail.com wrote: @above it's a user-defined function using fast exponentiation -- You received this message because you are

Re: [algogeeks] Distance in a dictionary

2011-01-21 Thread nishaanth
Its a state space search. Solve it by using any of the known search algorithms. BFS, Best first search, DFS, A* On Fri, Jan 21, 2011 at 2:00 PM, snehal jain learner@gmail.com wrote: You have a dictionary of N words each of 3 chars. Given 2 words you have to find the optimum path between

Re: [algogeeks] power of 3

2011-01-21 Thread snehal jain
@manmeet how? On Fri, Jan 21, 2011 at 7:36 PM, Manmeet Singh mans.aus...@gmail.comwrote: @juver++ : the above is a user defined function. but its possible to the problem using bit wise operators. On Fri, Jan 21, 2011 at 7:29 PM, juver++ avpostni...@gmail.com wrote: @above it's a

[algogeeks] Amazon Question

2011-01-21 Thread nagaraj N
How do you find out the fifth maximum element in an binary search tree in efficient manner without using any extra space? -- 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: Amazon Question

2011-01-21 Thread juver++
This question was posted some time ago. One solution is - start from the largest element (which is the righmost one in the tree). Then apply algorithm of searchin node's predecessor. It takes O(k) time to find k-th largest/smallest number. -- You received this message because you are

Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
write n, n-1 to base 3 check if thr gives 0, if it gives no. is of form 3^n On Fri, Jan 21, 2011 at 8:04 PM, snehal jain learner@gmail.com wrote: @manmeet how? On Fri, Jan 21, 2011 at 7:36 PM, Manmeet Singh mans.aus...@gmail.comwrote: @juver++ : the above is a user defined function.

Re: [algogeeks] OS galvin sol..

2011-01-21 Thread jayapriya surendran
wow..thank you so much On Wed, Jan 19, 2011 at 2:08 PM, LALIT SHARMA lks.ru...@gmail.com wrote: -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

[algogeeks] Google Question

2011-01-21 Thread suganya c
Assume you are writing number in ascending order to an array of constant size.once you reach the end of the array,you start writing from the beginning, thus writing over the oldest entries.Write an algorithm for finding a specific number in this array. -- You received this message because you

Re: [algogeeks] Sites for Interview Questions

2011-01-21 Thread rahul rai
http://www.ocf.berkeley.edu/~wwu/riddles/intro.shtml Rahul K Rai rahulpossi...@gmail.com On Tue, Jan 18, 2011 at 9:27 PM, Yellow Sapphire pukhraj7...@gmail.comwrote: Hi, Can someone suggest good books/websites/blogs for interview related questions. thanks-- YS -- You received this

Re: [algogeeks] Re: L values and r values

2011-01-21 Thread rahul rai
Thanks , btw the example was from Dragon Book of Compilers . . Any one knows an instructor manuall or some selected set of solutions for that . ? I have read it that they are not published On 1/21/11, Gene gene.ress...@gmail.com wrote: L and R values have great significance to language designers

RE: [algogeeks] Re: Sites for Interview Questions

2011-01-21 Thread turksheadeducation
One more interesting site is http://www.rawkam.com -Original Message- From: algogeeks@googlegroups.com [mailto:algogeeks@googlegroups.com] On Behalf Of awesomeandroid Sent: 19 January 2011 AM 09:15 To: Algorithm Geeks Subject: [algogeeks] Re: Sites for Interview Questions

Re: [algogeeks] Sites for Interview Questions

2011-01-21 Thread Abhishek Sharma
Programming Interviews Exposed is a good one.. On Tue, Jan 18, 2011 at 9:27 PM, Yellow Sapphire pukhraj7...@gmail.comwrote: Hi, Can someone suggest good books/websites/blogs for interview related questions. thanks-- YS -- You received this message because you are subscribed to the

Re: [algogeeks] Adobe Question

2011-01-21 Thread Divya Jain
if sorted then a tweak in merge sort will work On 20 January 2011 23:23, nishaanth nishaant...@gmail.com wrote: Ya as Ashish said hashing is the best solution :) On Fri, Jan 14, 2011 at 6:00 PM, Ashish Goel ashg...@gmail.com wrote: ideally, a hashMap would be preferred walk through one

Re: [algogeeks] merging 2 search trees

2011-01-21 Thread Divya Jain
@ above height will not be balanced then On 21 January 2011 19:15, nishaanth nishaant...@gmail.com wrote: Find the node in T which is the maximum(which is either the root or the rightmost in the right subtree). After finding this node, just make the right child of this node point to the root

Re: [algogeeks] Re: Google Question

2011-01-21 Thread Algoose chase
hope this works : #includestdio.h #define MAX(A,B) AB?A:B #defineMIN(A,B) AB?A:B int FindMaxA(int n) { int i,k,factor,max = 0,cur,prev; int* arr = new int[n+1]; int p = MIN(n,4); for( int j = 1;j = p;j++) arr[j] = j; for(i=5;i=n;i++) { k = i-4;

Re: [algogeeks] Distance in a dictionary

2011-01-21 Thread rahul rai
@nishaanth can u give the outline?// On 1/21/11, nishaanth nishaant...@gmail.com wrote: Its a state space search. Solve it by using any of the known search algorithms. BFS, Best first search, DFS, A* On Fri, Jan 21, 2011 at 2:00 PM, snehal jain learner@gmail.com wrote: You have a

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
@fight good solution. 3^n contains only one 1 in the 3-base representation. So write number M in base-3, and check if it contains only one digit(1). There is no need to find with M-1. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

Re: [algogeeks] power of 3

2011-01-21 Thread Manmeet Singh
@ juver++ : fight is my tc handle. here u can call me manmeet :) :) On Fri, Jan 21, 2011 at 9:35 PM, juver++ avpostni...@gmail.com wrote: @fight good solution. 3^n contains only one 1 in the 3-base representation. So write number M in base-3, and check if it contains only one digit(1).

Re: [algogeeks] Adobe Question

2011-01-21 Thread Manmeet Singh
how merge sort ?/ On Thu, Jan 20, 2011 at 11:23 PM, nishaanth nishaant...@gmail.com wrote: Ya as Ashish said hashing is the best solution :) On Fri, Jan 14, 2011 at 6:00 PM, Ashish Goel ashg...@gmail.com wrote: ideally, a hashMap would be preferred walk through one array and set the

Re: [algogeeks] Distance in a dictionary

2011-01-21 Thread nishaanth
Ok lets define the following functions. movegen()- gives the list of next move given the state. This is basically all the 1 distance words given the current word. heuristic()- this gives the number of non-matching characters of the given word with the goal word. Start from start state and

Re: [algogeeks] OS galvin sol..

2011-01-21 Thread Sreeprasad Govindankutty
Thanks so much On Wed, Jan 19, 2011 at 4:20 AM, jayapriya surendran priya7...@gmail.comwrote: wow..thank you so much On Wed, Jan 19, 2011 at 2:08 PM, LALIT SHARMA lks.ru...@gmail.com wrote: -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- You received this

Re: [algogeeks] Re: Amazon Question

2011-01-21 Thread nishaanth
@Juver..doesnt it require the parent information ? What if the data structure has only left and right pointers. On Fri, Jan 21, 2011 at 8:41 PM, juver++ avpostni...@gmail.com wrote: This question was posted some time ago. One solution is - start from the largest element (which is the righmost

Re: [algogeeks] Distance in a dictionary

2011-01-21 Thread Manmeet Singh
whts complexity for this movegen() On Fri, Jan 21, 2011 at 9:52 PM, nishaanth nishaant...@gmail.com wrote: Ok lets define the following functions. movegen()- gives the list of next move given the state. This is basically all the 1 distance words given the current word. heuristic()- this

Re: [algogeeks] power of 3

2011-01-21 Thread juver++
@manmeet so, please choose your nickname at the forum :) -- 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

Re: [algogeeks] Re: Amazon Question

2011-01-21 Thread juver++
@above yes, posted solution needs parent links. Another solution is to process tree in reverse inorder: right subtree, root, left subtree and keeping counter k, when k is zero return current node -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] OS galvin sol..

2011-01-21 Thread Anand
It's really good. Thanks a lot On Fri, Jan 21, 2011 at 8:24 AM, Sreeprasad Govindankutty sreeprasad...@gmail.com wrote: Thanks so much On Wed, Jan 19, 2011 at 4:20 AM, jayapriya surendran priya7...@gmail.comwrote: wow..thank you so much On Wed, Jan 19, 2011 at 2:08 PM, LALIT SHARMA

Re: [algogeeks] OS galvin sol..

2011-01-21 Thread LALIT SHARMA
My Pleasure !! On Fri, Jan 21, 2011 at 11:22 PM, Anand anandut2...@gmail.com wrote: It's really good. Thanks a lot On Fri, Jan 21, 2011 at 8:24 AM, Sreeprasad Govindankutty sreeprasad...@gmail.com wrote: Thanks so much On Wed, Jan 19, 2011 at 4:20 AM, jayapriya surendran

[algogeeks] Amazon - Tree

2011-01-21 Thread Decipher
You are given a bst where each node has a int value , parent pointer , and left and right pointers , write a function to find a path with a given sum value. Path can go from left subtree tree , include root and go to right tree as well . we need to find these paths also . 5 / \ 1 10 / \ / \ 0

[algogeeks] Graph Theory+ DP

2011-01-21 Thread tillegomezz
Given a distribution of packages on media and a list of dependences between packages, you have to calculate the minimal number of media changes required to install all packages. For your convenience, you may assume that the operating system comes on exactly 2 DVDs.

[algogeeks] Re: Graph Theory+ DP

2011-01-21 Thread juver++
Yes, you are right -- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit

[algogeeks] find a line

2011-01-21 Thread divya
Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide the region to 2 parts with half points in each .the input will be an array of points and the length of the array. struct point{ int x; int y; }; input : struct

Re: [algogeeks] OS galvin sol..

2011-01-21 Thread rahul rai
can u give me sipser solution mannual? On 1/21/11, Sreeprasad Govindankutty sreeprasad...@gmail.com wrote: Thanks so much On Wed, Jan 19, 2011 at 4:20 AM, jayapriya surendran priya7...@gmail.comwrote: wow..thank you so much On Wed, Jan 19, 2011 at 2:08 PM, LALIT SHARMA

Re: [algogeeks] Symmetric matrix

2011-01-21 Thread Umer Farooq
We can also use jagged arrays for this purpose int[][] symmetric_matrix = new int[size][]; for (int i=0; i size; i++) ...symmetric_matrix[i]=new int[max_diagonal/(size)]; On Wed, Jan 12, 2011 at 9:30 AM, Sathaiah Dontula don.sat...@gmail.comwrote: 1 + 2 + + n ( max diagonal) = n (

[algogeeks] nearest points

2011-01-21 Thread divya
Given n points on a 2D coordinate system . What is the most efficient way of finding nearest point for each point? How can we find all the points at a distance k from a given point efficiently? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

[algogeeks] Fwd: Indians r poor but India is not a poor country

2011-01-21 Thread Piyush Verma
-- *Piyush Verma* *MNNIT Allahabad* -- 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 algogeeks+unsubscr...@googlegroups.com. For

Re: [algogeeks] Adobe Question

2011-01-21 Thread Divya Jain
if both arrray are sorted. take two ptrs, one pointing to a[0] other to b[0]. if elements are same then nt disjoint. else increment ptr pointing to smaller element until it becomes equal or greater than the element pointed by other. repeat until either ptr reaches end of array.. On 21 January

[algogeeks] Re: find a line

2011-01-21 Thread Dave
@Divya: The coordinates of the points are between 0 and 1 and are integers. That can't be right. Dave On Jan 21, 1:46 pm, divya sweetdivya@gmail.com wrote: Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide

Re: [algogeeks] Google Question

2011-01-21 Thread aniket chatterjee
It will be like a circularly sorted array.There exists a binary search type divide and conquer mechanism to find a specific number in such type of arrays. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] sorted array inplace merge

2011-01-21 Thread snehal jain
Given an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space]. e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8] i have thought of