Re: [algogeeks] Divide the array into groups

2011-01-30 Thread 赵宇
@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 learner@gmail.com wrote:

 @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, nishaanth nishaant...@gmail.com wrote:

 @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 learner@gmail.comwrote:

 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) ..
 anyone with better ideas?


 On Fri, Jan 21, 2011 at 1:20 PM, snehal jain learner@gmail.comwrote:

 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 group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Southeast University
Nicholas.Zhaoyu

-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-30 Thread Rohit Saraf
@ ^
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,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-29 Thread snehal jain
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) ..
anyone with better ideas?

On Fri, Jan 21, 2011 at 1:20 PM, snehal jain learner@gmail.com wrote:

 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 group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-29 Thread nishaanth
@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 learner@gmail.com wrote:

 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) ..
 anyone with better ideas?


 On Fri, Jan 21, 2011 at 1:20 PM, snehal jain learner@gmail.comwrote:

 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 group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-29 Thread snehal jain
@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, nishaanth nishaant...@gmail.com wrote:

 @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 learner@gmail.comwrote:

 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) ..
 anyone with better ideas?


 On Fri, Jan 21, 2011 at 1:20 PM, snehal jain learner@gmail.comwrote:

 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 group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-29 Thread nishaanth
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 learner@gmail.com wrote:

 @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, nishaanth nishaant...@gmail.com wrote:

 @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 learner@gmail.comwrote:

 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) ..
 anyone with better ideas?


 On Fri, Jan 21, 2011 at 1:20 PM, snehal jain learner@gmail.comwrote:

 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 group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Divide the array into groups

2011-01-29 Thread Rohit Saraf
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 Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

-- 
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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Divide the array into groups

2011-01-20 Thread snehal jain
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 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, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.