• DLL_Vs_CLL


    What is Circular Linked List ? What are Advantages and Disadvantages of Circular Linked List

     
     

    In it the last node does not contain NULL pointer. Instead the last node contains a pointer that has the address of first node and thus points back to the first node. 

    It is shown below: 

    Circular Linked List

    Advantages: 

    1. If we are at a node, then we can go to any node. But in linear linked list it is not possible to go to previous node.
    2. It saves time when we have to go to the first node from the last node. It can be done in single step because there is no need to traverse the in between nodes. But in double linked list, we will have to go through in between nodes. 

    Disadvantages: 

    1. It is not easy to reverse the linked list.
    2. If proper care is not taken, then the problem of infinite loop can occur.
    3. If we at a node and go back to the previous node, then we can not do it in single step. Instead we have to complete the entire circle by going through the in between nodes and then we will reach the required node. 

    Advantages of Doubly linked list over singly linked list
    1) A doubly linked list can be travel across in both forward and backward direction.
    2) For delete operation a pointer to previous node is needed that is difficult in singly linked list so we need to traverse the list but in doubly linked list the previous node can be found easily using previous pointer.


    Disadvantages of Doubly linked list over singly linked list
    1) In doubly linked list extra space is required for previous pointer.

    2) In all operations like insertion and deletion, an extra pointer (previous pointer) has to be maintained.

    Circular Linked List

    In Circular linked list all nodes are connected in such way that they form a circle and no NULL at the end of the list like a circle.

    Advantages of Circular Linked Lists:
    1) In this linked list any node can be a starting point. And to traverse list, we can start at any point and stop when the first node is visited again.

    2) Unlike doubly linked list, in this linked list we don’t need to focus on two pointers for next and previous. So it is useful implementing a queue.

    3) It is also useful for repeating list. For example operating system, so that when it reaches the end of the list of all application it can go to the front of the list

    4) Circular DLL are used to implement advanced data structures like Fibonacci Heap.

    Singly, Doubly & Circular Linked List

     
    This is a basic type of Linked List.

     SinglyDoublyCircular
    Concept One way direction Two way direction One way direction in a circle
    Has head Yes Yes No-because tail will refer to first node
    Has tail Yes Yes Yes
    No of Node 1-next node 2-next node & previous node 1-next node
    insert() O(n) O(1) O(n)
    delete() O(n) O(1) O(1)
    Benefit require small space for each element allow to traverse the list in both directions execute to the end can be quickly
  • 相关阅读:
    让IE6/IE7/IE8支持HTML5标签的js代码
    你应该抓紧学习Python,它是开发Web应用最强大的语言
    细数IE6的一串串的恼人bug,附加解决方法!
    邪恶的编码:复制与粘帖
    谈谈微信公众平台开发
    jQuery练手:仿新浪微博图片文字列表淡进淡出上下滚动效果
    DIV-CSS布局中position属性详解
    解决java编译错误:编码GBK的不可映射字符
    离线下载安装 NLTK 的 nltk_data 模块
    Python NLTK 自然语言处理入门与例程(转)
  • 原文地址:https://www.cnblogs.com/szzshi/p/7093418.html
Copyright © 2020-2023  润新知