Re: [algogeeks] Print all possible valid set of given numer

2012-09-09 Thread Pritpal S
@Atul, Bharat : it might be needed if 0 is the part of original number. On Fri, Sep 7, 2012 at 1:28 AM, atul anand atul.87fri...@gmail.com wrote: correct... On 9/6/12, bharat b bagana.bharatku...@gmail.com wrote: no need to look for 3 or above digits .. On Thu, Aug 23, 2012 at 11:11 AM,

Re: [algogeeks] Print all possible valid set of given numer

2012-09-09 Thread bharat b
@pritpal : even if 0 is part of number .. we don't usually write any positive number starts with 0 right ... On Sun, Sep 9, 2012 at 9:47 PM, Pritpal S pritpal2...@gmail.com wrote: @Atul, Bharat : it might be needed if 0 is the part of original number. On Fri, Sep 7, 2012 at 1:28 AM, atul

Re: [algogeeks] Print all possible valid set of given numer

2012-09-06 Thread bharat b
no need to look for 3 or above digits .. On Thu, Aug 23, 2012 at 11:11 AM, atul anand atul.87fri...@gmail.comwrote: divide number into digit form and save to arr[] input=1234 formed arr[]={1,2,3,4}; print elements for arr[]; now make set of 2 , 3, 4, i.e when i=2; we get *12*,3,4

Re: [algogeeks] Print all possible valid set of given numer

2012-09-06 Thread atul anand
correct... On 9/6/12, bharat b bagana.bharatku...@gmail.com wrote: no need to look for 3 or above digits .. On Thu, Aug 23, 2012 at 11:11 AM, atul anand atul.87fri...@gmail.comwrote: divide number into digit form and save to arr[] input=1234 formed arr[]={1,2,3,4}; print elements for

[algogeeks] Print all possible valid set of given numer

2012-08-22 Thread zeroByZero
A set will be call valid if all number can be represent as a alphabet (ie number should be less than or equal to 26) . Example : given number is 1234 then 1) {1,2,3,4} - valid ans 2){12,3,4} - Valid 3){1,23,4} -Valid 4){1,2,34} -not valid 5){123,4} - not valid 6){1234} not valid So for given

Re: [algogeeks] Print all possible valid set of given numer

2012-08-22 Thread atul anand
divide number into digit form and save to arr[] input=1234 formed arr[]={1,2,3,4}; print elements for arr[]; now make set of 2 , 3, 4, i.e when i=2; we get *12*,3,4 1,*23*,4 1,2,*34* i=3 *123*,4 1,*234* i=4 *1234* On Wed, Aug 22, 2012 at 6:34 PM, zeroByZero shri.nit...@gmail.com wrote: A set

[algogeeks] Re: count possible number of binary search trees, given number of nodes

2012-02-29 Thread Gene
A related interesting problem is counting binary set hierarchies: the number of perfect binary trees you can build over the same set of n=2^k leaves, where there is no distinction between left and right children. In other words, starting with n=2^k elements, put them into disjoint sets of 2

[algogeeks] Re: count possible number of binary search trees, given number of nodes

2012-02-14 Thread Don
For a binary search tree the solution is called the Catalan Numbers. The formula is (2n)!/(n!(n+1)!) The first few terms are: 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640,

Re: [algogeeks] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-02-11 Thread Moheed Moheed Ahmad
Yeah, its BST(given that each node's data is different from others.) -Moheed I am who I am, no matter where I am or who I am with. * * On Fri, Feb 10, 2012 at 5:07 PM, Manni mbd mbd2...@gmail.com wrote: are you sure u want to ask BINARY SEARCH treees and not Binary trees.. On 1/29/12,

Re: [algogeeks] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-02-11 Thread praveen raj
It will be very helpful if u could tell me for binary search tree and binary tree both... PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- 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] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-02-10 Thread Manni mbd
are you sure u want to ask BINARY SEARCH treees and not Binary trees.. On 1/29/12, Moheed Moheed Ahmad mohe...@gmail.com wrote: I know how to solve it programatically, can anybody pls help me to solve it using combinatorics. -Moheed -- You received this message because you are subscribed to

[algogeeks] [Combinatorics] count possible number of binary search trees, given number of nodes

