DOC PREVIEW
UMD CMSC 132 - Linear Data Structures

This preview shows page 1-2-24-25 out of 25 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Linear Data StructuresSlide 2Linked ListReference-based ImplementationArray vs. Reference-based Linked ListLinked List – Insert (After Cursor)Slide 7Linked List – Delete (Cursor)Slide 9Doubly Linked ListSlide 11Node Structures for Linked ListsDoubly Linked List – InsertionCircular Linked ListsCircular Linked Lists – ExamplesStackStack ImplementationsStack ApplicationsQueueQueue ImplementationsQueue – ArrayQueue – Circular ArraySlide 23Slide 24Slide 25Linear Data StructuresNelson Padua-PerezChau-Wen TsengDepartment of Computer ScienceUniversity of Maryland, College ParkLinear Data StructuresListsLinked listDoubly linked listCircular listStack QueueCircular queueLinked ListPropertiesElements in linked list are orderedElement has successorState of ListHeadTailCursor (current position)HeadTailCursorReference-based ImplementationNodes contain references to other nodesExampleIssuesEasy to find succeeding elementsStart from head of list for preceding elementsArray vs. Reference-based Linked ListReference-based linked listInsertion / deletion = O(1)Indexing = O(n)Easy to dynamically increase size of listArrayInsertion / deletion = O(n)Indexing = O(1)Compact, uses less spaceEasy to copy, mergeBetter cache localityLinked List – Insert (After Cursor)1. Original list & new element temp2. Modify temp.next  cursor.nextLinked List – Insert (After Cursor)3. Modify cursor.next  temp4. Modify cursor  tempLinked List – Delete (Cursor)1. Find before such that before.next = cursor2. Modify before.next  cursor.nextLinked List – Delete (Cursor)3. Delete cursor4. Modify cursor  before.nextDoubly Linked ListPropertiesElements in linked list are orderedElement has predecessor & successorState of ListHeadTailCursor (current position)HeadTailCursorDoubly Linked ListExampleIssuesEasy to find preceding / succeeding elementsExtra work to maintain links (for insert / delete)More storage per nodeNode Structures for Linked ListsLinked listClass Node {Object data;Node next;}Doubly linked listClass Node {Object data;Node next;Node previous;}Doubly Linked List – InsertionExampleMust update references in both predecessor and successor nodesCircular Linked ListsLast element links to first elementPropertiesCan reach entire list from any nodeNeed special test for end of listRepresentBuffersNaturally circular dataHeadTailCircular Linked Lists – ExamplesCircular linked listCircular doubly linked listStackPropertiesElements removed in opposite order of insertionLast-in, First-out (LIFO)Must track position of Top (last element added)Stack operationsPush = add element (to top)Pop = remove element (from top)Stack ImplementationsLinked listAdd / remove from head of listArrayIncrement / decrement Top pointer after push / popX Y Z … TopStack ApplicationsRun-time procedure informationArithmetic computationsPostfix notationSimplified instruction setJava bytecodeQueuePropertiesElements removed in order of insertionFirst-in, First-out (FIFO)Must track Front (first in) and Back (last in)Queue operationsEnqueue = add element (to back)Dequeue = remove element (from front)Queue ImplementationsLinked listAdd to tail (Back) of listRemove from head (Front) of listArrayCircular arrayQueue – ArrayStore queue as elements in arrayProblemQueue contents move (“inchworm effect”)As result, can not add to back of queue, even though queue is not fullQueue – Circular ArrayCircular array (ring)q[ 0 ] follows q[ MAX – 1 ]Index using q[ i % MAX ]ProblemDetecting difference between empty and nonempty queueQueue – Circular ArrayApproach 1Keep Front at first inKeep Back at last inProblemEmpty queue identical to queue with 1 elementQueue – Circular ArrayApproach 2Keep Front at first inKeep Back at last in – 1ProblemEmpty queue identical to full queueQueue – Circular ArrayInherent problem for queue of size NOnly N possible (Front – Back) pointer locationsN+1 possible queue configurations Queue with 0, 1, … N elementsSolutionsMaintain additional state informationUse state to recognize empty / full queueExamplesRecord SizeRecord QueueEmpty flagLeave empty element in queueStore marker in


View Full Document

UMD CMSC 132 - Linear Data Structures

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Download Linear Data Structures
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Linear Data Structures and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Linear Data Structures 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?