0

I wrote a code and I want to find out what is the time complexity of this program. Can anyone tell me what is the time complexity of my code?

import java.io.*;
class revenge
{
    public static void main(String aargs[])throws IOException
    {
        BufferedReader b=new BufferedReader(
            new FileReader("C://Users/Shuvro/Downloads/B-large-practice.in"));
        //System.out.println("enter t");
        int t=Integer.parseInt(b.readLine());
        for(int i=1;i<=t;i++) {
            String s1=b.readLine();
            StringBuilder s=new StringBuilder(s1);
            int c=0;
            while(s.indexOf("-")>=0) {
                for(int j=0;j<=s.lastIndexOf("-");j++) {
                    if(s.charAt(j)=='-')
                    s.setCharAt(j,'+');
                    else
                    s.setCharAt(j,'-');
                }
                c++;
            }
            System.out.println("Case #"+i+": "+c);
        }
    }
}

I tried to find out the complexity myself and I think its O(n^2).Am I right?

Pablo Lozano
  • 10,122
  • 2
  • 38
  • 59
Shuvro
  • 23
  • 3
  • 1
    Possible duplicate of [How to find time complexity of an algorithm](http://stackoverflow.com/questions/11032015/how-to-find-time-complexity-of-an-algorithm) – Alex Romanov Apr 04 '17 at 14:08
  • I would start by understanding what this code is actually supposed to do. – GhostCat Apr 04 '17 at 14:09
  • Another thing to take into consideration: `n` is a measure of the length of a certain input. You should first have a clear idea about what your `n` is, before starting to determine any time-complexity. –  Apr 04 '17 at 14:11
  • https://code.google.com/codejam/contest/6254486/dashboard#s=p1&a=1 this is the link to the problem . my answer was accepted and it said its correct.just want to know the time complexity – Shuvro Apr 04 '17 at 14:32

0 Answers0