07-stack_queue - CSE 143 Lecture 7 Stacks and Queues slides created by Marty Stepp http/www.cs.washington.edu/143 Runtime Efficiency(13.2

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

View Full Document Right Arrow Icon
CSE 143 Lecture 7 Stacks and Queues slides created by Marty Stepp http://www.cs.washington.edu/143/
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Runtime Efficiency (13.2) efficiency : A measure of the use of computing resources by code. – can be relative to speed (time), memory (space), etc. – most commonly refers to run time • Assume the following: – Any single Java statement takes the same amount of time to run. – A method call's runtime is measured by the total of the statements inside the method's body. – A loop's runtime, if the loop repeats N times, is N times the runtime of the statements in its body.
Background image of page 2
3 ArrayList methods returns a string representation of the list such as "[3, 42, -7, 15]" toString() returns the number of elements in list size() replaces value at given index with given value set( index , value ) removes/returns value at given index, shifting subsequent values left remove( index ) returns the value at given index get( index ) returns first index where given value is found in list (-1 if not found) indexOf( value ) removes all elements of the list clear() inserts given value at given index, shifting subsequent values right add( index , value ) appends value at end of list add( value ) • Which operations are most/least efficient, and why?
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Stacks and queues • Sometimes it is good to have a collection that is less powerful, but is optimized to perform certain operations very quickly. • Today we will examine two specialty collections: stack : Retrieves elements in the reverse of the order they were added. queue : Retrieves elements in the same order they were added. stack queue
Background image of page 4
5 Abstract data types (ADTs) abstract data type (ADT) : A specification of a collection of data and the operations that can be performed on it. – Describes what a collection does, not how it does it • We don't know exactly how a stack or queue is implemented, and we don't need to. – We just need to understand the idea of the collection and what operations it can perform. (Stacks are usually implemented with arrays; queues are often implemented using another structure called a linked list.)
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Stacks stack : A collection based on the principle of adding elements and retrieving them in the opposite order. – Last-In, First-Out ("LIFO")
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/04/2011 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Page1 / 20

07-stack_queue - CSE 143 Lecture 7 Stacks and Queues slides created by Marty Stepp http/www.cs.washington.edu/143 Runtime Efficiency(13.2

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