COSC160: Data Structures Linked Lists

Slides:



Advertisements
Similar presentations
M180: Data Structures & Algorithms in Java
Advertisements

ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 2.
Linked lists. Data structures to store a collection of items Data structures to store a collection of items are commonly used Typical operations on such.
1 Linked List. List vs Arrays Two built-in data structures that can be used to organize data, or to create other data structures: Lists Arrays.
Linked Lists Source: presentation based on notes written by R.Kay, A. Hill and C.Noble ● Lists in general ● Lists indexed using pointer arrays ● Singly.
Lecture 6 of Computer Science II
Unit – I Lists.
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Chapter 4 Linked Structures.
Understanding Algorithms and Data Structures
Data Structure By Amee Trivedi.
Linked List :: Basic Concepts
COSC160: Data Structures: Lists and Queues
Algorithms for iSNE Dr. Kenneth Cosh Week 2.
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
CSCI-255 LinkedList.
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
UNIT – I Linked Lists.
Design & Analysis of Algorithm Priority Queue
COMP 53 – Week Eleven Hashtables.
MIS 215 Module 1 – Unordered Lists
CE 221 Data Structures and Algorithms
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lists CS 3358.
Lecture - 6 On Data Structures
COSC160: Data Structures Binary Trees
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Linked List Variations
EEL 4854 IT Data Structures Linked Lists
ENERGY 211 / CME 211 Lecture 12 October 17, 2008.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Review Graph Directed Graph Undirected Graph Sub-Graph
COSC160: Data Structures Linked Lists
CSCE 210 Data Structures and Algorithms
Lists.
Linked List Sudeshna Sarkar.
LINKED LISTS CSCD Linked Lists.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Top Ten Words that Almost Rhyme with “Peas”
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Introduction to Linked Lists
CMSC 341 Lecture 5 Stacks, Queues
Lists.
Topic 11 Linked Lists -Joel Spolsky
Chapter 15 Lists Objectives
Arrays and Linked Lists
COSC160: Data Structures B-Trees
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Linked List Intro CSCE 121 J. Michael Moore.
Further Data Structures
Linked Lists.
Hassan Khosravi / Geoffrey Tien
Linked Lists in C and C++
Linked Lists Chapter 4.
Problem Understanding
Linked List.
Chapter 17: Linked Lists.
Lecture 16 Section 6.2 Thu, Mar 1, 2007
Hank Childs, University of Oregon
Data Structures & Algorithms
Lecture No.02 Data Structures Dr. Sohail Aslam
Chapter 4: Simulation Designs
Linked Lists.
Linked List Intro CSCE 121.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Topic 11 Linked Lists -Joel Spolsky
Problem Understanding
Presentation transcript:

COSC160: Data Structures Linked Lists Jeremy Bolton, PhD Assistant Teaching Professor

Outline Data Structure (lower-level) Implementations Design Decisions Chaining (Linked Lists) Design Decisions and Implications on Complexity Example: Tail Pointer Arrays Design Decisions Arrays vs. Chaining Interesting Applications Polynomial Arithmetic and Evaluation

Linear Structures Linear structures are generally implemented using arrays or chaining Contiguous vs. non-contiguous in memory Static size vs. dynamic size When designing a data structure, one must consider these low-level designs One major decision: contiguous vs non-contiguous (ie array vs chain) This design decision will have implications with respect to usage and efficiency There are many design decisions that a programmer must consider Some are standard, others may be tailor-made for the problem/solution on-hand.

List Class Implemented by Chaining (Linked Lists) Design Decisions Single Link, next Head pointer maintained Standard Operations Insert(item, index) Remove(index) Retrieve(index)

Inserting into a Linked List Lets investigate three cases of the insertion operation Insert to front of list Insert to middle of list Insert to end of list

Inserting into front of a Linked List Insert to front of list Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Time complexity?

Inserting into middle of Linked List Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Time complexity?

Inserting to end of Linked List Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Time complexity?

Design Decisions One major goal of a data structure is to provide an efficient way to manage data. Can we improve the efficiency of any of these operations -- YES Example: Tail pointer Notably decrease order of computation for insert to end of list, at the cost of maintaining an extra pointer per list

Insert to End (List with Tail Pointer) Significant time reduction. What is the time complexity now?

List Variations: Singly Linked vs. Doubly Linked Lists Differences Doubly Linked List Can traverse a list in both directions at added cost of 1 pointer per node Slightly simplify iteration scheme for insertions and removals

Singly Linked vs. Doubly Linked Lists Singly Linked List Doubly Linked List

Why a double link? May be useful in specific situations. Remove last node A prev pointer, may reduce retrieval and insertion times at the cost (space) of 1 extra pointer per node. Create an efficient algorithm: Node* get(int index)

List Class Implemented as Array Assume the following design decisions Array initialized to “large” capacity, chosen appropriately based on application No gaps in the list (items shift after a removal) Assumes index = 0 is beginning of list Should maintain index for end (size) of list or numItems Operations Insert(item, index) Remove(index) Retrieve(index) Concerns: What happens if insertion exceeds capacity?

Inserting into an Array Lets investigate three cases of the insertion operation Insert to front of array Insert to middle of array Insert to end of array

Insertion to Front of Array Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Time complexity?

Insert to Middle of Array Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Time complexity?

Insert to End of Array Approximately how many computational steps? Does the number of computational steps depend on the size of the list? Note: Assumes there is enough allocated space. Time complexity?

“Worst” Case Time Complexity for a List Class IMPLEMENTATION CHAINING ARRAYS INSERT FRONT Θ(1) Θ(𝑛) INSERT MIDDLE INSERT BACK Θ 1 * Θ(1)** RETRIEVE FRONT RETRIEVE MIDDLE RETRIEVE BACK REMOVE FRONT REMOVE MIDDLE REMOVE BACK * Assumes tail ptr ** Assumes alloc Exercise: try to fill out table for best case and average case.

Basic Lists: Array vs Linked List Implementation Example: Design a list class for use to store information for 250 tenants in apt. building. Design an aptList Class with the following operations Insert(item, location): bool Remove(item): bool Find(item): int How would you implement this structure as a class? Array or Chain? Why? What member variables would you include? Why? We could keep the data in the list in some order …