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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:49:09+00:00 2026-05-31T05:49:09+00:00

I am a beginner of C++ and learning Algorithm Analysis: I am writing a

  • 0

I am a beginner of C++ and learning Algorithm Analysis:
I am writing a method which return a row number of a 2d array has most 1’s , each rows from the input array are all sorted and hits 0 when all 1’s are sort to the front like

1,1,1,0,0
1,1,0,0,0
1,1,1,1,0
1,0,0,0,0
1,1,1,1,1

the method will return 5 from this array and here is the code:

int countone(int a[][]){
int count = 0, column = 0, row = 0, current = 0, max;
bool end = true;
do{
     if(a[row][column]==1)
     {
        current++;
        column++;
     }
     if(a[row][column]==0)
     {
        column=0;
        if(count<current)
        {
           count = current;
           max = row;
           current = 0;
        }
     row++;        
     if(a[row][column] != 1 && a[row][column] != 0)
     {
        end = false;
        return max;
     }
 }
while(end)

the code hasn’t tested yet so it may contains bug and error, but this is not the main point anyway.
I would like to find out the cost of this method, but I have no idea how to calculate it.

The cost I want is Running time T(n) and Big-Oh notation. If possible, the method should running in O(n) time ( not O(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-31T05:49:10+00:00Added an answer on May 31, 2026 at 5:49 am

    This is how you can evaluate the runtime complexity of your code.For your code, the worst case complexity would be the size of your matrix (i.e. if your code compiles) after you make the end false when row and column equal the size of your matrix.

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

Sidebar

Related Questions

I'm a beginner learning some assembly, when preserving the ESP register before a function
I'm a beginner (self-learning) programmer learning C++, and recently I decided to implement a
This is a beginner's rails learning confusion. When I learn rails, from time to
I'm a beginner programmer and I'm learning my first language, C. I'm learning mostly
I am learning Python, following a book (Python Programming for the Absolute Beginner, 3rd
I'm a beginner to C programming. I'm trying to learning how to code a
I am a beginner in Haskell so please bear with me. (Just started learning
I am new to Scala, just started learning, so this is basic beginner question.
Beginner help needed :) I am doign an example form a php book which
What's the ideal Python version for a beginner to start learning Python? I need

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.