|
|
|
|
![]() ![]() |
Nov 13 2007, 11:02 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 305 Joined: 1-October 07 From: India Member No.: 50,968 |
Given an array of elements with many numbers occurring even number of times and two numbers occurring odd number of times. Find out the two numbers that occur odd number of times.
example: Elements in array -- 14433446 The expected result is 1 and 6 One solution 1. Find max of the array 2. Hash Function : element/max value 3. Repeat to all elements... 4. Find frequency... yo will get the 2 elements with odd frequency. but this is not the optimal.... Do find more solutions to this and post it. Look for time and space complexity. Another Solution one more solution 1. Scan through the array 2. Insert the element into a BST if its already not there. If its already avl, delete it from BST. 3. Repeat for all the elements 4. Now, BST will have only the elements with odd occurrence. Time complexity : O(n*log n) Courtesy: Varun. (friend) |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th September 2008 - 06:17 AM |