Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7719261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:22:19+00:00 2026-06-01T03:22:19+00:00

You are given as input an unsorted array of n distinct numbers, where n

  • 0

You are given as input an unsorted array of n distinct numbers, where n is a power of 2. Give an algorithm that identifies the second-largest number in the array, and that uses at most n+log₂(n)−2 comparisons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:22:20+00:00Added an answer on June 1, 2026 at 3:22 am
    1. Start with comparing elements of the n element array in odd and even positions and determining largest element of each pair. This step requires n/2 comparisons. Now you’ve got only n/2 elements. Continue pairwise comparisons to get n/4, n/8, … elements. Stop when the largest element is found. This step requires a total of n/2 + n/4 + n/8 + … + 1 = n-1 comparisons.
    2. During previous step, the largest element was immediately compared with log₂(n) other elements. You can determine the largest of these elements in log₂(n)-1 comparisons. That would be the second-largest number in the array.

    Example: array of 8 numbers [10,9,5,4,11,100,120,110].

    Comparisons on level 1: [10,9] ->10 [5,4]-> 5, [11,100]->100 , [120,110]–>120.

    Comparisons on level 2: [10,5] ->10 [100,120]->120.

    Comparisons on level 3: [10,120]->120.

    Maximum is 120. It was immediately compared with: 10 (on level 3), 100 (on level 2), 110 (on level 1).

    Step 2 should find the maximum of 10, 100, and 110. Which is 110. That’s the second largest element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you are given an array of unsorted integers as A = {3,4,5,1,4,2} Input
You are given an Array of numbers and they are unsorted/random order. You are
Given a unsorted sequence of a[1,...,n] of integers, give an O(nlogn) runtime algorithm to
By which I mean this: Given the input set of numbers: 1,2,3,4,5 becomes 1-5.
Suppose that my Haskell function is given an input, which is supposed to be
I am attempting to compose a style sheet that, given an XML input (obviously)
Given following Ruby statements: (Read input and store each word in array removing spaces
HI, suppose i have given input numbers like this 1,2,3,4,5,6,7,8,9,0 i should form it
I'd like to find a library or command that given input like every third
question origin Given an unsorted array of size n containing objects with ids of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.