1. Time complexity (large o notation):
O (1) < O (logn) < O (n) < O (Nlogn) < O (N2) < O (n3) < O (2n) < O (n!) < O (NN)
(1) Time complexity of commonly used data structures in Python:
The time complexity of the list built-in operations:
Dict time complexity for built-in operations:
(2) Abstract datatype (adt:abstract data type):
Common data Operations (5 types):
Increase (insert)
deleting (deleting)
Change (change)
Check (Find)
Sort
2. The implementation of the stack:
(1) The performance of the stack:
(2) The operation of the stack:
stack (): Create a new empty stack
push (item): Add a new element item to the top of the stack
pop (): Pop-up stack top element
Peek (): Returns the top element of the stack
is_empty (): Determines whether the stack is empty
size (): Returns the number of elements in the stack
(3) Implementation stack:
1 classStack (object):2 """implementation of the stack"""3 def __init__(self):4Self.__list= []5 6 #Add a new element item to the top of the stack7 defpush (self, item):8Self.__list. Append (item)9 Ten #pop-up stack top element One defpop (self): A returnSelf.__list. Pop () - - #returns the top element of the stack the defPeek (self): - ifSelf.__list: - returnSelf.__list[-1] - Else: + returnNone - + #determine if the stack is empty A defIs_empty (self): at returnSelf.__list== [] - - #returns the number of elements in the stack - defsize (self): - returnLen (self.__list) - in - if __name__=="__main__": tos =Stack () +S.push (1) -S.push (2) theS.push (3) *S.push (4) $ Panax Notoginseng Print(S.pop ()) - Print(S.pop ()) the Print(S.pop ()) + Print(S.pop ())
Operation Result:
1. Time complexity (large o notation) and implementation of stacks using Python