More

    LINKED LIST VS. ARRAYS

    Linked Lists and Arrays can be used for storing a list of data.

    Arrays are allocated continuous memory locations and the array name holds a reference to the beginning of this memory block. Individual elements can be located easily, randomly and in constant time by calculating the exact memory location of the element using the start memory location of the allocated block and the position (index) of the element.

    Linked lists however are not allocated with fixed continuous memory locations. In a linked list nodes are allocated in different memory locations and each node points (contains the address of) the next node in the list. Last node does not point to anything. Both arrays and linked lists have their advantages and disadvantages.

    Advantages of arrays

    1. Simple and easy to use
    2. Faster constant time access to the elements.

    Disadvantages of arrays

    1. Fixed Size
    2. Complex position based insertion
      • To insert an element at a given position we might have to shift the remaining elements to its right.

    Advantages of linked lists:

    1. They can be expanded in constant time. Insertions and deletions will be faster.
    2. No wastage of space, except the space used for pointers. We can start with space for just one element allocated and add on new elements easily.

    Disadvantages of linked lists

    1. Array support random-access and it takes only 0(1) to access any element in the array. In linked lists we need to traverse the list to reach the required node and hence take 0(n) in worst case.
    2. Overhead of storing and retrieving data.

    You can learn about arrays in Java at javajee.com/introduction-to-arrays-in-java

    Recent Articles

    OAUTH – FREQUENTLY ASKED QUESTIONS FOR INTERVIEWS AND SELF EVALUATION

    Why is refresh token needed when you have access token? Access tokens are usually short-lived and refresh tokens are...

    SUMO LOGIC VIDEOS AND TUTORIALS

    Sumo Logic Basics - Part 1 of 2 (link is external) (Sep 29, 2016)Sumo Logic Basics - Part 2 of 2...

    GIT – USEFUL COMMANDS

    Discard all local changes, but save them for possible re-use later:  git stash Discarding local changes...

    DISTRIBUTED COMPUTING – RECORDED LECTURES (BITS)

    Module 1 - INTRODUCTION Recorded Lecture - 1.1 Introduction Part I – Definition

    BOOK REVIEW GUIDELINES FOR COOKBOOKS

    Whenever you add reviews for the book, please follow below rules. Write issues in an excel.Create an excel...

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Ge the daily news in your inbox