[algogeeks] Re: stacks

2011-07-23 Thread ross
Well. the idea of an array is - given an integer 'i', you should support RANDOM ACCESS to the ith element in the 1d array. Since, we have two stacks, if you want to access an ith element ( say, i = 5 ),pop all the top 4 elements from the 1st stack and push it to the second stack. Now, access the

[algogeeks] Re: MS

2011-07-23 Thread ross
@akshata sharma: Kindly post a new question as a separate thread and not as a reply to an existing one so tat it would be noticed by many ppl! As akash suggestd, use a bit vector called 'visited' of 26 size for ASCII or of a larger size in case of Unicode ( still constant space and i dont think

[algogeeks] Re: Sum to K problem

2011-07-02 Thread ross
                cout\nPossible Subset not present;         cin.get();         return 0; } On Fri, Jun 24, 2011 at 11:42 PM, ross jagadish1...@gmail.com wrote: This is the subset sum problem which is NP,. The DP is as follows, M[i,j] = 1 , if a subset of first i elements has a sum = j

[algogeeks] Re: Queue to support insert , delete, find max in o(1)

2011-06-26 Thread ross
@Divye: Awesome solution dude with amortized complexity of O(1)! The examples made things even clearer :) On Jun 26, 8:13 am, DK divyekap...@gmail.com wrote: I've solved it for find_min() - the find_max implementations are analogous. Example: i = insert d = delete i 1 - q - 1 dq - 1 --

[algogeeks] Sorting Array

2011-06-26 Thread ross
Given a sequence of numbers in the range of 1-N^2, what is the most efficient way to sort the numbers (better than NlgN).. Can counting sort be used here? Is an O(N) solution possible.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
that the person asking this question wanted O(n) ? On Jun 26, 1:31 pm, radha krishnan radhakrishnance...@gmail.com wrote: Yes ! Count Sort !! On Sun, Jun 26, 2011 at 1:44 PM, ross jagadish1...@gmail.com wrote: Given a sequence of numbers in the range of 1-N^2, what is the most

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@L: It was asked if we could take advantage of the ranges of the integers between 1-N^2.. I doubt if its possible. On Jun 26, 5:33 pm, ross jagadish1...@gmail.com wrote: @radhakrishnan: Counting sort in this case, will be O(n2).. as it involves traversing the entire array! On Jun 26, 5:03 pm

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
: @ross: I guess the orignal problem is that there are N numbers which are all in the range [1, N * N], can you do the sorting in O(N) time complexity? If this is true,  we can firstly  do the discretization and then do the counting sort. -- You received this message because you are subscribed

[algogeeks] Product of N numbers - with Constraints

2011-06-26 Thread ross
Given an array A , of N integers ( In no particular order), fill up an auxilary array B such that B[i] contains the product of all elements in A other than A[i]. Constraints: O(n) Time, Can this be done with O(1) space? Division is *not* allowed . eg: A 1 2 3 4 5 B 120 60 40 30 24 -- You

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@Divye: Good theoretical proof and analysis as well.. As you mentioned, this one works like charm for uniformly distributed inputs :) On Jun 26, 8:36 pm, DK divyekap...@gmail.com wrote: Use a radix sort. Complexity of the radix sort is O(N k) where k is the number of digits used to represent

[algogeeks] Re: Product of N numbers - with Constraints

2011-06-26 Thread ross
is good. On Jun 26, 9:47 pm, Ashish Goel ashg...@gmail.com wrote: this is goog question Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sun, Jun 26, 2011 at 10:04 PM, Dave dave_and_da...@juno.com wrote: @Ross: This satisfies your

[algogeeks] Queue to support insert , delete, find max in o(1)

2011-06-24 Thread ross
Hi, I know that a stack can be modified with another stack to support push pop min in const time. Design a FIFO data structure to support ins, del, and find min in O(1). Extra space allowed. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: Queue to support insert , delete, find max in o(1)

2011-06-24 Thread ross
, ross jagadish1...@gmail.com wrote: Hi, I know that a stack can be modified with another stack to support push pop min in const time. Design a FIFO data structure to support ins, del, and find min in O(1). Extra space allowed. -- You received this message because you are subscribed

[algogeeks] Re: Queue to support insert , delete, find max in o(1)

2011-06-24 Thread ross
that issue...then we can use the same logic of using one more stack that we use for implementing modified stack keeping track of the min()..I hope this will solve the issue On Fri, Jun 24, 2011 at 3:57 PM, ross jagadish1...@gmail.com wrote: @piyush, Dude, how will that make findmin

