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 9193623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:12:41+00:00 2026-06-17T21:12:41+00:00

I have this question: Given two sorted lists (stored in arrays) of size n,

  • 0

I have this question:

Given two sorted lists (stored in arrays) of size n, find an O(log n)
algorithm that computes the nth largest element in the union of the
two lists.

I can see there is probably a trick here as it requires the nth largest element and the arrays are also of size n, but I can’t figure out what it is. I was thinking that I could adapt counting sort, would that work?

  • 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-17T21:12:43+00:00Added an answer on June 17, 2026 at 9:12 pm

    Compare A[n/2] and B[n/2]. If equal, any of them is our result. Other stopping condition for this algorithm is when both arrays are of size 1 (either initially or after several recursion steps). In this case we just choose the largest of A[n/2] and B[n/2].

    If A[n/2] < B[n/2], repeat this procedure recursively for second half of A[] and first half of B[].

    If A[n/2] > B[n/2], repeat this procedure recursively for second half of B[] and first half of A[].

    Since on each step the problem size is (in worst case) halved, we’ll get O(log n) algorithm.


    Always dividing array size by two to get the index works properly only if n is a power of two. More correct way of choosing indexes (for arbitrary n) would be using the same strategy for one array but choosing complementing index: j=n-i for other one.

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

Sidebar

Related Questions

This is a homework question, binary search has already been introduced: Given two arrays,
I was asked this question: You are given two lists of integers, each of
Ok, so this is the question. Let's say I have a given value: 2000;
hello i have this question i was trying to find a way to call
I came across this post , which reports the following interview question: Given two
I have this code where I am using two javascript functions that do some
This question was asked in interview and deals with recursion/backtracking. Suppose we have two
I have a language-agnostic question about an algorithm. This comes from a (probably simple)
This question is a continuation of a previous thread to compare two lists with
I have this question, just in theory. I do some query results and there

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.