linked structures songs games movies ii
play

Linked Structures Songs, Games, Movies II Fall 2013 Carola Wenk - PowerPoint PPT Presentation

Linked Structures Songs, Games, Movies II Fall 2013 Carola Wenk Linked Lists x: y: hello world! The simplest dynamic structures is a linear ordering of data, called a linked list. We saw that is was easy to modify a


  1. Linked Structures Songs, Games, Movies II Fall 2013 Carola Wenk

  2. Linked Lists x: y: “hello” “world!” The simplest dynamic structures is a linear ordering of data, called a “linked list”. We saw that is was easy to modify a linked structure without “touching” all of the data. How do we implement additions and deletions? Is finding an item efficient?

  3. Adding Items Actually, what does it mean to add to a linked list? How do we add to the beginning of the list? . . . L:

  4. Adding Items Actually, what does it mean to add to a linked list? How do we add to the beginning of the list? . . . L: x:

  5. Adding Items Actually, what does it mean to add to a linked list? How do we add to the beginning of the list? . . . L: x:

  6. Adding Items Actually, what does it mean to add to a linked list? How do we add to the beginning of the list? . . . L,x: Adding to the front of a list is easy and requires constant work.

  7. Adding Items Actually, what does it mean to add to a linked list? How do we add to the end of the list? p: . . . L: x:

  8. Adding Items Actually, what does it mean to add to a linked list? How do we add to the end of the list? p: . . . L: x:

  9. Adding Items Actually, what does it mean to add to a linked list? How do we add to the end of the list? p: . . . L: x:

  10. Adding Items Actually, what does it mean to add to a linked list? How do we add to the end of the list? p: . . . L: x:

  11. Adding Items • Actually, what does it mean to add to a linked list? How do we add to the end of the list? p: . . . L: x: Sadly, we must traverse the entire structure just to add to the end!

  12. Adding Items • Actually, what does it mean to add to a linked list? How do we add to the end of the list? L_head: L_tail: . . . x: If we kept track of the end of the list, then we could add an item with just a few operations.

  13. Adding Items • Actually, what does it mean to add to a linked list? How do we add to the end of the list? L_head: L_tail: . . . x: But, if we wanted to insert anywhere else, we’re still out of luck.

  14. Finding Items • To find anything in a linked list, we again need to (potentially) traverse the entire structure. The implementation is easy, but in the worst case it is no better than a linear search, regardless of whether the linked list is ordered or not! . . . L: Finding an element is no better than in an array; it takes time that is linear in the size of the list.

  15. Removing Items • We must also keep track of the preceding element, so that we can reassign its neighbor. p: . . . L: x The implementation is easy, but in the worst case it is no better than a linear search, regardless of whether the linked list is ordered or not!

  16. Removing Items • We must also keep track of the preceding element, so that we can reassign its neighbor. p: . . . L: x The implementation is easy, but in the worst case it is no better than a linear search, regardless of whether the linked list is ordered or not!

  17. Removing Items • We must also keep track of the preceding element, so that we can reassign its neighbor. p: . . . L: x The implementation is easy, but in the worst case it is no better than a linear search, regardless of whether the linked list is ordered or not.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend