Re: [algogeeks] Re: Find the later version

2011-10-12 Thread mohit verma
WE CAN USE RADIX SORT TO FIND THE MAX VERSION :TRAVERSING FROM LEFT TO RIGHT
(RADIX WILL BE NUMBERS BETWEEN THE POINTS).
It will reduce the search space too.


On Tue, Oct 11, 2011 at 1:58 AM, sumit kumar pathak
sumitkp1...@gmail.comwrote:

 *
 *regards
 - Sumit Kumar Pathak
 (Sumit/ Pathak/ SKP ...)
 *Smile is only good contagious thing.*
 *Spread it*!



 On Tue, Oct 11, 2011 at 11:22 AM, DIPANKAR DUTTA 
 dutta.dipanka...@gmail.com wrote:

 what's happen if the versions are not in same length..

 For example

 v1: 1.1.1.133.2
 v2: 1.2
 v3: 1.2.3.4..333
 v4: 1.2.3.4.5554.222
 v5: 1.3.2.2.2.2.2.2.2.2.2.2.2.2

 It implies we must be scan from left side one by one ...

 In general the we make a some sort of lexical comparison where each
 character is a number and separated by number ..

  the problem definition is as :

 let V1,V2,V3 ...Vn be the n version

 let S={1,2,3...n} ,index=0

 Latest[S,index]= return Vi if { Max(ALL Vi[k] where i belongs to S )}
 is a singleton, else
  =  return Latest[ set of all index belongs to  { Max(ALL
 Vi[k] where i belongs to S )}, index+1 ]





 On 10/11/11, Dave dave_and_da...@juno.com wrote:
  @Karen: It is more complicated than scanning character by character.
  E.g., 1.10.3 is older than 1.9.7. I think


 snip

 you need to parse the
  numbers between the dots and compare them

 /snip

 simple, easier and correct way.
 points:
   -  compare left to right (ofcourse) each version being vector of numbers
   - for diffrent size, assume extra ones to be zero while comapring (no
 need to store trailing zeros)



  one by one. Thus, in the
  above example, 1 compares equal to 1, so you keep scanning. Then 10
  compares greater than 9 so the first string is number of the newer
  version. I did this many years ago in a csh install script for a unix
  product.
 
  Dave
 
  On Oct 10, 9:52 pm, bagaria.ka...@gmail.com
  bagaria.ka...@gmail.com wrote:
  Given two strings describing the version of a particular software need
 to
  find the later version.
 
  For eg.
  1st string = 1.2.4.5
  2nd string=1.2.3.5
 
  1st string is the later one.
 
  Can be done using traversing the string and comparing each character
 one
  after the another. Looking for a better solution with lesser
 complexity.
 
  --
  Thanks and Regards
 
  *Karan Bagaria*
  *MCA Final Year*
  Training and Placement Representative
  *NIT Durgapur*
 
  --
  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.
 
 


 --
 Thanks and Regards,
 --
 **DIPANKAR DUTTA
 Software Development Engineer
 Xen Server - OpenStack Development Team (DataCenter and Cloud)

 Citrix RD India Pvt Ltd
 69/3, Millers Road, Bangalore – 560052
 Phone: +91 8147830733
 Office: Extn: 16429
 Email: dipankar.du...@citrix.com

 --
 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.


  --
 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.




-- 

*MOHIT VERMA*

-- 
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] Re: Find the later version

2011-10-12 Thread Gene
As others have said, you have not completely specified the problem.
If you always have exactly 4 base 10 numbers separated by dots, and
you are working in C or C++ then you can use sscanf to get the numbers
and compare them:

// Return:
//  positive if version s1 is an earlier version than s2,
//  negative if s2 is earlier than s1
//  zero if they're the same version
#define VERSION_CMP_ERROR INT_MAX
int version_cmp(char *s1, char *s2)
{
  int i, v1[4], v2[4];
  if (sscanf(s1, %u.%u.%u.%u, v1+0, v1+1, v1+2, v1+3) != 4 ||
  sscanf(s2, %u.%u.%u.%u, v2+0, v2+1, v2+2, v2+3) != 4)
   return VERSION_CMP_ERROR;
  for (i = 0; i  4; i++)
if (v1[i] != v2[i])
  return v2[i] - v1[i];
  return 0;
}

On Oct 11, 4:52 am, bagaria.ka...@gmail.com
bagaria.ka...@gmail.com wrote:
 Given two strings describing the version of a particular software need to
 find the later version.

 For eg.
 1st string = 1.2.4.5
 2nd string=1.2.3.5

 1st string is the later one.

 Can be done using traversing the string and comparing each character one
 after the another. Looking for a better solution with lesser complexity.

 --
 Thanks and Regards

 *Karan Bagaria*
 *MCA Final Year*
 Training and Placement Representative
 *NIT Durgapur*

-- 
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] Re: Find the later version

2011-10-12 Thread Amol Sharma
scan the numbers as string
if both strings dont have equal numbers of dots then add trailing 0's with
dots to the string with less number of dots

now divide both the string into 2 equal halves compare the left half .if
unequal then divide recursively and again compare left of the divided
string.if equal the compare the right half and divide and
compare it recursivelythis will reduce the complexity to logn.


--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 http://gplus.to/amolsharma99
http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99





On Thu, Oct 13, 2011 at 2:21 AM, sravanreddy001 sravanreddy...@gmail.comwrote:

 it is expected that the version is given as string, in that case, atoi()
 has be used to convert string to int

-- 
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] Re: Find the later version

2011-10-11 Thread DIPANKAR DUTTA
what's happen if the versions are not in same length..

For example

v1: 1.1.1.133.2
v2: 1.2
v3: 1.2.3.4..333
v4: 1.2.3.4.5554.222
v5: 1.3.2.2.2.2.2.2.2.2.2.2.2.2

