There are K pegs. Each peg can hold discs in decreasing order of radius
when looked from bottom to top of the peg. There are N discs which have
radius 1 to N; Given the initial configuration of the pegs and the final
configuration of the pegs, output the moves required to transform from the
There are K pegs. Each peg can hold discs in decreasing order of radius
when looked from bottom to top of the peg. There are N discs which have
radius 1 to N; Given the initial configuration of the pegs and the final
configuration of the pegs, output the moves required to transform from the
does this work if array elements are negative???
--
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
@Piyush : yes it works ... please check the link again ..Lucifer has added
more details to the same post for better explanation.
follow that link and if you have any queries post your queries on that old
link.
On Mon, Jan 9, 2012 at 1:04 PM, Piyush Grover piyush4u.iit...@gmail.comwrote:
Hi Atul
Given a set S, find all the maximal subsets whose sum = k. For example, if
S = {1, 2, 3, 4, 5} and k = 7
Output is: {1, 2, 3} {1, 2, 4} {1, 5} {2, 5} {3, 4}
Hint:
- Output doesn't contain any set which is a subset of other.
- If X = {1, 2, 3} is one of the solution then all the subsets of X {1}
@Piyush :
you are re-posting same problem which you had posted on 5 dec 2011.
check this link :-
http://groups.google.com/group/algogeeks/browse_thread/thread/8a58ea05c96f811b/ee74f8a4d7b68561?lnk=gstq=Maximal+possible+subsets+Algorithm#ee74f8a4d7b68561
On Mon, Jan 9, 2012 at 3:27 AM, Piyush
Hi Atul
Yes, I posted it earlier but couldn't keep track of it, thanks for the
link. I still have a doubt, does it give all the maximal subsets
or all the subsets. I couldn't get it from the algo posted by Lucifer.
On Mon, Jan 9, 2012 at 9:45 AM, atul anand atul.87fri...@gmail.com wrote:
refer algorithms by cormen for this
On Mon, Nov 28, 2011 at 9:56 PM, Nitin Garg nitin.garg.i...@gmail.comwrote:
Find the min and max in an array. Now do it in less than 2n comparisons.
(they were looking for the solution that finds both max and min in about
3/2 n comparisons).
--
Nitin
Greetings!
The strategy should be to process the elements in pairs - and compare the
larger element with current maximum, and smaller element with current
minimum.
loop runs upto n in steps of 2, and in each iteration, there are 3
comparisons:
- between (i)th and (i+1)th element
- between min(i,
Find the min and max in an array. Now do it in less than 2n comparisons.
(they were looking for the solution that finds both max and min in about
3/2 n comparisons).
--
Nitin Garg
Personality can open doors, but only Character can keep them open
--
You received this message because you are
Take numbers in pair of 2, compare with each other and then compare the
maximum among them with max (maximum element so far) and minimum among them
with min (minimum element so far) , In this way you will be able to find
max, min in 3 comparisons for each 2 integers. Hence 3n/2 comparisons
needed
Hi
The solution in the link is of complexity (n*2^n))
Does anyone know any better solution ?
Regards
Ankur
On Tue, Jul 26, 2011 at 11:10 PM, rajeev bharshetty rajeevr...@gmail.comwrote:
@Ankur The link does has a very good explanation. Nice solution :)
On Tue, Jul 26, 2011 at 10:47 PM,
Given an array of size n, print all the possible subset of array of
size k.
eg:-
input:
a[]={1,2,3,4}, k = 2
output:
1,2
1,3
1,4
2,3
2,4
3,4
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Hi
Dont u think the subsets will also be
{2,1}
{3,1}
{3,2}
{4,1}
{4,2}
{4,3}
On Tue, Jul 26, 2011 at 11:59 AM, sumit sumitispar...@gmail.com wrote:
Given an array of size n, print all the possible subset of array of
size k.
eg:-
input:
a[]={1,2,3,4}, k = 2
output:
1,2
1,3
1,4
2,3
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..
#include stdio.h
#include stdlib.h
void print_comb(int *a, int len)
{
int tlen = len;
int i, j, k;
for (i=0;i5;i++) {
for (j=i+1; j4;j++) {
anyway, the code i posted is buggy.. doesn't work for k=3.. don't use it :)
On Tue, Jul 26, 2011 at 1:02 PM, Vishal Thanki vishaltha...@gmail.com wrote:
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..
#include stdio.h
#include stdlib.h
void
#include bitset
#include iostream
#include math.h
#include vector
int main() {
using namespace std;
int arr[] = {1,2,3,4};
int k = 2;
int n = sizeof(arr)/sizeof(int);
vectorint v(arr, arr+n);
int l = pow(2.0, n);
for (int i = 0; i l; ++i) {
bitset32 b(i);
if (b.count() != k)
continue;
for (int j
int main()
{
buildsubsets(0,0,);
}
void buildsubsets(int i,int j,String subset)
{
if(j==k)
{
coutsubset+ ;
return ;
}
for(;in;++i)
buildsubsets(i+1,j+1,subset+arr[i]);
}
assume that given arr[] is a character array i.e.
check this link:
*http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
On Tue, Jul 26, 2011 at 11:59 AM, sumit sumitispar...@gmail.com wrote:
Given an array of size n, print all the possible subset of array of
size k.
eg:-
input:
a[]={1,2,3,4}, k = 2
output:
1,2
1,3
1,4
2,3
Here is the working code..
#include stdio.h
#include stdlib.h
int a[] = {1,2,3,4,5};
#define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
void print_comb(int len)
{
int tlen = len;
int i, j, k;
int al = ARRLEN(a);
for (i = 0; i al; i++) {
for (j=i+len-1;
Check this
http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki vishaltha...@gmail.comwrote:
Here is the working code..
#include stdio.h
#include stdlib.h
int a[] = {1,2,3,4,5};
#define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
@Ankur Garg: Nice explanation at the link given by u...
On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg ankurga...@gmail.com wrote:
Check this
http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki vishaltha...@gmail.comwrote:
@Ankur The link does has a very good explanation. Nice solution :)
On Tue, Jul 26, 2011 at 10:47 PM, Kunal Patil kp101...@gmail.com wrote:
@Ankur Garg: Nice explanation at the link given by u...
On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg ankurga...@gmail.com wrote:
Check this
for 12 answer will be 36? is it ur question?
--
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
Hi Geeks, One of The My Friend had This Question in His Technical
Round of Facebook, I m going to share with you.lest see how geek
approach this...Plz don't make this post spam..by discussing whats ur
friend name, wich colge, etc etc..just share your approach, think
solve the question, even
I am not sure if I can explain the general approach as efficiently as
by explaining with an example:
for the example you have give , say to find for A= 1,000,000,000 -
2,000,000,000
first two billion is not heavy.
So finding from 1,000,000,000 - 1,999,999,999
It is:( 1 + sigma (x) ) 70 , where
26 matches
Mail list logo