Lecture5 - Lists EECS 233 Previous Lectures Memory...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Lists EECS 233
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
-2- Previous Lectures Memory management by PLs OO programming, ADT Recursion Mathematical background and running time analysis We start to learn “data structures” today!
Image of page 2
-3- How to Represent A Sequence of Data? A sequence: an ordered (but not sorted) collection of items 32, 5, 4, 24, 3, 5, 7, … “David”, “Mark”, “Grace”, “Tim”, “Tim”, “Michael”, “David”, … Different from A bag, which is not ordered A set, which contains unique items
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
-4- A List ADT View list as a black-box object with certain operations Empty list on creation Get an i-th element Add a new element at position i Remove an element at position i Get the number of elements in the list Check if a given element (specified by its position i or by a reference) is the last in the list Etc… See Java list interface: Which data structures to use for implementation??
Image of page 4
-5- Array Representation Store list elements wall-to-wall in memory in an array Keep a variable recording the current number of elements Advantages Easy and efficient access to any item in the sequence item[i] gives you the item at position i Random access Every item can be accessed in constant time given its index Very compact: no auxiliary fields are required Disadvantages of using an array: The need to specify an initial array size and resize as required (how?) Difficult to insert/delete items at arbitrary positions (running time?) May have many empty positions 32 17 46 lst numItems
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
-6- Linked List Representation
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern