All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Algorithm requested (Posted on 2013-12-18) Difficulty: 3 of 5
Given an array with random odd and even integers.
Please suggest the most efficient algorithm to put all even numbers on one side and all odd numbers on the other side in this array.

Source: Got an Email from an unknown person.

See The Solution Submitted by Ady TZIDON    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
an algorithm | Comment 2 of 3 |
Steps:
(1) convert from base 10 to base 2
(2) reverse the digits
(3) sort from smallest to largest
(4) reverse the digits
(5) convert from base 2 to base 10

Since the even numbers all end in zero (in base 2), putting the reversed binary representation in smallest to largest order puts all the even numbers at the beginning and all the odd numbers at the end

  Posted by Larry on 2013-12-18 15:38:33
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information