5_heaps - Basic Data Structures and Heaps David Kauchak...

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Basic Data Structures and Heaps David Kauchak Sorting demo (http://math.hws.edu/TMCM/java/xSortLab/) Data structures What is a data structure? Way of storing data that facilitates particular operations. Well talk about mostly about operations on a dymanic set: Operations : For a set S Search ( S,x ) - Does x exist in S ? Insert ( S,x ) - Add x to S . Delete ( S,x ) - Given a pointer/reference to an element x , delete it from S Minimum ( S ) - Return the smallest element from S Maximum ( S ) - Return the largest element from S Array Sequential locations in memory in linear order. Element are accessed via their index. Read/write application of particular indices occur in (1) time. In- sert, delete, and most set operations (e.g. Maximum ) occur in ( n ) time. Representation Search- Iterate over elements until element is found - O ( n ) 1 Insert- Create new array of size n+1. Copy elements and insert new element - ( n ) InsertIndex- Insert element and shift over all remaining ele- ments - ( n ) Delete- Delete element and shift down remaining elements - ( n ) Minimum- Search every element for the minimum - ( n ) Maximum- Search every element for the maximum - ( n ) Uses? Double Linked list Objects are arranged linear. An element in the list points to the next and previous element in the list. Deletion of particular element occurs in (1) time. Most other oper- ations occur in ( n ) time. Representation Search- Iterate over elements by following links until element is found - ( n ) Insert- Add element to the beginning of the linked list and update the head - (1) InsertIndex- Iterate over elements until index is found and insert element by updating links - ( n ) Delete- Delete element and update pointers of previous and next element - (1) Minimum- Search every element for the minimum - ( n ) Maximum- Search every element for the maximum - ( n ) Uses? Stack LIFO (last in first out) Picture the stack of plates at a buffet Can be implemented using an array or a linked list....
View Full Document

This document was uploaded on 05/25/2011.

Page1 / 10

5_heaps - Basic Data Structures and Heaps David Kauchak...

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

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