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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:27:41+00:00 2026-06-09T08:27:41+00:00

Here is an algorithm I am trying to analyse (see below). I do not

  • 0

Here is an algorithm I am trying to analyse (see below). I do not understand why this has a O(n) time complexity when the merge sorts has O(n logn), they both seems to be doing the same thing.

then both have the same j time complexity, if you left j be the row then 2^j X c(n/2^j) = cn and they both have a running time of log n, where n is the number of elements.

Algorithm: BinarySum(A, i, n)
Input: An array A and integers i and n.
Output: The sum of the n integers in A starting at index i.
if n = 1 then
return A[i]
return BinarySum(A, i, [n/2] ) + BinarySum(A, i + [n/2], [n/2])

thanks,
daniel

  • 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-09T08:27:43+00:00Added an answer on June 9, 2026 at 8:27 am

    You are processing for constant time each member of an array. No matter how are you doing this, the resulting complexity will be O(n). By the way, if you use a pen and paper method for a simple example, you’ll see that in fact you are calling array’s elements exactly in order they appear in the array, which means that this algorithm is equivalent to simple iterative summation.

    Formal proof for O(n) complexity follows directly from the Master theorem. Recurrence relation for your algorithm is

    T(n) = 2 T(n/2)
    

    which is covered by case 1 of the theorem. From this complexity is calculated as

    O(n ^ log_2_(2)) = O(n)
    

    As for merge sort, its recurrence relation is

    T(n) = 2 T(n/2) + O(n)
    

    which is a totally different story – case 2 of the Master theorem.

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

Sidebar

Related Questions

I'm trying to understand the unification algorithm described in SICP here In particular, in
I'm trying to implement this algorithm description from a previous question I had here
So I'm trying to understand the Tomasulo algorithm for out-of-order instruction execution. Here's what
I'm trying to understand the algorithm described here , but the explanation really isn't
I am trying to understand the algorithm from the famous 'diff' paper here ,
I'm trying to run this CannyEdge-detection algorithm on ImageJ. The code is here on
Stuck trying to figure out the best algorithm here. I have this simple function
Okay so here's my algorithm for finding a Cut in a graph (I'm not
I am trying to find a better algorithm here. In my problem, a user
I am trying to implement my own Thinning Algorithm in Matlab to understand the

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.