Linear Data Structures 1.6

Linear Data - Doubling Strategy Analysis •  We replace the array k = log2 n times •  The total time T(n of a series of n add(o operations

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the 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: 12-01-17 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: 12-01-17 9:52 AM Stacks Chapter 5.1 CSE 2011 Prof. J. Elder - 28 - Last Updated: 12-01-17 9:52 AM The Stack ADT •  The Stack ADT stores arbitrary objects •  Auxiliary stack operations: •  Insertions and deletions follow the last-in first-out scheme –  object top(): returns the last inserted element without removing it •  Think of a spring-loaded 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: 12-01-17 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: 12-01-17 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.

Page1 / 5

Linear Data - Doubling Strategy Analysis •  We replace the array k = log2 n times •  The total time T(n of a series of n add(o operations

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

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