[algogeeks] Re: Sum to K problem

2011-06-24 Thread ross
This is the subset sum problem which is NP,. The DP is as follows, M[i,j] = 1 , if a subset of first i elements has a sum = j. else 0, The recurrence is, M[i,j] = max(M[i-1,j] , M[i-1,j-Ai]) where Ai is the ith element. You can maintain back pointers to keep track of previous elements so that

[algogeeks] Sort - Consecutive Array in O(n)

2011-06-24 Thread ross
Given an array, A, find if all elements in the sorted version of A are consecutive in less than O(nlogn). eg: A: 5 4 1 2 3 on sorting 1 2 3 4 5 all elements are consecutive -- true A: 1 9 2 22 on sorting 1 2 9 22 all elements are NOT consecutive - false -- You received this message because you

[algogeeks] Re: Sort - Consecutive Array in O(n)

2011-06-24 Thread ross
One solution would be to : check if max-min = N and that all elements are unique in the array. However, this may require space complexity.. Looking for a better solution. On Jun 25, 12:44 am, ross jagadish1...@gmail.com wrote: Given an array, A, find if all elements in the sorted version

[algogeeks] Re: Question on Combination

2011-06-23 Thread ross
= index to N *and then call             *printcombinations(a,sum-a[i],level+1,index+1); *I think it will work then...   On Thu, Jun 23, 2011 at 10:48 AM, ross jagadish1...@gmail.com wrote: Given an array and a sum S output all combinations of elements that sum to S. eg: 1 2 3 sum

[algogeeks] Re: strings

2011-06-22 Thread ross
@Harshal, Even if you use a buffer of size 256 it is still O(1), because 256 is a constant invariant of n... Ur solution is correct! On Jun 22, 10:24 am, Harshal hc4...@gmail.com wrote: ignore above solution. My bad, did'nt see O(1) space constraint!! On Wed, Jun 22, 2011 at 10:53 AM,

[algogeeks] Re: sort the array

2011-06-22 Thread ross
@himanshu: I dont think, the approach works, in present form. in place merge sort or insertion sort is fine. Test with, 12 13 19 16 and 0 20 10 14 as 2 parts of the array. On Jun 22, 8:42 am, Sriganesh Krishnan 2448...@gmail.com wrote: ya...we can do it in O(n) n time!!! nice question! On

[algogeeks] Question on Combination

2011-06-22 Thread ross
Given an array and a sum S output all combinations of elements that sum to S. eg: 1 2 3 sum = 3 1+1+1, 2+1 3 I came up with the foll algorithm, but it outputs 2+1 and 1+2 again. (does not handle repetitions) printcombinations(int a[],int sum,int level) { if(sum==0) { print array} else if (sum0)

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread ross
Hi, Ya DP with memoization is best.. nCr= n-1Cr-1 + n-1 C r DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; (LINEAR SPACE COMPLEXITY is possible because at each time we require only 2 rows of the matrix) Base Cases, nCn = 1. DP[i,i]=1. 1Cn = 1 DP[1,j] =1. nC1 = n . nC0 = 1 for ( i = 0 - N ) for ( j= i -

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread ross
A small correction, j = 0 to i. On Jun 21, 2:01 pm, ross jagadish1...@gmail.com wrote: Hi, Ya DP with memoization is best.. nCr= n-1Cr-1 + n-1 C r DP]i,j] = DP[i-1,j-1] + DP[i-1,j]; (LINEAR SPACE COMPLEXITY is possible because at each time we require only 2 rows of the matrix) Base

[algogeeks] Re: How to remove duplicate element from array in one pass.

2011-06-13 Thread ross
@sunny agarwal: Yes, it would be considered constant space.. even if it required 1MB of space . By big oh notation of space, we mean cases where input size, 'n' tends to infinity and the space requirement of the algorithm proposed does not approach infinity. here, even if n-infinity, input size

[algogeeks] Re: Mathematical Induction

2011-06-13 Thread ross
@howtechstuffworks: Your question seems to be - why 'k+1' and not 'k+2' or 'k+3' or something else. The simple reason is that, Given that P('k') and P('k+1') is true, we can extend it for ANY value of k. (ie) k+2 , can be derived from 'k+1' by substituting k=k+1. similarly k+3 can be

[algogeeks] Sorting an array - using the foll functions

