Arrays and Linked Lists Flashcards
1
Q
What is array?
A
Contiguous area of memory consisting of equal-size elements indexed by contiguous integers.
2
Q
Time for Array Operation
A
access to any element - o(1) (constant time)
add / remove at the end - o(1) (constant time)
add / remove at the front / middle - o(n) (linear time)
3
Q
Time for Singly-Linked List Operation
A
Find - o(n) Empty - o(1) AddBefore(node,key) - o(n) AddAfter(node,key) - o(1) no tail PushFront - o(1) TopFront - o(1) PopFront - o(1) PushBack - o(n) TopBack - o(n) PopBack - o(n) with tail PushFront - o(1) TopFront - o(1) PopFront - o(1) PushBack - o(1) TopBack - o(1) PopBack - o(n)
4
Q
Time for doubly linked list Operation
A
Everything o(1) except find operation ( o(n) )