Neewbie question on time complexity

in the following code what would be the time complexity and would this work for a project with the following question:
i have to write a code that gets a variable of an array n x n with only 1 or 0 where i have to find the k row which all the cells are 0 and in the k column all the values are 1 besides for [k][k] which has to be 0 if non is found then -1 is returned. and i need to do it in O(n) time complexity! so heres my code that i wrote up but im not sure about the time complexity.
public static int isSink(int[][] mat)
int row=0,col=0;
boolean found=false;
while(row<mat.length && !found)
//check if its not the connecting spot
if(row != col)
if(mat[row][col]==0 && mat[col][row]==1)
col++;
else
//if the row is not 0 or if the column is not 1
col=0;
row++;
else
// Is the connecting spot and need to check if its 0 otherwise continue to next row
if(mat[row][col]==0)
col++;
else
col=0;
row++;
}//end of if row == col
//if the row is completed then there is a hole
if(col==mat.length)
return row;
}//end of while
return -1;
}// end of method

    public static int isSink(int[][] mat)
        int row=0,col=0;
        boolean found=false;
        while(row<mat.length && !found)
            //check if its not the connecting spot
            if(row != col)
                if(mat[row][col]==0 && mat[col][row]==1)
                    col++;
                else
                    //if the row is not 0 or if the column is not 1
                    col=0;
                    row++;
            else
            // Is the connecting spot and need to check if its 0 otherwise continue to next row
                if(mat[row][col]==0)
                    col++;
                else
                    col=0;
                    row++;
            }//end of if row == col
            //if the row is completed then there is a hole
            if(col==mat.length)
                return row;
        }//end of while
        return -1;
    }// end of method

