Re: [algogeeks] 4Sum

2012-06-18 Thread KK
@Hemesh : +1 @Jalaj : read Hemesh's solution again it is for 4sum. In short, make a new array having sum of each unique pair of given array. - O(n^2) sort it - O(n^2) for each number bi in new array, binary search (target - bi) in the same array - O(n^2) On Sunday, 17 June 2012 12:41:40

[algogeeks] SPOJ Problems SCUBADIV

2012-06-18 Thread Rituraj
Hi, I am trying to solve this problem. http://www.spoj.pl/problems/SCUBADIV/ But I am getting a lot of WAs! Any good logic(Solution) to solve the problem? Thanks in advance for your reply. Rituraj 2nd year B.Tech(CSE) NIT-Patna -- You received this message because you are subscribed to

Re: [algogeeks] Analysis of Partial Sorting.

2012-06-18 Thread Amitesh Singh
Thanks Hassan. But I was more interested in knowing the mathematic proof of Partial Quick Sort. -- Amitesh On Sun, Jun 17, 2012 at 7:54 PM, Hassan Monfared hmonfa...@gmail.comwrote: O(N*logM) On Sat, Jun 16, 2012 at 5:15 PM, Amitesh Singh singh.amit...@gmail.comwrote: Hi Guys,

Re: [algogeeks] expectation values..

2012-06-18 Thread Gaurav Popli
http://www.spoj.pl/problems/FAVDICE/ On Sun, Jun 17, 2012 at 8:43 PM, Doom duman...@gmail.com wrote: If we expand it.. E(t) = E(t1) + E(t2) + E(t3) + ... + E(tn); here I am able to derive E(t1) as N/1 using the expression E(t1) = 1/N + ((N-1)/N)(E(t1) + 1); but how do I proceed? How do I

Re: [algogeeks] Find the Max from each sub-array of size k

2012-06-18 Thread Ramindar Singh
We can also build a Balanced BST for the window elements and on each shift we need to have a delete operation and add oeration. O(n logk) Also we can add the Shashank algo where we check if the newly added element is greater than the current BST's max element. So we can discard the current BSt

[algogeeks] Re: Microsoft question

2012-06-18 Thread Ramindar Singh
We can use Median of medians http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array.

Re: [algogeeks] I need

2012-06-18 Thread adarsh kumar
This is typical knapsack problem. On Mon, Jun 18, 2012 at 10:33 AM, Rituraj worstcod...@gmail.com wrote: Hi, I am trying to solve this problem. http://www.spoj.pl/problems/SCUBADIV/ But I am getting a lot of WA! Any good logic(solution) to solve the problem? Thanks in advance for your

[algogeeks] Re: Microsoft question

2012-06-18 Thread enchantress
Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1 to k min_index = i for j i+1 to n if a[j] a[min_index] min_index = j swap(a[i],a[min_index]) required element : a[k] On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give

Re: [algogeeks] 4Sum

2012-06-18 Thread Amol Sharma
@hemesh,kk: let's take a test case : arr: 2 4 6 8 arr^2 : 6 8 10 10 12 14(sum of each unique pair in arr[i]) let's say target sum is 26 your solution will return true as they 12+14=26 but in 12 and 14, 8 is common, infact 26 is not possible in the given array can u

[algogeeks] spoj problem : POKER

2012-06-18 Thread Mayank Singh
here is my code: #includestdio.h #includestring.h #includestdlib.h int main() { int t,i,j,k1,k2,ans[40],sum,sum1; char str[40][20],str1[6],str2[6]; scanf(%d,t); for(i=0;i=t;i++) { gets(str[i]); } for(i=1;i=t;i++) { for(j=1,k1=0;j15,k15;j=j+3,k1++)

[algogeeks] Re: spoj problem : POKER

2012-06-18 Thread Mayank Singh
it also ran successfully on ideone.com plz help me i am classifying the card in two parts: one with same suit and other with different suit... plz let me know if futher explanation is needed abt the code help me regarding this.. thanx -- You received this message because you are subscribed

RE: [algogeeks] Precedence or Associativity

2012-06-18 Thread Ashot Madatyan
Let us see what we have - we basically have an expression A || B C. We also know the following: 1. || and are both considered sequence points 2. The has precedence over the || operator 3. The C/C++ languages use minimal evaluation principle when evaluating the logical expressions (see the

Re: [algogeeks] Re: spoj problem : POKER

2012-06-18 Thread Pranjal Patil
Your code fails on one of the test cases like 5H 6H 7H 8H 9H. it should give straight flush instead of flush, Think of all such cases are change accordingly .. On Mon, Jun 18, 2012 at 10:01 PM, Mayank Singh singh13490may...@gmail.com wrote: it also ran successfully on ideone.com plz help me i

Re: [algogeeks] 4Sum

2012-06-18 Thread utsav sharma
@hemesh :- please explain your approach On Mon, Jun 18, 2012 at 2:58 PM, Amol Sharma amolsharm...@gmail.com wrote: @hemesh,kk: let's take a test case : arr: 2 4 6 8 arr^2 : 6 8 10 10 12 14(sum of each unique pair in arr[i]) let's say target sum is 26 your

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Abhishek Sharma
In a stack, you can't access any element directly, except the top one. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h int main() { int stack[]={1,2,3,4,5,6,7,8},top=7;// int i,j,temp; for(i=1;i=top;i++) {

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread aditya gupta
this is not a stack at all, u have just named it as a stack. for it to be a stack u should access only the top most element at any point of time!!! On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h int main() { int

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Prem Nagarajan
I think there is a problem in this solution. U r accessing stack elements from 1 to n in the outer loop. It is not possible. 1st element cannot be accessed without popping first n-1 elements out. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach

Re: [algogeeks] Re: Microsoft question

2012-06-18 Thread Prem Nagarajan
@enchantress : This problem can be solved using quicksort in O(nlogn). No need to go for selection sort. But O(n) solution is needed. On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.com wrote: Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1

Re: [algogeeks] Re: Directi question-centre of the tree

2012-06-18 Thread rajesh pandey
I found it in some paper ;) Diameter and center De nition 4. The diameter of tree is the length of the longest path. De nition 5. A center is a vertex v such that the longest path from v to a leaf is minimal over all vertices in the tree.Tree center(s) can be found using simple algorithm.