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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:34:20+00:00 2026-06-02T04:34:20+00:00

I have a random ordered array of 30 elements with only 3 distinct keys

  • 0

I have a random ordered array of 30 elements with only 3 distinct keys (TRUE, FALSE and NULL) that I want to sort using insertion sort. What will be the time complexity? Will it be O(n2) assuming worst case or O(n) assuming best case since there are only 3 different keys?

  • 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-02T04:34:21+00:00Added an answer on June 2, 2026 at 4:34 am

    n refers to the size of the array, not the possible elements of the array. Thus, the complexity is the same:

    • Worst-case: O(n2)
    • Best-case: O(n)
    • Average-case: O(n2)

    Having 3 distinct elements will reduce the amount of elements you have to check during the “insertion” phase, but only by a constant factor. This will not change the asymptotic run-time.

    For example, in the average-case, instead of insert checking n elements, it will check n/3 elements. This is better, but not asymptotically.

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

Sidebar

Related Questions

I have a pseudo random number generator (PRNG) class that I want to unit
I have an array that is built using the explode() function, but seeing how
I got requirements- 1. Have random values in a List/Array and I need to
Possible Duplicate: True random number generator I have worked with random functions in python,ruby,
In a folder I have random module files. eg. user.rb that contains module User,
I have a large set of strings that I'm using for natural language processing
I have an array of objects of my custom class and i want to
I have random Product Links URL. I want the result Like > http://yourdomain.com/index.php?main_page=product_info&products_id=5 Product
What is the algorithm to have random reals using x++ in Dynamics AX?
I have random strings that are similar to this: 2d4hk8x37m or whatever. I need

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.