Lecture5 - Lists EECS 233-2 Previous Lectures Memory...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lists EECS 233-2- Previous Lectures Memory management by PLs OO programming, ADT Recursion Mathematical background and running time analysis We start to learn “data structures” today!-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-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 (speciFed by its position i or by a reference) is the last in the list Etc… See Java list interface: W h i c h d a t a s t r u c t u r e s t o u s e f o r i m p l e m e n t a t i o n ? ?-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 efFcient 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 Felds are required Disadvantages of using an array: The need to specify an initial array size and resize as required (how?) DifFcult to insert/delete items at arbitrary positions (running time?) May have many empty positions 32 17 46 … lst numItems-6- Linked List Representation...
View Full Document

This note was uploaded on 04/07/2008 for the course EECS 233 taught by Professor Rabinovich during the Spring '08 term at Case Western.

Page1 / 19

Lecture5 - Lists EECS 233-2 Previous Lectures Memory...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online