This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Doubling Strategy Analysis
• We replace the array k = log2 n times
• The total time T(n) of a series of n add(o)
operations is proportional to
n + 1 + 2 + 4 + 8 + …+ 2k = n + 2k + 1 1 = 3n 1 geometric series • Thus T(n) is O(n) 2 • The amortized time of an add operation is
O(1)! 1 4
1
8 #
% Recall:
$
CSE 2011
Prof. J. Elder  26  1 " r n +1 &
ri =
!
1" r (
'
i =0
n Last Updated: 120117 9:52 AM Applications of Array Lists
• Maintaining a sorted list when insertions and removals
are relatively rare. CSE 2011
Prof. J. Elder  27  Last Updated: 120117 9:52 AM Stacks
Chapter 5.1 CSE 2011
Prof. J. Elder  28  Last Updated: 120117 9:52 AM The Stack ADT
• The Stack ADT stores
arbitrary objects • Auxiliary stack
operations: • Insertions and deletions
follow the lastin firstout
scheme – object top(): returns the
last inserted element
without removing it • Think of a springloaded
plate or Pez dispenser – integer size(): returns the
number of elements
stored • Main stack operations: – boolean isEmpty():
indicates whether no
elements are stored – push(object): inserts an
element
– object pop(): removes and
returns the last inserted
element
CSE 2011
Prof. J. Elder  29  Last Updated: 120117 9:52 AM Stack Interface in Java • Example java
interface public interface Stack {
public int size();
public boolean isEmpty();
public Object top()
throws EmptyStackException;
public void push(Object o);
public Object pop()
throws EmptyStackException;
} CSE 2011
Prof. J. Elder  30  Last Updated: 120117 9:52 AM ...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures

Click to edit the document details