suhas y7
suhas y7

Reputation: 3

It's About data Structure

There are two unsorted lists containing Integers, need to find the common largest integer in the list ?

I have an idea about this question, i taught first we need to find the largest element in the first list and then we need to apply linear search method for the second list using largest element of the first list. Is this logic correct....? If it's not can one help me with the logic for this question.

can any one help me out for this question please...

Upvotes: 0

Views: 104

Answers (1)

Chris Trahey
Chris Trahey

Reputation: 18290

The problem with you first thought is that if the largest element in the first item does not occur in the second, you would never try another.

The most efficient way I can think of in a short time is this:

  1. Order both arrays in descending order
  2. grab the first element in the first array
  3. compare to the first element in the second array
  4. if it is the same, you are done
  5. If the first item is larger than the second, pop it off of array 1 and repeat from step 2
  6. if the first item is smaller than the second, pop the second off of array 2 and repeat from step 2

Upvotes: 1

Related Questions