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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:34:50+00:00 2026-05-30T19:34:50+00:00

I am trying to understand the time complexity for these two functions. I have

  • 0

I am trying to understand the time complexity for these two functions. I have tried experimenting with both and here is what I have come up with

List.foldBack (@) [[1];[2];[3];[4]] [] => [1] @ List.foldBack (@) [[2];[3];[4]] []
=> [1] @ ([2] @ List.foldBack (@) [[3];[4]] [])
=> [1] @ ([2] @ ([3] @ List.foldBack (@) [4] []))
=> [1] @ ([2]@([3] @ ([4] @ List.foldBack[])))
=> [1]@([2]@([3]@([4]@([])))
=> [1; 2; 3; 4]


List.fold (@) [] [[1];[2];[3];[4]]
=> List.fold (@) (([],[1])@ [2]) [[3];[4]]
=> List.fold (@)  ((([]@[1])@[2])@[3]) [[4]]
=> List.fold (@)  (((([]@[1])@[2])@[3])@[4]) []
=> (((([]@[1])@[2])@[3])@[4])

Now it seems to me that they are both linear since it takes the same amount of calculations to achieve the same result. Am i correct or is there something that I am missing?

  • 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-30T19:34:51+00:00Added an answer on May 30, 2026 at 7:34 pm

    If each inner operation is Θ(1), List.fold and List.foldBack is O(n) where n is the length of the list.

    However, to estimate asymptotic time complexity, you need to rely on Θ(1) operations. In your example, things are a little more subtle.

    Suppose you need to concatenate n lists where each list has m elements. Since @ is O(n) of the length of the left operand, we have complexity of foldBack:

      m + ... + m // n occurences of m
    = O(m*n)
    

    and that of fold:

      0 + m + 2*m + ... + (n-1)*m // each time length of left operand increases by m
    = m*n*(n-1)/2
    = O(m*n^2)
    

    Therefore, with your naive way of using @, foldBack is linear while foldis quadratic to the size of input lists.

    It is worth to note that @ is associative (a @ (b @ c) = (a @ b) @ c); therefore, results are the same for fold and foldBack in this case.

    In practice, if the inner operator is non-associative, we need to choose the right order by either using fold or foldBack. And List.foldBack in F# is made tail-recursive by transforming lists to arrays; there are some overheads by this operation as well.

    • 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 how these two are connected. Every time you make a
I'm trying to understand compile versus run-time computation in java. I have the following
I have heard this time and again, and I am trying to understand and
I'm trying to understand the django admin better and at the same time, I'm
I've been having a hard time trying to understand PyPy's translation. It looks like
Just trying to understand that - I have never used it before. How is
I'm trying to understand when is the appropriate time to use Doctine_Table classes and
i'm having hard time trying to understand how interrupts work. the code below initialize
I was trying to understand why numberOfSectionsInTableView is being called multiple times each time
I'm trying to understand how I can use the local server time to quickly

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.