Similar Messages

  • Hello, I have two questions on time capsule  I can only have it on my external hd files and free up my internal memory to my mac  I can use an external hard drive, in my case a lacie rugged as shared memory for my two computers

    Hello, I have two questions on time capsule  I can only have it on my external hd files and free up my internal memory to my mac  I can use an external hard drive, in my case a lacie rugged as shared memory for my two computers

    I have a mackbook pro and an iMac if I buy a time capsule 2tb airport, I can use it with time machine and what would be the best way to use it.
    There is no particular setup required for TM.. both computers will create their own backup sparsebundle which is like a virtual disk.. Pondini explains the whole thing if you read the reference I gave you.
    and how to use time capsule airport whit other external hd to use my old lacie airport with the new time capsule
    Up to you.. you can plug the external drive into the TC and enjoy really slow file transfers or you can plug it into your computer and use it as external drive.. which is faster than the TC.. and TM can include it in the backup.
    Again everything is explained in the reference.. you are not reading it.

  • How can I prevent deleted mail from ending up in "All Mail"     and "Archives"?  To my horror, I've emptied these boxes and lost all my mail from all my boxes  (and why do I need to enter this question three times?"

    How can I prevent deleted mail from ending up in "All Mail" and "Archives"? 
    To my horror, I emptied these boxes and lost all my mail from all my boxes .
    All mail also disappeared from my iPad, I suppose because they are "synched"
    (Also, no offense, but why do I need to enter this question multiple times?)
    Thanks for any thoughts.

    I'm having a similar but slightly different problem. My company just migrated to Gmail, and it's saving mail drafts every 30 seconds into my Trash folder.
    I unchecked the "Show in IMAP" preference in the Gmail settings, but my Drafts folder completely disappeared. I went back and checked it and the folder reappeared (with my drafts still in there).
    I like the idea if starting an email on my laptop and having the option of finishing it on my iPhone or iPad, so only saving Drafts locally would not be ideal.

  • I'm using a new computer and to open one website I have to answer the security questions each time saying that the site doesn't recognize this computer.

    Each time I try to open my "ubt" website, I get a message that says the site does not recognize this computer so I have to answer the security questions each time. I get the message "You are attempting to log in to your account from a computer that we do not recognize..." All other websites work just fine. The Mac store person could not figure it out. This site works on Safari, but I prefer Firefox.

    The ipod is not a backup device. The music sync is one way - computer to ipod.  The only exception is itunes purchases:  Without syncing:File>transfer Purchases
    Copy everything from your backup copy of your  old computer to your new one.

  • Why do I have to answer security questions every time I download an app

    Not sure why I have to answer my security questions every time I try to download an app? How do I change that setting?

    Contact iTunes
    Apple - Support - iTunes - Contact Us
    To reset the them:
    From a Kappy  post
    The Three Best Alternatives for Security Questions and Rescue Mail
       1. Use Apple's Express Lane.
              Go to https://expresslane.apple.com ; click 'See all products and services' at the
              bottom of the page. In the next page click 'More Products and Services, then
              'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
              ID security questions' and click 'Continue'. Please be patient waiting for the return
              phone call. It will come in time depending on how heavily the servers are being hit.
         2.  Call Apple Support in your country: Customer Service: Contacting Apple for support or
              Apple ID- Contacting Apple for help with Apple ID account security. Ask to speak to
              Account Security.
         3.  Rescue email address and how to reset Apple ID security questions.
    How to Manage your Apple ID: Manage My Apple ID

  • HT5622 Will I have to awnser my security questions every time I get an app? And if so how do I get rid of them?

    Will I have to awnser my security questions every time I get an app? And if so how do I get rid of them?

    If you forgot them:
    From a Kappy  post
    The Three Best Alternatives for Security Questions and Rescue Mail
       1. Use Apple's Express Lane.
    Go to https://expresslane.apple.com ; click 'See all products and services' at the
    bottom of the page. In the next page click 'More Products and Services, then
    'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
    ID security questions' and click 'Continue'. Please be patient waiting for the return
    phone call. It will come in time depending on how heavily the servers are being hit.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • Sorting singly linked list with minimum time complexity

    Hi ...
    anyone could tell me how can i sort singly linked list with minimum time complexity .... ????
    Regards...

    By MergeSort or QuickSort O(n log n). But then you
    have to first extract the objects in the list,sort
    them, then rebuild the list. But it will still bealot
    faster than by keeping the list linked.Technically, I believe insertion sort is marginally
    faster for small n ( <20 or so).Woohoo! So for 20 out of the possible 2147483648 array
    sizes Insetion is faster!
    Unfortunately, checking for that case probably wastes
    all the time you get from using the faster sort...
    That would depend on the actual distribution off array sizes. So it's an engineering decision.
    Sylvia.

  • I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this

    I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this is extremely irritating, I cannot re-initialize the same file or initialize and another PDF file after I have initialized the first file. If you cannot help please let me know if should use an earlier  version of Reader or find anther company that has the appropriate software.

    Perhaps you missed that you started a discussion at I have OS 10.9.2 and have downloaded latest version of Reader 11. I can no longer fill in form or scroll using the side bar. and you did not respond to the last post there.

  • The time complexity of "Sort 1D Array"

    Does anyone know the time complexity of "Sort 1D Array"? The document of this function does not say anything about that, so I write test VI to sort an array of 10000 integer elements. It seems that the excution time is less than 1 second, so I guess the complexity is O(n*logn). Any suggestion would be appreciated, thanks.

    A few thoughts based on my recollection of that old coding challenge.  There are different kinds of algorithmic approaches you may consider.
    1. A simple approach to that challenge could involve a lot of search / lookup functions.  Each time you parse a word, you perform a search to see if it's in your list already.  If so, increment its count.  If not, add it to the list with count=1.
       This was far too slow for word counting large docs.  Too many slow-ish searches.  But pretty easy to implement and maybe good enough for smaller docs.
    2. I pursued an approach that used hashing instead of searches.  It *seemed* too slow, but some months after the challenge when I had another use for the core hash table functionality, I found a really dumb bug that I'd overlooked before.  Fixing it improved the speed by something like 100x.  (Missed one spot where I needed a shift register to enforce in-placeness).
       This is largely the same approach, merely trying to speed up the lookup/search function via a more complex technique (hash tables).  As I found out, the complexity makes it more bug-prone.  Still, once fixed, lookup speed is in the order of constant with no clear dependency on the number of elements in the hash table.  (Note: it *is* still dependent on the "fill ratio".  You want enough memory available to size your table for maybe ~25% usage or less.)
    3.  One idea I tried out was to maintain a separate list of the 10 or 25 most-common words, sorted by count.  (The main reason was that there could be a tie for 4th place at the end, and I wanted enough extra candidates around to get the correct tie-breaker result.)  Each time I parsed another word and incremented its count, I'd check to see whether its new count qualified it to belong in the special most-common list.  I still did a lot of lookup and sort stuff, but it was always on a very
    There are surely other kinds of data structures and algorithms available.  Do you have a specific app in mind for this?  Or just generally curious?  I ask because some of the things one might do to optimize for a specific app (or code challenge) wouldn't be so appropriate as a general-purpose routine.
    -Kevin P.

  • Some question regarding time evaluation

    Hello,
    I have two questions regarding time evaluation:
    1. Is it possible (if yes, how) to still include a employee in time evaluation even if this employee is inactive (status P0000-STAT2 = 0). We need this in order to calculate weeks of not working (this has to be calculated). I know that for payroll this is possible wih a setting in infotype 0003.
    2. Is it possible (and how) to read data back from payroll into time. For example in payroll you export something to ZL table, can you then pick this up in time evaluation schema, as there is also ZL table. Or is there another way to do this?
    Thanks for you answers,
    Liesbeth

    hi Schrage
    Why you want to evaluate the time for inactive person.
    If you want you can do.
    Process :
    First of all you have to group your employees. and sub groups.( for inactive emp)
    Assign the employee sub group grouping for PCR in Basic Pay ( IMG ).
    Then come to Time Evaluation Schema. Put the Day grouping nn nn nn nn in the Parameters. and run the time evaluation. You will get the output in DZL table.
    For the above process you need to configure the T510S table.
    Yes you can read the payroll into time.
    the same concept will run in both of the modules.
    the output should appear in the ZL table only.
    Here the concept is.....Some companies, they will not use the payroll wage types. only they will use the time wage types.. these wage types has to be configure in the T510S. and we have to do the wage type copying from the part of time management only if they are not using the payroll. So either in Payroll or in Time management the evaluation of time willbe the same.
    Cheers
    Vijai

  • Financial website doesn't recognize my computer and asks security questions each time I log in

    When I sign into a financial website it doesn't remember my mac and requires me to answer security questions each time.  I called the website and they said the problem is with my mac's settings.  Anyone else have this problem?

    They do it for YOUR protectoin and security and to avoid someone else pretending to be you.
    They may or may not use cookies and other things.
    it is possible it was designed to work with a differenent browser or even platform though I would say that has gotten rarer.
    Assuming you use Apple Safari
    Safari
    http://www.apple.com/support/safari
    you are asking us to make assumptions and jump to conclusions also.
    Enable the Developer menu in Safari and User Agent setting to 'tell' a site you are using something else;
    try using Firefox 3.6.17 also.
    Check your preferences

  • A technical question about time.

    I find myself wondering what would be the total playing time of my iTunes library. How can I determine this? I could copy the total file into Excel then add up the time column, but as I have 12,000 tracks I doubt Excel could handle it. Is there a simple way to do this?

    Select Library - Music and look at the botton center of the iTunes window.
    Click it to change the displayed info.
    A technical question about time.
    T=2π √L/G

  • Any real time complex validations and assignments

    Hi frds,
    Any one can share few real time complex validations and Assignments on product object?
    Thanks in advance
    Regards.

    Rajeev,
    I do not have real time validation exaples. There are couple of blogs on SDN
    search for
    MDM Expression Engine
    (the document name is MDM Express Engine: Validations,Assignments and More)
    Parsing and Validating Numbers
    (used for check digits but gives more insight on writing validations.)
    I hope this helps
    Regards
    Bala Pochareddy

  • Time complexity

    Hi,
    I there any way to check time complexity(time units) of a code/program..

    from the program u can call
    SWO_GET_RUNTIME_INFO
    fn module

  • My question last time didn't get answered. Can I send in my iPod touch for a new one if I have a two year warranty?

    My iPod touch 5th gen isn't charging, when I plug in my charger I've always used. It's an apple product and a message pops up saying "This accessory may not be supported" The charger isn't the problem because my mom used her iPhone with my charger and her phone charges fine with it. For Christmas, I got a portable charger and I used it the day after Christmas for a little bit and it worked, but then 20 minutes later my brother wanted to use it. So I let him use it. Then I went to go use my normal charger instead and when I plugged it in that message popped up. It's been like this sense the day after Christmas and the only way it charges is right before I swipe right to turn my iPod all the way off I plug my charger in real fast before the message can pop up. I've tried resetting my iPod, cleaning out the area it charges, and few other things. I've also tried getting help from people that work with technology at some stores. They all told me I had to contact Apple Support Communities. I'm trying to contact you guys, but last time I did it didn't solve my problem. I really want to get an answer to be able to fix it or have it replaced. I'm 13 and saved all my money on my own to get the iPod have. It took me a long time to save and I really don't it to be broken and not be able to get it replaced. Someone please help my resolve this.

    You late question did get answered:on the 18th of this month. Sounds like you did not like the answers. Starting a new post without mentioning yur first post wastes people time
    My iPod touch 5th gen isn't charging and when I plug my working charger in that I've always used a message pops up that says "This accessory may not be supported". So can I send it in for a new one if I have a warranty?

