Data Structure 4

  1. What are Collection ADTs
    Unlike queues and stacks, the Collection ADTs allow retrieval of information based on the contents of the information.
  2. in Collection ADT, in what order are the elements and how does retrieval work?
    Elements in a collection are not in any particular order. Retrieval of an element requires comparisons.
  3. what does the == operator compare?
    • It returns true if and only if the
    • two variables reference the same object.

    or if they have the same value
  4. How does the ADT manipulates in By copy and in By reference
    By copy: The ADT manipulates copies of the data used in the client program.

    • By reference: The ADT manipulates references to the actual
    • elements passed to it by the client program. This is the most
    • commonly used approach and is the approach we use in our
    • course.
  5. Implementing ADTs "by copy" 

    what method to make copies? and what interface? 

    Drawbacks?
    • Object's clone method, Cloneable interface
    • Drawbacks: 
    • Copy of object might not reflect up-to-date status of original object
    • Copying objects takes time, especially with deep-copying methods.
    • Storing extra copies of objects also requires extra memory.
  6. Implementing ADTs "by reference"

    what is exposed? 

    what are the drawbacks?
    contents of the collection ADT are exposed ot the client program so it has direct access to the individual elements in the collection 

    Drawbacks: 

    Objects are accessed through aliases so the client program could accidently change an attribute of the objects. This might in turn cause problems. For example if it changes the key value for an element stored in a sorted list, then the order of the list is broken.
  7. which one is better in terms of space and time for by reference and by copy?
    • If processing time and space are issues, and if we are comfortable
    • counting on the application programs to behave properly, then the
    • "by reference" approach is probably best.

    • If we are not too concerned about time and space (maybe our list
    • objects are not too large), but we are concerned with maintaining
    • careful control over the access to and integrity of our lists, then the
    • "by copy" approach is probably best.
  8. Array-based implementation 

    insertion for sorted lists

    deletion for sorted lists

    insertion for unsorted lists

    deletion for unsorted lists
    Insertion for sorted lists: need to shift elements after the insertion position one slot toward the end.

    Deletion for sorted lists: need to shift elements after the deletion positionone slot toward the front.

    Insertion for unsorted lists: can simply insert the element to the first empty slot in the list. No shift is needed.

    Deletion for unsorted lists: use the last element to replace the deleted element. No shift is needed.
  9. Reference-based implementation 

    insertion for unsorted lists: 

    insertion and deletion for sorted lists:
    Insertion for unsorted lists: can simply insert the element to the front of the list.

    Insertion and deletion for sorted lists: need to update references of the related nodes.
  10. what are the two fields in a node in a singly linked list
    data and link(a reference to the next-node)
  11. Adding an element to a reference-based sorted list requires three steps:
    1.Find the location where the new element belongs;

    2.Create a node for the new element;

    3.Correctly link the new node into the identified location.
  12. Circular linked lists
    list in which every node has a successor; the "last" element is succeeded by the "first" element.
  13. Circular linked list 

    create : 

    public booleaan remove (T element)
    • public booleanremove (T element)
    • // Removes an element e from this list such that
    • // e.equals(element) and returns true;
    • // if no such element exists returns false.
    • {
    •   find(element);
    •   if (found)
    •   {
    •      if (list == list.getLink()) // if single element list
    •         list = null;
    •       else
    •           if (previous.getLink() == list) // if removing last node
    •               list = previous;
    •           previous.setLink(location.getLink()); // remove node
    •           numElements--;
    •    }
    •    return found;
    • }
  14. Circulat linked list: 

    the add method

    public void add(T element)
    • public void add(T element)
    • // Adds element to this list.
    • {
    •     LLNode<T> newNode= new LLNode<T>(element);
    •     if (list == null)
    •     {
    •         // add element to an empty list
    •         list = newNode;
    •         newNode.setLink(list);
    •     }
    •     else
    •     {
    •       // add element to a non-empty list
    •       newNode.setLink(list.getLink());
    •       list.setLink(newNode);
    •       list = newNode;
    •      }
    •       numElements++;
    • }
  15. Doubly linked lists
    linked list in which each node is linked to both its successor (link) and its predecessor (back).
  16. what is a header node?

    what is a trailer node?
    Header node-A placeholder node at the beginning of a list; used to simplify list processing.

    Trailer node-A placeholder node at the end of a list; used to simplify list processing.
Author
lcsanc14
ID
344077
Card Set
Data Structure 4
Description
final test
Updated