Tuesday 11 March 2014

Lists



Specification

AbstractDataType  LinearList{ 
  instances 
    finite ordered collection of elements 
  operations 
    create():   create an empty list 
    destroy(): 
    IsEmpty() 
    Length(): 
    Find(k):    find k'th element 
    Search(x):  find position of x 
    delete(): 
    insert(x): insert x after the current element element 
    output(): 
} 

Array Representation

      |---|
length |5  |
      ----------------------------------
      |e  |e |  ...   |e  |   |  |   |   |
      |-1-|-2|-------|-n-|---|--|---|---|
  • Operations require simple implementations.
  • Insert, delete, and search, require linear time
  • Inefficient use of space

One-way Linked Representation

     |---|
prev |10 |
     ----
     |   |
 curr |5--|

        | |--- |||---| |||---|   |            | |---|
    ----|||-----||----- |--------||       ---- |----|
          |e |   |e  |   |e  |                  |e  |
          |-1|   |-2-|   |-3-|                  |-n-|
  • Insert and delete in O(1) time
  • Search in O(n) time
  • Memory overhead, but allocated only to entries that are present.

Circular One-way Linked Representation

     |---|
prev |10 |
     ----
     |   |
 curr |5--|
    ----------------------------------------------|
   |||                                            |
  |---|   |---   |---|   |---|                  |-|-|
  | ----||| ----|| ----||- ------||       ----||-   |
  |---|   |--|   |---|   |---|                  |---|
  |/--|   |e1|   |e2-|   |e3-|                  |en-|
  • The head node, together with the circular representation, simplify the dealing with boundaries conditions

Doubly Linked Representation

||---|-----|-|---|------|---|---------           --------|-|--|--
|| e1 | ----| |e2 | ---- |e3 | --------           --------| |en | |
--------   --------   --------                           --------


  • Insert and delete in (1) time.
  • We can also go here for doubly linked list with an additional header node.

No comments:

Post a Comment

 

FACEBOOK PAGE

SKETCHES & PAINTINGS