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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:04:05+00:00 2026-05-19T11:04:05+00:00

How do you compute the number of operations each line of code would take.

  • 0

How do you compute the number of operations each line of code would take.

Example.

Algorithm find2D (A,x)
    arrLength = A.length
    for j <- 1 to arrLength – 1 do
         for k <- 1 to arrLength – 1 do
                if A[j][k] = x then
                  return true
          increment k
    increment j
return false

I came up with this pseudo code. So I’m not really sure how to count the number of operations each line of code takes.

So like the first loop would be 1+n operations since you have to set the j, compare j to arrLength – 1, and it will loop n-1 times. So that gives you n-1 + 1 + 1 which is n+1 operations.

So for the second loop would it just be the same thing even though its nested.

I’m a little confused on the A[j][k] = x comparison, how many operations would that be.

Thanks.

  • 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-19T11:04:05+00:00Added an answer on May 19, 2026 at 11:04 am

    Big-Oh is asymptotic, so you shouldn’t be concerned with the “1” in “1+n”.

    If all you’re looking for is the Big-Oh classification of that code, simply consider that you have two loops, one nested inside the other, and each loop does some constant number of operations per element. Then the inside loop is O(n), and the outside loop is executing the inside loop n times, so the outside loop is O(n^2). Then the whole function is O(c+n^2) where c is the constant number of operations from the code surrounding the outside loop. Since Big-Oh is asymptotic, the c disappears and your function is O(n^2).

    If you’re trying to calculate the exact number of operations the code takes, you’ll probably need to establish what abstract machine you’re using.

    Hope this helps.

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

Sidebar

Related Questions

I can't seem to find an algorithm to compute the number of arrays within
Is it possible to compute the number of different elements in an array in
I am trying to compute and count the number of rows inside a C#
This question asks how to compute the Cartesian product of a given number of
I have a class that spawns an arbitrary number of worker object that compute
For given floating point numbers x and a , I would like to compute
If a large number is subtracted from a smaller number then borrow is needed.
Write Script to read a positive integer number then it computes the following sequence:
I have a number of classes that represent various computer components, each of which
I would like to compute the absolute difference of two integers. Naively, this is

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.