It implies we must be scan from left side one by one ...

In general the we make a some sort of lexical comparison where each
character is a number and separated by number ..

 the problem definition is as :

let V1,V2,V3 ...Vn be the n version

let S={1,2,3...n} ,index=0

Latest[S,index]= return Vi if { Max(ALL Vi[k] where i belongs to S )}
is a singleton, else
  =  return Latest[ set of all index belongs to  { Max(ALL
Vi[k] where i belongs to S )}, index+1 ]





On 10/11/11, Dave dave_and_da...@juno.com wrote:
 @Karen: It is more complicated than scanning character by character.
 E.g., 1.10.3 is older than 1.9.7. I think you need to parse the
 numbers between the dots and compare them one by one. Thus, in the
 above example, 1 compares equal to 1, so you keep scanning. Then 10
 compares greater than 9 so the first string is number of the newer
 version. I did this many years ago in a csh install script for a unix
 product.

 Dave

 On Oct 10, 9:52 pm, bagaria.ka...@gmail.com
 bagaria.ka...@gmail.com wrote:
 Given two strings describing the version of a particular software need to
 find the later version.

 For eg.
 1st string = 1.2.4.5
 2nd string=1.2.3.5

 1st string is the later one.

 Can be done using traversing the string and comparing each character one
 after the another. Looking for a better solution with lesser complexity.

 --
 Thanks and Regards

 *Karan Bagaria*
 *MCA Final Year*
 Training and Placement Representative
 *NIT Durgapur*

 --
 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.




-- 
Thanks and Regards,
--
**DIPANKAR DUTTA
Software Development Engineer
Xen Server - OpenStack Development Team (DataCenter and Cloud)

Citrix RD India Pvt Ltd
69/3, Millers Road, Bangalore – 560052
Phone: +91 8147830733
Office: Extn: 16429
Email: dipankar.du...@citrix.com

-- 
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] Re: Find the later version

2011-10-11 Thread sumit kumar pathak
*
*regards
- Sumit Kumar Pathak
(Sumit/ Pathak/ SKP ...)
*Smile is only good contagious thing.*
*Spread it*!



On Tue, Oct 11, 2011 at 11:22 AM, DIPANKAR DUTTA dutta.dipanka...@gmail.com
 wrote:

 what's happen if the versions are not in same length..

 For example

 v1: 1.1.1.133.2
 v2: 1.2
 v3: 1.2.3.4..333
 v4: 1.2.3.4.5554.222
 v5: 1.3.2.2.2.2.2.2.2.2.2.2.2.2

 It implies we must be scan from left side one by one ...

 In general the we make a some sort of lexical comparison where each
 character is a number and separated by number ..

  the problem definition is as :

 let V1,V2,V3 ...Vn be the n version

 let S={1,2,3...n} ,index=0

 Latest[S,index]= return Vi if { Max(ALL Vi[k] where i belongs to S )}
 is a singleton, else
  =  return Latest[ set of all index belongs to  { Max(ALL
 Vi[k] where i belongs to S )}, index+1 ]





 On 10/11/11, Dave dave_and_da...@juno.com wrote:
  @Karen: It is more complicated than scanning character by character.
  E.g., 1.10.3 is older than 1.9.7. I think


snip

 you need to parse the
  numbers between the dots and compare them

/snip

simple, easier and correct way.
points:
  -  compare left to right (ofcourse) each version being vector of numbers
  - for diffrent size, assume extra ones to be zero while comapring (no need
to store trailing zeros)



 one by one. Thus, in the
  above example, 1 compares equal to 1, so you keep scanning. Then 10
  compares greater than 9 so the first string is number of the newer
  version. I did this many years ago in a csh install script for a unix
  product.
 
  Dave
 
  On Oct 10, 9:52 pm, bagaria.ka...@gmail.com
  bagaria.ka...@gmail.com wrote:
  Given two strings describing the version of a particular software need
 to
  find the later version.
 
  For eg.
  1st string = 1.2.4.5
  2nd string=1.2.3.5
 
  1st string is the later one.
 
  Can be done using traversing the string and comparing each character one
  after the another. Looking for a better solution with lesser complexity.
 
  --
  Thanks and Regards
 
  *Karan Bagaria*
  *MCA Final Year*
  Training and Placement Representative
  *NIT Durgapur*
 
  --
  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.
 
 


 --
 Thanks and Regards,
 --
 **DIPANKAR DUTTA
 Software Development Engineer
 Xen Server - OpenStack Development Team (DataCenter and Cloud)

 Citrix RD India Pvt Ltd
 69/3, Millers Road, Bangalore – 560052
 Phone: +91 8147830733
 Office: Extn: 16429
 Email: dipankar.du...@citrix.com

 --
 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.



-- 
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] Re: Find the later version

2011-10-10 Thread Dave
@Karen: It is more complicated than scanning character by character.
E.g., 1.10.3 is older than 1.9.7. I think you need to parse the
numbers between the dots and compare them one by one. Thus, in the
above example, 1 compares equal to 1, so you keep scanning. Then 10
compares greater than 9 so the first string is number of the newer
version. I did this many years ago in a csh install script for a unix
product.

Dave

On Oct 10, 9:52 pm, bagaria.ka...@gmail.com
bagaria.ka...@gmail.com wrote:
 Given two strings describing the version of a particular software need to
 find the later version.

 For eg.
 1st string = 1.2.4.5
 2nd string=1.2.3.5

 1st string is the later one.

 Can be done using traversing the string and comparing each character one
 after the another. Looking for a better solution with lesser complexity.

 --
 Thanks and Regards

 *Karan Bagaria*
 *MCA Final Year*
 Training and Placement Representative
 *NIT Durgapur*

-- 
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.