Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Linear Data Structures - Object-Oriented Programming II | CMSC 132, Study notes of Computer Science

Material Type: Notes; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-y9a
koofers-user-y9a 🇺🇸

10 documents

1 / 32

Toggle sidebar

Related documents


Partial preview of the text

Download Linear Data Structures - Object-Oriented Programming II | CMSC 132 and more Study notes Computer Science in PDF only on Docsity! CMSC 132: Object-Oriented Programming II Linear Data Structures Department of Computer Science University of Maryland, College Park Overview Linear data structures General properties Implementations Array Linked list Restricted abstractions Stack Queue Add & Remove Elements Add an element Where? At head (front) of list At tail (end) of list After a particular element Remove an element Remove first element Remove last element Remove a particular element (e.g., String “Happy”) What if “Happy” occurs more than once in list? Accessing Elements How do you find an element? At head (front) of list At tail (end) of list By position Example: the 5th element By iterating through the list, and using relative position Next element (successor) Previous element (predecessor) List Implementations Two basic implementation techniques for lists Store elements in an array Store as a linked list Place each element in a separate object (node) Node contains reference to other node(s) Link nodes together Linked Implementation Advantages Can efficiently insert / remove elements anywhere Disadvantages Cannot efficiently access element at any position Need to traverse list to find element Less efficient use of space 1-2 additional references per element Efficiency of Operations Array Insertion / deletion = O(n) Indexing = O(1) Linked list Insertion / deletion = O(1) Indexing = O(n) Linked List – Insert (After Cursor) 1. Original list & new element temp 2. Modify temp.next → cursor.next Linked List – Delete (Cursor) 3. Delete cursor 4. Modify cursor → before.next Doubly Linked List Linked list where Element has predecessor & successor Issues Easy to find preceding / succeeding elements Extra work to maintain links (for insert / delete) More storage per node Doubly Linked List – Insertion Example Must update references in both predecessor and successor nodes Stack Stack operations Push = add element (to top) Pop = remove element (from top) Example Stack Properties Elements removed in opposite order of insertion Last-in, First-out (LIFO) A restricted list where Access only to elements at one end Can add / remove elements only at one end Stack Applications Run-time procedure information Arithmetic computations Postfix notation Simplified instruction set Java bytecode Queue Properties Elements removed in order of insertion First-in, First-out (FIFO) A restricted list where Access only to elements at beginning / end of list Add elements only to beginning of list Remove elements only from end of list Queue Applications Examples Songs to be played Jobs to be printed Customers to be served Citizens to cast votes South Africa, 2004 Queue Implementations Linked list Add to tail (back) of list Remove from head (front) of list Array Circular array Queue – Circular Array Approach 1 Keep Front at first in Keep Back at last in Problem Empty queue identical to queue with 1 element Queue – Circular Array Approach 2 Keep Front at first in Keep Back at last in – 1 Problem Empty queue identical to full queue Queue – Circular Array Inherent problem for queue of size N Only N possible (Front – Back) pointer locations N+1 possible queue configurations Queue with 0, 1, … N elements Solutions Maintain additional state information Use state to recognize empty / full queue Examples Record Size Record QueueEmpty flag Leave empty element in queue Store marker in queue
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved