Professional Documents
Culture Documents
Arrays, Link Lists, Stacks and Queues
Arrays, Link Lists, Stacks and Queues
Deliverables
Arrays
Link Lists
Stacks
Queues
6/5/2012 7:14 PM Copyright@ gdeepak.com 2
Arrays
Arrays are stored in contiguous memory locations and contain similar
data. Position of any array element can be accessed from its index
position with help of array’s starting address.
3 10 0 -135 2 21 41 6 87 11
Continuous allocation is required for array, while this is not with link
list
There will be more cache misses in the Link list then in the
arrays
Chain of method
calls in the Java In other data
Recursion
Virtual Machine, Structures
Function Calls
6
98
37
25
12
5
6/5/2012 7:14 PM Copyright@ gdeepak.com 24
Stack Example
Push
Array: increment “top” and insert element. Must check for overflow!
Linked list: insert element at front of linked list
pop(push(S, v))=S
Top(push(S, v))=v
Top(pop(push(push(S,12),15))) = top(push(S,12))
5 45 71
Perform Operations
Enqueue 99
Dequeue
Dequeue
99
6/5/2012 7:14 PM Copyright@ gdeepak.com 31
Queues
isEmpty():return
size(): returns
s Boolean
number of
indicating queue
elements stored.
is empty or not
O(1)
O(1)
Multiprogramming
Tunnel
Circular Queue is
essentially implemented
as a linear array in a
wrapped around fashion
where even rear pointer
r f
of the queue can come
before the front pointer
6/5/2012 7:14 PM Copyright@ gdeepak.com 35
Questions, Comments and Suggestions