DataStructures2 - Irregular Data Structures Linked lists,...

Info iconThis preview shows pages 1–17. 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

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

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

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: Irregular Data Structures Linked lists, trees, and graphs 1 Popescu 2012 Motivation Irregular data structures needed to overcome disadvantages of arrays Easy expansion and contraction to keep up with dynamic data size Modeling of irregular data, with complex neighboring relationship 2 Cost Irregular data structures Increased complexity Decreased efficiency Structure stored explicitly, not all storage used to store data No direct access to all data 3 Linked list A 1-D sequence data structure Not an array Each data element is linked to the next Link: memory address pointing to a data element Link list node: data element + link Example credit card transaction amounts in dollars, sorted Links stored explicitly E.g. 32 bit / link Actual address irrelevant here Link shown with arrow Link to first element has to be known (shown in red) Link of last element is null 4 13.40 12.50 7.45 2.50 Linked list Add a new transaction in the amount of $8.12 Start at first node (using known red arrow link) Is amount (13.40) smaller than $8.12? No, use node link to go to next node Is amount (12.50) smaller than $8.12? No, use node link to go to next node Is amount (7.45) smaller than $8.12? 5 13.40 12.50 7.45 2.50 Linked list Add a new transaction in the amount of $8.12 Yes, insert new node Make new node Set new node amount to $8.12 6 13.40 12.50 7.45 2.50 8.12 Linked list Add a new transaction in the amount of $8.12 Yes, insert new node Make new node Set new node amount to $8.12 Set new node link to next node 7 13.40 12.50 7.45 2.50 8.12 Linked list Add a new transaction in the amount of $8.12 Yes, insert new node Make new node Set new node amount to $8.12 Set new node link to next node Set previous node link to new node 8 13.40 12.50 7.45 2.50 8.12 Linked list Add a new transaction in the amount of $8.12 9 13.40 12.50 7.45 2.50 8.12 Linked list Delete transaction $12.50 Move to node storing $12.50 transaction 10 13.40 12.50 7.45 2.50 8.12 Linked list Delete transaction $12.50 Move to node storing $12.50 transaction Set link of previous node to next node 11 13.40 12.50 7.45 2.50 8.12 Linked list Delete transaction $12.50 Move to node storing $12.50 transaction Set link of previous node to next node Delete current node 12 13.40 7.45 2.50 8.12 Linked list Delete transaction $12.50 13 13.40 7.45 2.50 8.12 Linked list Delete transaction $13.40 Special case Set red link equal to link of first node Delete first node 14 13.40 7.45 2.50 8.12 Linked list Delete transaction $13.40 Special case Set red link equal to link of first node Delete first node 15 7.45 2.50 8.12 Linked list Advantages List grows and shrinks as needed, w/o having to modify entire list Insertion & deletion imply local changes Disadvantages...
View Full Document

This note was uploaded on 02/27/2012 for the course CS 177 taught by Professor Staff during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 54

DataStructures2 - Irregular Data Structures Linked lists,...

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

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