1 / 12

Linked Lists

Linked Lists. Topics to be discussed…. Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists. myList. a. b. c. d. Linked list.

colin-gates
Download Presentation

Linked Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked Lists

  2. Topics to be discussed… Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists

  3. myList a b c d Linked list • A linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence; more complex variants add additional links. This structure allows for efficient insertion or removal of elements from any position in the sequence. • Each node contains a value and a link (pointer or reference) to some other node The last node contains a null link back

  4. More terminology • A node’s successor is the next node in the sequence • The last node has no successor • A node’s predecessor is the previous node in the sequence • The first node has no predecessor • A list’s length is the number of elements in it • A list may be empty (contain no elements) back

  5. Here is a singly-linked list (SLL): Each node contains a value and a link to its successor (the last node has no successor) The header points to the first node in the list (or contains the null link if the list is empty) myList a b c d Singly-linked lists

  6. Insertion Description • Insertion at the top of the list • Insertion at the end of the list • Insertion in the middle of the list

  7. Deletion Description • Deleting from the top of the list • Deleting from the end of the list • Deleting from the middle of the list

  8. Other operations on linked lists • Most “algorithms” on linked lists—such as insertion, deletion, and searching—are pretty obvious; you just need to be careful • Sorting a linked list is just messy, since you can’t directly access the nth element—you have to count your way through a lot of other elements back

  9. Here is a doubly-linked list (DLL): Each node contains a value, a link to its successor (if any), and a link to its predecessor (if any) The header points to the first node in the list and to the last node in the list (or contains null links if the list is empty) myDLL a b c Doubly-linked lists

  10. Advantages: Can be traversed in either direction (may be essential for some programs) Some operations, such as deletion and inserting before a node, become easier Disadvantages: Requires more space List manipulations are slower (because more links must be changed) Greater chance of having bugs (because more links must be manipulated) DLLs compared to SLLs back

  11. Circular Lists A circular linked list is a linked list in which the head element's previous pointer points to the tail element and the tail element's next pointer points to the head element. In the special case of a circular list with only one element, the element's previous and next pointers point to itself, and it is both the head and tail of the list. back

  12. Thank You

More Related