2011-06-12 Thread ross
There is an array in an external system (i.e. u cannot access the array elements directly). The system exposes 3 functions of O(1) - (assume) : length() - returns the length of the array. get(i) - returns the element at index i. reverse(i,j) - reverses the elements in the array from index i to

[algogeeks] Re: Sorting an array - using the foll functions

2011-06-12 Thread ross
@aashish, Yeah, i went through the link, nice one dude! But, i believe even that would be O(n2). On Jun 12, 2:42 pm, ross jagadish1...@gmail.com wrote: @piyush: Hi piyush, It is reverse the elements from i to j.. For example, 12 22 33 44 55 66 63 when given reverse (0,2) produces 33 22 12

[algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-12 Thread ross
+1 On Jun 12, 3:38 pm, Arpit Sood soodfi...@gmail.com wrote: @present moderators + admin atleast make those people as group moderators along with you who are active. On Sun, Jun 12, 2011 at 3:21 PM, Akshata Sharma akshatasharm...@gmail.comwrote: finally!!! finally!! we have

Re: [algogeeks]

2011-06-10 Thread ross
@sunny agarwal : i dont think, it is O(lgn) its not a BST and further u need to check for existence of y in the path from lca to x or lca to z., so it l be O(n).. On Jun 10, 1:57 pm, sunny agrawal sunny816.i...@gmail.com wrote: find common Ancestor of both. see if y lies on path from x or z to

[algogeeks] Re: Puzzle

2011-06-09 Thread ross
@lalit: The idea here would be for Train T, make it cross its own parachute first. Then move both the train fwd until the trailing train reaches a parachute. When the trailing train reaches the parachute of the leading train, make it move faster than the leading train . Naturally the leading train

[algogeeks] Re: MS Q

2011-06-09 Thread ross
An algorithm is: Have a bit array B of 256/65k size. If an color 'i' is encountered in the solution, set its B[i]=1; Traverse the solution array S, if(S[i]==B[i]) hits++; else if ( B[S[i]] ) pseudohits++; On Jun 10, 9:40 am, Harshal

[algogeeks] Difference btwn elements in a sorted array a-b=k

2011-06-07 Thread ross
Given an integer 'k' and an sorted array A (can consist of both +ve/- ve nos), output 2 integers from A such that a-b=k. PS: nlogn solution would be to check for the occurence of k-a[i] (using bin search) when you encounter a[i]. methods like hash consume space. Is an O(n) solution with O(1)

[algogeeks] Re: Difference btwn elements in a sorted array a-b=k

2011-06-07 Thread ross
the lower index while the other pointing the upper index?? On Tue, Jun 7, 2011 at 2:57 PM, ross jagadish1...@gmail.com wrote: Given an integer 'k' and an sorted array A (can consist of both +ve/- ve nos), output 2 integers from A such that a-b=k. PS: nlogn solution would be to check

[algogeeks] Re: Difference btwn elements in a sorted array a-b=k

2011-06-07 Thread ross
@piyush: in the case of a+b=k, assuming a and b are 2 ptrs to start and end, when u increase a, sum increases and when u decrease b sum decreases. i doubt if that s the same case for a-b.. On Jun 7, 2:47 pm, ross jagadish1...@gmail.com wrote: Can u use the same logic u use for a+b=k

[algogeeks] Re: Scheduling

2011-06-07 Thread ross
@Aakash Johari: Sorting works fine if all jobs can be completed in a day.. I have a modification to this question - suppose the time to do a job is not one day and is given as Ti for job i, then how should one solve it? On Jun 7, 11:58 am, Aakash Johari aakashj@gmail.com wrote: yes, it's

[algogeeks] Min Enqueue Dequeue in O(1)

2011-06-07 Thread ross
Design a Queue (strictly fifo) to support findmin, enqueue, dequeue in o(1). extra space allowed. (for a stack, its trivial with 2 stacks) Can the same approach be applied for a queue? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: get rid of sohail panzer spam

2011-06-07 Thread ross
i think each of us in the group should start to spam sohail panzer's gmail id in separate mails :P On Jun 7, 8:32 pm, nicks crazy.logic.k...@gmail.com wrote: haha...like it !! On Tue, Jun 7, 2011 at 8:04 AM, anshu anshumishra6...@gmail.com wrote: For those people who want to get rid of

[algogeeks] Re: Min Enqueue Dequeue in O(1)

2011-06-07 Thread ross
, Jun 7, 2011 at 9:26 PM, ross jagadish1...@gmail.com wrote: Design a Queue (strictly fifo) to support findmin, enqueue, dequeue in o(1). extra space allowed. (for a stack, its trivial with 2 stacks) Can the same approach be applied for a queue? -- You received this message because you

[algogeeks] Re: Samsung Bangalore is hiring a lot!!!!

2011-06-07 Thread ross
@sayan: thanks for the info :) Any idea on the compensation dude? On Jun 7, 10:53 pm, sayan nayak sayanna...@gmail.com wrote: :D.Sure.Afterall  Destiny is not a matter of chances,it all abt ur choices :) On Tue, Jun 7, 2011 at 11:20 PM, sunny agrawal sunny816.i...@gmail.comwrote:

