Do not confuse these two conceptions:

 

1.Data representation

How we organize data in physical memory.

 

1) Formula-based representation

In this kind of data representation, we can use a formula to determine where to store each element of a list. The simplest case is to store successive element of a list in successive memory location.

For example:

            An array. location(i) = i - 1, so we can find ith element in array[i-1]

 

2) Linked representation

The elements of a list may be stored in any arbitrary set of memory locations. So each elements has an explicit pointer that tells us the loction of the next element in the list.

For example:

            A linked list.

 

3) Indirect addressing

A combination of 1) and 2). That means the list elements may be stored in any arbitrary set of location, but we maintain a table such that ith table entry to tell us where the ith list element is. So, the table stores the addresses of the list element.

 

 

 

 

 

 

 

 

 

 

 


Note: If we use formula-based representation, we need to predict the maximum possible size of data. So, we can say it is static and sometimes it will cost waste of space. The same thing can happen with indirect addressing representation. But linked representation is more flexible because you can dynamically create a new node and insert it into the list without change the location of others. In other words, you need not pre-allocate enough space for storing elements.

 

2. Data structure

How we organize data logically.

 

So, the most important thing for each kind of data structure is those properties it must maintain (such as stack on which operation can only be taken on one side) and the operations on them.

Whatever data representation you use, you can probably construct some kind of data structure on it. The major difference is the time used on operation.

 

Let assume the size of each element is s. There are totally n elements.

We have:

 

 

 

   

  Representation

                                   Function

 

  Find kth element

 

Delete kth element

 

  Insert after kth  

       element

 

    Formula-based

 

          O(1)

 

O((n-k)*s)

 

O((n-k)*s)

         Linked           

    representation

 

           O(k)

 

O(k)

 

O(k+s)

 

  Indirect addressing

 

           O(k)

 

O(n-k)

 

O(n-k)

 

 

Note:

1)in formula-based and indirect addressing representation, after delete and insert element, you should move some elements to keep the original property of this representation.

For example: it you insert a new element into an array, you should move backward those elements behind the new element.

2)the time complexity of the function that perform on the lined represented data of insertion and deletion are independent of the size of the list element.

3)the complexity is linearly dependent on the element size in formula-based data representation.