@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,
@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
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
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
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
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
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
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,
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,
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
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
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
@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
@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
@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,
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
@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
@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
@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
@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
@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
@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
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,)
@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
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
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
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
@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
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
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
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
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
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
@ 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
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
@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
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
@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
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
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),
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
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
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
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
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
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
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
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
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
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,
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
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
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
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
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
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??
--
@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
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..?
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
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
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
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
@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,
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
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
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
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
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
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
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
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
71 matches
Mail list logo