[algogeeks] Re: Array Merge Problem

2011-06-06 Thread ross
, gets in the smallest elemnt of A and swaps it with the largest element of B. Hope its clear. On Jun 6, 11:15 am, Aakash Johari aakashj@gmail.com wrote: @ross: I couldn't get reddy's solution. Please explain. On Sun, Jun 5, 2011 at 10:50 PM, Deepak Jha deepak.127.0@gmail.comwrote

[algogeeks] Re: Peoplesoft Developer // Chicago, IL // 4 month contract+

2011-06-06 Thread ross
people like you pollute algogeeks!! Go get a life and get lost! We would love to work in the US but we are not here to get spammed by you. On Jun 7, 12:08 am, sohail panzer sohail.panz...@gmail.com wrote: Dear Consultant, Hope you are doing good, Please let me know if you are comfortable with

[algogeeks] Re: Array Merge Problem

2011-06-04 Thread ross
: A can contain any combination of nos 0,1,1.5 and B should contain 2 3 4 5 9 (in any order.) this example is given by ROSS itself. so sravanreddy solution is right , correct me if i'm wrong. On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote: @sravanreddy...logical bugs

[algogeeks] Intersection of 2 linked lists -

2011-06-02 Thread ross
Given 2 linked lists, determine whether they intersect or not? (question is not find the point of intersection, which i am sure can be done by computing the lengths of both lists (len1 and len2) and traversing the larger list by |len1 - len2| and traversing subsequently until 2 ptrs meet. I am

[algogeeks] Re: HOT HOT HOT!!! AIX Engineer position in Miami Florida

2011-06-02 Thread ross
@sohail panzer: PEOPLE LIKE YOU POLLUTE ALGOGEEKS. JUST SHUT UP AND STOP SPAMMING THIS GROUP!! On Jun 3, 1:36 am, sohail panzer sohail.panz...@gmail.com wrote:  Dear Professional, Hope you are doing well. I am a technical recruiter with Panzer Solutions LLC Software Implementing and IT

[algogeeks] Re: Intersection of 2 linked lists -

2011-06-02 Thread ross
linked lists Space Complexity : O(1) Ankit Sambyal BITS Pilani On Thu, Jun 2, 2011 at 11:54 AM, ross jagadish1...@gmail.com wrote: Given 2 linked lists, determine whether they intersect or not? (question is not find the point of intersection, which i am sure can be done by computing

[algogeeks] Re: HOT HOT HOT!!! AIX Engineer position in Miami Florida

2011-06-02 Thread ross
this group. Where is admin!!! On Fri, Jun 3, 2011 at 8:49 AM, ross jagadish1...@gmail.com wrote: @sohail panzer: PEOPLE LIKE YOU POLLUTE ALGOGEEKS. JUST SHUT UP AND STOP SPAMMING THIS GROUP!! On Jun 3, 1:36 am, sohail panzer sohail.panz...@gmail.com wrote:  Dear Professional

[algogeeks] Re: Intersection of 2 linked lists -

2011-06-02 Thread ross
Hi Arpit, I dont think this sort of intersection is possible.. A linked list has only one next pointer and it can point to single node only. In the counter example you gave, the next ptr of node 3 points to two nodes. So, such a case does not arise. On Jun 3, 9:26 am, Arpit Mittal

[algogeeks] Finding circle areas under dust bins

2011-05-31 Thread ross
Hi all, Given a huge circular area containing lot of people (whose positions are given as coordinates) how will you place dustbins in the area, such that no person has to move more than 100 metres to reach a dustbin. Minimize the number of dustbins. -- You received this message because you

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
@Anshu If you do add top bottom, left right element to the popped element in qeuue should you need to do it for each element in the matrix. So, will that not be O(n3)?? Clarify if i am wrong. On May 30, 9:52 am, Aakash Johari aakashj@gmail.com wrote: At the each level, traversed by BFS,

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
anshumishra6...@gmail.com wrote: @ross no, a particular element has to read only 5 times maximum. 1 reading (i,j) (if its flag is already false skip) 2 read by top element 3. read by bottom element 4 read by left element 5 read by right element coz atleast one of the this operation its flag

[algogeeks] Re: Finding Blocks in a matrix

2011-05-30 Thread ross
@anshu mithra: Hi, Thanks for clarifying! :) On May 30, 11:06 am, anshu mishra anshumishra6...@gmail.com wrote: main() { for (i = 0; i n; i++) {      for (j = 0; j n; j++)      {             if (flag[i][[j])            {                  bfs(mat, flag, i, j);                  count++;

[algogeeks] Binary Tree Problem

2011-05-30 Thread ross
Given a binary tree(not a BST) find the 2 nodes of the binary tree which are separated by maximum distance. By distance, we mean no. of edges in the path from node1 to node2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread ross
, 2011 at 1:26 PM, ross jagadish1...@gmail.com wrote: Given a binary tree(not a BST) find the 2 nodes of the binary tree which are separated by maximum distance.  By distance, we mean no. of edges in the path from node1 to node2. -- You received this message because you are subscribed

[algogeeks] Scheduling dp problem - MSFT interview

2011-05-30 Thread ross
You are given a sequence of jobs. The no. of days which each job takes to complete is also provided. You are also given the penalty amount to be paid per day each day a job left done. Give an optimal ordering among jobs to minimize penalty. There are no concurrent jobs. eg: Jobs:

[algogeeks] A Graph Problem

2011-05-29 Thread ross
There are n persons. You are provided with a list of ppl which each person does not like. Determine the minm no. of houses required such that, in no house 2 people should dislike each other. Is there a polynomial time solution exist for this? Or is this not solvable at all? -- You received this

[algogeeks] Re: A Graph Problem

2011-05-29 Thread ross
@anshu mishra: Yeah. Thanks! :) On May 30, 8:26 am, anshu mishra anshumishra6...@gmail.com wrote: it is exactly a graph coloring problem. so it has no polynomial order solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: Finding Blocks in a matrix

2011-05-29 Thread ross
@vishal Hi, I do not get you. Can you please elaborate a little more how you ll use hash? On May 30, 8:50 am, Vishal Thanki vishaltha...@gmail.com wrote: what about using a hash function? On Mon, May 30, 2011 at 10:18 AM, ross jagadish1...@gmail.com wrote: Given a matrix, you need

[algogeeks] Array Merge Problem

2011-05-28 Thread ross
Hi all, Given 2 sorted arrays: A and B each holding n and m elements respectively,. Hence, total no. of elements = m+n Give an algorithm to place the smallest 'm' elements(out of the m+n total available) in A and the largest 'n' elements in B. ( A and B need not be sorted in the end) eg: A : 1 2

[algogeeks] Re: Array Merge Problem

2011-05-28 Thread ross
@sravanreddy: Hey, Nice Solution :) cool! On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote: Maintain a pointer A_end = m-1; doing a comparision something similar to merge sort int i=0;j=0; while (i m){  if (a[i] b[j])   i++;  else{   swap(a[A_end],b[j])   A_end --;  

[algogeeks] Google Interview Question

2011-05-27 Thread ross
Hi all, Given an array of elements find the largest possible number that can be formed by using the elements of the array. eg: 10 9 ans: 910 2 3 5 78 ans: 78532 100 9 ans: 9100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Odd Even Sort array

2011-05-27 Thread ross
Hi all, Sort all elements in odd indices of an array in ascending order and even indices in descending order. Finally, rearrange so that all even indexed elements come first. eg: input – 7 2 6 4 8 3 1 even indexed : 7 6 8 1 = sort 8 7 6 1 odd indexed: 2 4 3 = sort 2 3 4 output – 8 7 6 1 2 3 4

[algogeeks] league problem

2009-05-04 Thread Ross
I have a problem where I'm putting a tennis league together under certain constraints: Each week, each player must play against a unique opponent. In addition, in a doubles league, each player must have a unique partner each week. There are limited numbers of courts. For example, if 11 people

[algogeeks] League Scheduling Problem

2008-12-10 Thread Ross
I have a problem which is a variation of the Sports League Scheduling Problem. This problem pertains specifically to a tennis league at my own sports club. Each winter, the pro puts out a blank sheet of paper for people to sign up for tennis leagues. From year to year, the number of people who