mercredi 11 novembre 2020

If statement and O(1) complexity

If there is an if else condition and if consists of 2 lines and else of 1 or generally the one has one more line, is the program O(1) ?

edit: The following example is about linked lists.

For example:

    public String smth() throws NoSuchElementException{
        if (size!=0) {  
            Object n = tail.item;
            
            if (size!=1) {
                tail = tail.prev;
                tail.next = null;
                
            }
            else{       
                head.prev = null;       
                head = head.next;
                tail = tail.prev;
            
                
            }   
            
            this.size = this.size - 1;
            return n.toString();
        }else {
            throw new NoSuchElementException();
        }
    }

Aucun commentaire:

Enregistrer un commentaire