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

  • Home
  • SEARCH
  • 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 6058025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:33:11+00:00 2026-05-23T08:33:11+00:00

What is the big O value for the following algorithm? Why is it that

  • 0

What is the big O value for the following algorithm? Why is it that value?

algorithm A (val array <ptr to int>)
     1 n = 0
     2 loop ( n < array size ) 
    1 min = n;
    2 m = n;
    3 loop ( m < array size)
      1 if (array[m] < array[min])
            1  min = m;
    4 swap(array[min],array[n]);
     3 n = n + 1

I answered O(n^2) am I correct? As to how I arrived to this conclusion, the inner loops executes the n times where n = the array size and the outer loop executes n times where n is the array size n*n = n^2

  • 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-05-23T08:33:11+00:00Added an answer on May 23, 2026 at 8:33 am

    Yes! you are correct!

    This is selection sort algorithm.
    Its Θ(n^2) to be more precise.

    Edit : Why is it that value?

    You take the first element. Compare it with all the other elements to find minimum in the array and place it in the first place. Iterations : n.
    You take the second element. Compare it with rest of the array and find minimum in that part (second minimum in whole array) and place it in the second place. Iterations : n-1.
    Continuing in this way for last element, Iterations : 1.

    Total = n+n-1+ … +1 = n(n+1)/2. That is O(n^2).

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

Sidebar

Related Questions

There is big array of entries having the following type: typedef struct { int
I am getting a 'ArgumentError: array size too big' message with the following code:
So I've got a big text file which looks like the following: <option value
I have the following line of code: sqlcommand.Parameters.Add(@LinkID, SqlDbType.Int, 4).Value = linkID; But, I'm
I've got following XML structure: <artists> <artist> <name></name> <image size=small></image> <image size=big></image> </artist> </artists>
In C/C++, if a multi-byte wide character (wchar_t) value is transmitted from a big-endian
I need to create a big array in my code, I have the values
Big problem. I'm not sure what it was that I did, but it seems
Why does the following simplified code not sets the font-size of the TextBlock to
Imagine someone coding the following: string s = SomeString; s.ToUpper(); We all know that

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.