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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:50:29+00:00 2026-06-18T17:50:29+00:00

I created this method in java that indicates whether an integer array is sorted

  • 0

I created this method in java that indicates whether an integer array is sorted or not. What is its complexity? I think if good is O(1) in the worst case is O(n) in the average case?

static boolean order(int[] a){
  for(int i=0;i<a.length-1;i++){
    if(a[i]>a[i+1]) return false;
  }
 return true;
}
  • 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-18T17:50:30+00:00Added an answer on June 18, 2026 at 5:50 pm

    You didn’t tell anything about your input. So suppose it’s totally random. So for any 2 neighbour pairs we have 50% chance that they are ordered. It means that we have probability 1 of making 1 step, 0.5 for 2 steps, 0.25 for 3 steps and generally 2^(-k) for k steps. Let’s calculate expected number of steps:

    enter image description here

    I don’t know how to calculate sum of this series so I used wolfram alpha and got answer: 2, so it’s a constant.

    So as I understand average case for random input is O(1).

    I’m not sure it is correct way to calculate average complexity but seems fine to me.

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

Sidebar

Related Questions

I created a file called Hello.java that looks like this: public class Hello {
I'v created a Contentprovide and implements it's update() method like this: @Override public int
Can a custom event be created for any object method? To do this do
Is there a way to override a Java method that the only thing that
I have successfully created an object loader in java that loads in vertices, indices,
I need some advice on this java method. The intent of this method is
Good day, I'm a beginner learning Jave EE. I created a servlet (controller) VersionOverview.java
In Java, is there a premade method that I can use to take some
I have a Java method something like this public boolean ReadBool(String ValueName, Boolean Value)
I have created JAVA GUI that will receive text file(.txt) from other client and

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.