@ ^
Why do you try hard not to understand the question or what one meant by the
question and instead try hard to find out flaws.
I mean ain't that obvious that you need to divide into minimum number of
groups?
--
Rohit Saraf
Third Year Undergraduate,
@snehal jain
As many group as possible?
All the inputed n numbers can be divided into n groups...
On Sun, Jan 30, 2011 at 2:13 PM, snehal jain wrote:
> @nishanth
> divide into groups ( not necessarily 2) in as many group as possible.. such
> that elements in each group is consecutive
>
> another
I don't see why you need O(n^2) time for rearranging.
It can be done in O(n log n) if you maintain the index along with every
element.
Then reordering would mean sort as per the indices.
--
Rohit Saraf
Third Year Undergraduate,
Dept. of Computer Scie
list all groups...with their elements
On Sun, Jan 30, 2011 at 12:32 PM, nishaanth wrote:
> so whats the required outputlist all possiblities or anything else? if
> its just this one output...then it sounds trivial
>
>
> On Sun, Jan 30, 2011 at 11:43 AM, snehal jain wrote:
>
>> @nishanth
so whats the required outputlist all possiblities or anything else? if
its just this one output...then it sounds trivial
On Sun, Jan 30, 2011 at 11:43 AM, snehal jain wrote:
> @nishanth
> divide into groups ( not necessarily 2) in as many group as possible.. such
> that elements in each
@nishanth
divide into groups ( not necessarily 2) in as many group as possible.. such
that elements in each group is consecutive
another example to clearify
A= { 9,7, 13, 11,6,12,8,10,3, 4, 2, 16,14,17,13,15)
ans
<9,7,13,11,6,12,8,10>
<3,4,2>
<16,14,17,13,15>
On Sun, Jan 30, 2011 at 11:32 AM, ni
@snehal..i guess you are missing something in the question...divide it into
2 groups such that (there should be some other condition or criterion).
On Sun, Jan 30, 2011 at 11:29 AM, snehal jain wrote:
> my approach
>
> sort in nlogn and then while traversing the array put the elements in a
>
my approach
sort in nlogn and then while traversing the array put the elements in a
group till they are consecutive . when a[i+1]!=a[i]+1 then put a[i+1] in
different group.. now we need to rearrange elements in the group so that
they are according to the given array.. but that will make it O(n^2)
Divide a list of numbers into groups of consecutive numbers but their
original order should be preserved.
Example:
<8,2,4,7,1,0,3,6>
Two groups:
<2,4,1,0,3> <8,7,6>
Better than O(n^2) is expected.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" grou