07-stack-queue - CSE 143 Lecture 7 Stacks and Queues reading Stuart Reges notes on website Runtime Efficiency(13.2 efficiency A measure of the use

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

View Full Document Right Arrow Icon
CSE 143 Lecture 7 Stacks and Queues reading: Stuart Reges notes on website
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 1 bottom 2 3 top pop, peek push 3 2 1 back front add remove, peek
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
Background image of page 5

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

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

This note was uploaded on 10/30/2011 for the course COMPUTER S 143 taught by Professor John during the Spring '11 term at Washington State Community College.

Page1 / 19

07-stack-queue - CSE 143 Lecture 7 Stacks and Queues reading Stuart Reges notes on website Runtime Efficiency(13.2 efficiency A measure of the use

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

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