2012-01-29 Thread Moheed Moheed Ahmad
I know how to solve it programatically, can anybody pls help me to solve it using combinatorics. -Moheed -- 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

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-10 Thread atul anand
@Piyush:.. nope is not correct ... this is right 0 1 2 3 0 1 0 0 0 1 1 0 1 0 2 1 0 1 0 3 1 0 1 0 4 1 0 1 0 use this code to precompute.. A[i,j] = A[i-1, j]; if ( A[i, j] == 0 and j - W[i] =0) A[i, j] = A[i -1, j - W[i]]; On Tue, Jan 10, 2012

[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Siddhartha
@lucifer and others: does this work for negative elements? What to do then??? -- 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: Maximal possible subsets Algorithm

2012-01-09 Thread atul anand
@Siddhartha : i dont think so this will work for -ve number because we are doing A[ i - 1, j - W[i] ] so if W[i] is -ve number then it would increases Wmax which is the number of column. i guess same algo can be modified so as to make it work for -ve number. On Mon, Jan 9, 2012 at 2:23 PM,

[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Siddhartha
yup...that was what i was thinking... i guess for negative nos, we can define Wmax= sum of modulus of weights,and then the same algo works... -- 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: Maximal possible subsets Algorithm

2012-01-09 Thread Lucifer
@All The same algo will work for both +ve and -ve nos.. no need for modification.. For ex- Say the sum is 4 and the set is { 1, 2, 3, -2 } Now if u include -2 as part of ur solution then for the rest 3 elements the sum would be 4-(-2) = 6, which is correct... On Jan 9, 2:20 pm, Siddhartha

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-08 Thread atul anand
@Lucifer : got it ..nice and clear :) :). On Sun, Jan 8, 2012 at 10:05 AM, Lucifer sourabhd2...@gmail.com wrote: @atul.. The table is used to record the state of subsets not print them.. (I am assuming that's what u meant)..Hence keeping that in mind, yes it captures all subsets... Now

[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread atul007
@Lucifier: i guess you made some editing mistake :- Initialize the array with the following values, 1) A[0, j] = 0 for 1 = j = Wmax 2) A[i, 0] = 1 for 0 = i = Wmax // it shoud be 1 for 0 = i =N about this equation :- A[i , j] = A[i-1, j] | A[ i-1 , j - W[i] ] say if W[i]=10 and j=3 , i

[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread Lucifer
@atul.. I thought that check would be obvious as i didn't put in the code.. so when the code is written for the second option we need to also check for j-W[i] =0.. :)... On Jan 7, 9:15 pm, atul007 atul.87fri...@gmail.com wrote: @Lucifier: i guess you made some editing mistake :- Initialize

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread atul anand
@Lucifer : thats okbut you are using bitwise OR to fill up the array A[]. if condition does not fullfill then wat to do to fill A[i,j] ?? i guess take it 0 if it does not fullfill.. A[i , j] = A[i-1, j] | 0 // A[ i-1 , j - W[i] ] check fail i didnt read your whole algorithm so i

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread atul anand
@Lucifer : for W[]={1,3,2,1,2} and Wmax=4. this array will be formed. 0 1 2 3 4 0 1 0 0 0 0 1 1 1 0 0 0 3 1 1 0 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 is it printing all subset ?? if yes then may be i am not getting it.. btw one query :- b) if

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread sravanreddy001
any comments of the following approach. first sort the weights, find the 'j' such that sum( wts from w1 until wj) Wmax sum( wts from W1 until Wj+1) Wmax also 'k' such that sum(wts from Wk to Wn) Wmax sum(wts from Wk-1 to Wn) Wmax so, a = j ( is the max number of elements in any subset,)

