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

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 132:
Object-Oriented Programming II
Linear Data Structures
Department of Computer Science
University of Maryland, College Park
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

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

Linear Data Structures

Terminology

Head (first element in list)

no predecessor Tail (last element in list)

no successor

Operations

Add element Remove element Find element

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?

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 List

Properties

Elements in linked list are ordered Element has successor

State of List

Head Tail Cursor (current position) HeadTail Cursor

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(

Linked list

Insertion / deletion = O(

Indexing = O( n

Linked List – Insert (After Cursor)

Modify

cursor

.next

temp

Modify

cursor

temp

Linked List – Delete (Cursor)

Find

before

such that

before

.next

= cursor

Modify

before

.next

cursor

.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

Restricted Abstractions

Restricting the operations an abstractionsupports can be a good thing

Efficiently supporting only a few operationsefficiently is easier If limited abstraction is sufficient, easier to reasonabout limited abstraction than a more general one

Restricted list abstractions

Stack (aka LIFO queue) Queue (aka FIFO queue) Dequeue (aka double ended queue)

Stack

Stack operations

Push = add element (to top) Pop = remove element (from top)

Example