Maybe you are looking for

  • Locking issues with transaction-isolation levels

              I believe that my program is suffering from some sort of deadlock, and I was hoping           for some feedback.           I am helping to develop a trading system           using EJBs, Oracle 9i, and Bea Weblogic 7.0. The system provides a

  • Increase file system size

    Hello, I have solaris9 system where on disk c0t0d0, I have 7 partitions. The first partition shows file system mounted=yes with 10GB space. This file system is near full ( 95% used). I need to increase the size. How can I do that? I have another part

  • Good receipt document can't be found

    hi everyone.. My name angga. currently i simulate make good receipt using BAPI_GOODSMVT_CREATE. i am input this field : GOODSMVT_HEADRET - posting_date -> 20.08.2008       - doc_date -> 20.08.2008 - gm_code -> 01 GOODSMVT_ITEM - material             

  • Printing problems with OS X 10.6.8

    Xerox Phaser 8550 displays "Configuration Error" when large Photoshop CS5.1 files are printed. Xerox says they have received many calls about similar problems and state that it's a problem with 10.6.8.  Any advice?  Thanks. 

  • Open CrystaReport on Business Object Infoview

    Hy, i have this problem: i create a crystal report and i publish on particular folder. The problem is when i try to open this report on Business Object Infoview because i receive this error message: Unable to find servers in CMS ..:6400 and cluster @