[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-07 Thread Lucifer
@atul.. The table is used to record the state of subsets not print them.. (I am assuming that's what u meant)..Hence keeping that in mind, yes it captures all subsets... Now once A[N, K] is 1 that means there are some subsets whose sum will be equal to K. Hence, to find all such subsets we will

[algogeeks] Re: All possible permutations of a given string

2011-12-28 Thread ravu sairam
In the link you have specified they are talking about using the C++ STL . I would like to know how is that STL implemented -- 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: All possible permutations of a given string

2011-12-28 Thread ravu sairam
What are the parameters it is taking i and j? What are those? We only have to permute(s)-where s is the string. -- 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

[algogeeks] Re: All possible permutations of a given string

2011-12-28 Thread Gene
Don't forget repeats. The string aaa has only one permutation. A related interesting question is how to write a permutation iterator. Here is the interface: typedef struct { // your code here } PERMUTATION_ITERATOR; /* Initialize the given permutation iterator with the string of n

[algogeeks] Re: All possible permutations of a given string

2011-12-28 Thread Lucifer
@ravu I have mentioned how next permutation works.. Also i have given an example in another post. Please go thru the link.. On Dec 28, 10:47 pm, Gene gene.ress...@gmail.com wrote: Don't forget repeats.  The string aaa has only one permutation. A related interesting question is how to write a

[algogeeks] Generate all possible binary trees given in-order traversal

2011-12-27 Thread bugaboo
Given an inorder traversal only for a binary tree (not necessarily a BST), give a pseudo code to generate all possible binary trees for this traversal sequence. Firstly, how many binary trees can be generated given an in-order traversal? I know that given 'n' nodes, number of BTs possible is

[algogeeks] Re: All possible permutations of a given string

2011-12-27 Thread SAMMM
Have a look at this algo :- Steinhaus–Johnson–Trotter 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 unsubscribe from this group, send email to

[algogeeks] Re: All possible permutations of a given string

2011-12-27 Thread Lucifer
This might help.. http://groups.google.com/group/algogeeks/browse_thread/thread/d3dafdcd53f101a9# On Dec 28, 11:53 am, SAMMM somnath.nit...@gmail.com wrote: Have a look at this algo :-  Steinhaus–Johnson–Trotter algorithm . -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: All possible permutations of a given string

2011-12-27 Thread Karthikeyan V.B
Hi, Using Backtracking, void swap(char* x,char* y) { char temp; temp=*x; *x=*y; *y=temp; } void permute(char* a,int i,int n) { int j; if(i==n) printf(%s\n,a); else { for(j=i;j=n;j++) { swap((a+i),(a+j)); permute(a,i+1,n); swap((a+i),(a+j)); } } } But this takes O(n*n!) time -- You received

[algogeeks] Best algorithm possible

2011-12-12 Thread KAY
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 eg: 2 3 5 78 ans: 78532 -- 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: Maximal possible subsets Algorithm

2011-12-05 Thread sourabh
@ Piyush.. I have a doubt... Is there any significance of the value Vi, if yes then can u give an example. If not, then is your question about finding all maximum subsets where the addition of the weights results in maximum (each weight being considered only once)... Say for ex- The max weight is

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread Piyush Grover
As such there's no significance for Vi, it's just to show that objects are not identical. We don't need to maximize on V. For the sake of problem you can ignore it. We can use the sum of values for other purpose. Take an examole: S= {1, 2, 3, 4, 5} are weights (I am not using Values) . Wmax = 8

[algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread WgpShashank
@piyuesh , Saurabh isn't 3-Sum Suffics Here ? Another thought problem can also be thought by generating power set of given set e.g. if set has n elemnts its power set has 2^n elements , then finds the set that has sum up yo given weight isn't it ? hope you know how to find power set

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread Piyush Grover
As I mentioned earlier solution with exponential time-complexity is the obvious one. Is there any way to solve this problem by greedy/Dynamic algo? On Mon, Dec 5, 2011 at 5:24 PM, WgpShashank shashank7andr...@gmail.comwrote: @piyuesh , Saurabh isn't 3-Sum Suffics Here ? Another thought

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread Shashank Narayan
@piyuesh 3-Sum is not exponential ? its quadratic , check wiki for refrence ? On Mon, Dec 5, 2011 at 5:36 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: As I mentioned earlier solution with exponential time-complexity is the obvious one. Is there any way to solve this problem by

[algogeeks] Find all possible paths(Amazon)

2011-11-20 Thread SAMMM
Given a (Directed/Non Directed) graph and a source node and destination node . Now your task is to find all the paths from a source node to the destination node . Both for directed and non directed graph. -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Find all possible combination of integers for a given sum

2011-10-25 Thread Prem Krishna Chettri
Its a subset Manipulation Problem.. Very simple logic.. Can Use Recursion for even more simplicity.. Call Recursion one with that element and once wdout.. On 10/25/11, Meng Yan mengyan.fu...@gmail.com wrote: Hi, my question is given sum=N and combination constraint=M (the number of elements),

[algogeeks] Find all possible combination of integers for a given sum

2011-10-24 Thread Meng Yan
Hi, my question is given sum=N and combination constraint=M (the number of elements), how to find all possible combinations of integers? For example, given sum=6, combination=3; how to get the result as following: 1+1+4; 1+2+3; 2+2+2; We don't care about order of the elements, which means 1+1+4

Re: [algogeeks] is it possible??

2011-10-01 Thread Hatta
in code bellow you declare main because any executable needs an entrypoint you cannot fake that anyway, it doesn't use main at all to invoke those functions. http://www.geeksforgeeks.org/archives/14538 #includestdio.h /* Apply the constructor attribute to myStartupFun() so that it is

Re: [algogeeks] is it possible??

2011-09-29 Thread UTKARSH SRIVASTAV
you can use _start function in c and then compile with gcc -nostartfile On Mon, Sep 19, 2011 at 2:39 PM, Prakash D cegprak...@gmail.com wrote: in c/c++ without main function how to write a compilable code? for example printing a string On Tue, Sep 20, 2011 at 12:15 AM, hary rathor

Re: [algogeeks] is it possible??

2011-09-29 Thread Hatta
in ELF compatible binaries it's also possible to use .ctors / .dtors not sure whether PES has similar sections but I believe it does. On Thu, Sep 29, 2011 at 3:42 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: you can use _start function in c and then compile with gcc -nostartfile On

[algogeeks] is it possible??

2011-09-19 Thread cegprakash
is it possible to print something without a main function?? I wonder how the code won't get any compile error -- 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

Re: [algogeeks] is it possible??

2011-09-19 Thread hary rathor
use #pragma in c . static block in java . by the way which lang you are talking about ? -- 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

Re: [algogeeks] is it possible??

2011-09-19 Thread Prakash D
in c/c++ without main function how to write a compilable code? for example printing a string On Tue, Sep 20, 2011 at 12:15 AM, hary rathor harry.rat...@gmail.comwrote: use #pragma in c . static block in java . by the way which lang you are talking about ? -- You received this message

[algogeeks] Re: Maximum possible edges in a graph

2011-09-06 Thread Shuaib Khan
I don't have a formal proof yet, but can anyone give a counter test case to following: Let f(n) be our function: if n is even: f(n) = (n^2)/4 else: f(n) = ((n-1)^2)/4 + (n-1)/2 On Wed, Sep 7, 2011 at 5:36 AM, Shuaib Khan aries.shu...@gmail.com wrote: What is the maximum number of edges

[algogeeks] Re: Maximum possible edges in a graph

2011-09-06 Thread Shuaib
Actually it is a bipartite graph. Thus answer equal to floor(n/2)*ceil(n/2). -- Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 07-Sep-2011, at 7:30 AM, Shuaib Khan aries.shu...@gmail.com wrote: I don't have a formal proof yet, but can anyone give a counter test case to

[algogeeks] is it possible to access data from memory location 0?

2011-08-26 Thread siddharam suresh
Thank you, Siddharam -- 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,

Re: [algogeeks] is it possible to access data from memory location 0?

2011-08-26 Thread SANDEEP CHUGH
no it results in segmentation fault On Fri, Aug 26, 2011 at 3:48 PM, siddharam suresh siddharam@gmail.comwrote: Thank you, Siddharam -- 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] is it possible to access data from memory location 0?

2011-08-26 Thread siddharam suresh
but its its valid address right Thank you, Sid. On Fri, Aug 26, 2011 at 8:16 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: no it results in segmentation fault On Fri, Aug 26, 2011 at 3:48 PM, siddharam suresh siddharam@gmail.com wrote: Thank you, Siddharam -- You

Re: [algogeeks] is it possible to access data from memory location 0?

2011-08-26 Thread UTKARSH SRIVASTAV
i think it is reserved for system functions and you are not allowed to work as your program is not alloted that area if somehow your program is allowed that area there will be no segmentation fault On Fri, Aug 26, 2011 at 7:57 AM, siddharam suresh siddharam@gmail.comwrote: but its its valid

Re: [algogeeks] is it possible to access data from memory location 0?

2011-08-26 Thread saurabh singh
0 is reserved as the address which can't be referenccd On Fri, Aug 26, 2011 at 9:08 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: i think it is reserved for system functions and you are not allowed to work as your program is not alloted that area if somehow your program is allowed

[algogeeks] Is it possible to determine an n-ary tree nodes depth given its index?

2011-08-01 Thread Douglas
I have a full n-ary tree with N nodes. The top node is indexed 0 with all other nodes indexed incrementally from left to right as we decend the tree. The last node has index N-1. For example, a 15 node binary tree would be indexed as follows: 0 1,2 3,4,5,6 7,8,9,10,11,12,13,14 So, my question

[algogeeks] Closest as Possible

2011-07-26 Thread rShetty
Problem statement goes as : Consider square root of integers form 1 to 100. Now partition the square roots of integers as being from 1 to 50 and 51 to 100. Now find the sum in the two partitions which is as close as possible or minimum? Give the algorithm ?? and das structures to be used?? --

Re: [algogeeks] Closest as Possible

2011-07-26 Thread Puneet Gautam
@rshetty: do u mean the sum of any no of elements separately in the two partitions be equal to each other..? is that what u mean..? On 7/26/11, rShetty rajeevr...@gmail.com wrote: Problem statement goes as : Consider square root of integers form 1 to 100. Now partition the square roots of

Re: [algogeeks] Closest as Possible

2011-07-26 Thread rajeev bharshetty
Sum of any number of elements on the two partitions should be as close as possible. On Tue, Jul 26, 2011 at 6:49 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: @rshetty: do u mean the sum of any no of elements separately in the two partitions be equal to each other..? is that what u mean..?

Re: [algogeeks] Closest as Possible

2011-07-26 Thread saurabh singh
Is answer 0 ?? On Tue, Jul 26, 2011 at 7:41 PM, rajeev bharshetty rajeevr...@gmail.comwrote: Sum of any number of elements on the two partitions should be as close as possible. On Tue, Jul 26, 2011 at 6:49 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: @rshetty: do u mean the sum of any

[algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread snehi jain
this question was asked in an interview. Regards Snehi -- 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread ankit sambyal
Are the elements of the array in some order, or are they random ? -- 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread snehi jain
the elements are random ... On Tue, Jul 19, 2011 at 12:01 AM, Saket Choudhary sake...@gmail.com wrote: Yeah if they are in some order then its possible doing it in O(n) else reading should itself take O(n^2) in the worst case. On 18 July 2011 23:54, ankit sambyal ankitsamb...@gmail.com

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread ankit sambyal
@Snehi :If the elements are random, then it seems that this problem can't be solved in O(n) time -- 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,

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread snehi jain
can it be solved in less than O(n^2) like O(nlogn ) types.. i cant figure out any solution less than O(n^2). On Tue, Jul 19, 2011 at 12:37 AM, ankit sambyal ankitsamb...@gmail.comwrote: @Snehi :If the elements are random, then it seems that this problem can't be solved in O(n) time -- You

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
what would be the O(n^2) sol. to this ...!! On Tue, Jul 19, 2011 at 12:41 AM, snehi jain snehijai...@gmail.com wrote: can it be solved in less than O(n^2) like O(nlogn ) types.. i cant figure out any solution less than O(n^2). On Tue, Jul 19, 2011 at 12:37 AM, ankit sambyal

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Saket Choudhary
Have a hash Table. Read the elements and push it to the hash table. If it alraedy exists you are done. On 19 July 2011 01:02, Shubham Maheshwari shubham.veloc...@gmail.comwrote: what would be the O(n^2) sol. to this ...!! On Tue, Jul 19, 2011 at 12:41 AM, snehi jain

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Saket Choudhary
Ruby Solution for 1d array. The logic for 2d array remains same. a=[1,2,3,4,5,1] b=[] for m in a unless b.include?(m) bm else puts m break end end On 19 July 2011 01:05, Saket Choudhary sake...@gmail.com wrote: Have a hash Table. Read the elements and push it to the hash

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
can we do anything else .. othr than hash tables ... On Tue, Jul 19, 2011 at 1:05 AM, Saket Choudhary sake...@gmail.com wrote: Have a hash Table. Read the elements and push it to the hash table. If it alraedy exists you are done. On 19 July 2011 01:02, Shubham Maheshwari

Re: [algogeeks] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Saket Choudhary
Ya. Have an extra array of size(nxn). the one that I have implemented above. -- 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] is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Shubham Maheshwari
the complexity of this func depends on the .include thing, and if it were to be coded in C, time cmplexity wud to to n^2. On Tue, Jul 19, 2011 at 1:12 AM, Saket Choudhary sake...@gmail.com wrote: Ruby Solution for 1d array. The logic for 2d array remains same. a=[1,2,3,4,5,1] b=[] for m in

[algogeeks] Generate all possible Interleavings of two arrays

2006-05-12 Thread Imran Mohammed Abdul Muqsith
Hi, Can anyone give the algo to generate all possible interleavings of two arrays (better if its in C or Java) E.g. A1[] = {a,b};B1[] = {c,d}; # Results = (2+2)!/(2! .2!) = 6 abcdacbdacdbcabdcadbcdab -- Mohammed Abdul Muqsith ImranDepartment of Computer Science and Engineering,Indian Institute