SlideServe
Menu
Préférences
© SlideServe · v2026

Exploring List Implementations: Arrays vs. Linked Lists and Recursive Structures

casper avatar
14 diapositives · 259 Views · Jul 17, 2014

This week's assignment focuses on software design issues, particularly in list implementations. We'll compare array-based implementations like ArrayList with the advantages and disadvantages of linked lists. Discussions will include the efficiency of insertions, space allocation, and the importance of recursive definitions in lists. Students will work in teams to review submission processes, with individual write-ups due Monday. The state-based list implementation presented in lecture will illustrate cohesive and decoupled components, fostering a deeper understanding of list structures and their applications.

Exploring List Implementations: Arrays vs. Linked Lists and Recursive Structures - slide 1
01 / 14Exploring List Implementations: Arrays vs. Linked Lists and Recursive Structures
1 / 17

Télécharger la présentation

Exploring List Implementations: Arrays vs. Linked Lists and Recursive Structures
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. No homework this week • Stage 2 starts next week

  2. Code review • Team with N members is assigned N submissions to review • Discuss submissions within team • Everyone on team writes up one review • Write-ups are done on an individual basis • Due on Monday • Stage 2 begins on Monday

  3. Today • Software design issues • In context of list definition • Recursion • In context of list definition

  4. Lists • We’ve seen an array-based list implementation, the ArrayList. • Advantage of an array-based implementation: • fast access to a specific index • typically less space usage than other options • Disadvantage of an array-based implementation: • can be expensive to insert items • resizing is an expensive operation

  5. Amortization • Resizing of array-based data structures involves a tradeoff: • many insertions (as in our Bag) are very efficient since no allocation of space is required (an array is allocated as a big block of memory) • some insertions (as in our Bag) are very expensive since resizing must take place

  6. Linked List • A linked list is a list implementation which spreads out the cost of space allocation evenly to all insertions. • Each insertion involves allocation of space

  7. Advantages/Disadvantages • Advantages • predictable cost of insertion • efficient insertion at any point in structure • Disadvantages • extra space required to store links • inefficient indexing

  8. Comparison of storage • A pair has a first and a second element • When pairs are used to construct lists, • the first is called the “head” or the “car” • the second is called the “tail”, “rest” or “cdr” • the pair is called a “cons cell” or simply a “cons”.

  9. Linked list implementations • Textbook discusses a typical linked list implementation • java.util.LinkedList is another typical implementation • These implementations have procedural, not object-oriented, roots.

  10. Traditional implementations • provide a large number of methods – making it difficult to reuse if less functionality is desired; • provide no means, beyond inheritance, to extend functionality to suit a specific situation; and • adding functionality requires knowledge of internal structure of the list.

  11. So… • These implementations are inflexible, and do not exhibit good OO design. • In lecture we will discuss a state-based list implementation which can be easily extended with new functionality.

  12. Variant/Invariant decomposition • Design principle which leads to cohesive and decoupled components • That which is invariant is put into one component • Variant properties/behaviors are factored out into separate components • Compare this to what we saw with e.g. Observer pattern: • decoupling of event generation (invariant) from event handling (variant)

  13. a list = a Linear Recursive Structure(LRS or LRStruct) • What is a list? • the empty list is a list • a pair whose tail is a list is itself a list • This is a recursive definition! (1) is called the base case, and (2) is called the recursive case. • Note that traditional implementations do not follow this precise definition of what a list is: • many have no explicit representation of an empty list • none are recursive on the list; instead they recurse on a list node • This has implications for how the structure can support extension (see Visitor support, in later slides)

  14. States • A list can therefore be in one of two states: • empty (corresponding to the base case) • non-empty (corresponding to the recursive case) • The state-based implementation we will study makes this distinction explicit in the representation