COSC 1P03 Data Structures and Abstraction 5.1 Linear Linked Structures.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Singly linked lists Doubly linked lists
Pointers.
Linked Lists CS-212 Dick Steflik. Linked Lists A sequential collection of information Can be unordered; i.e. in no specific order Can be ordered; may.
Linear Lists – Linked List Representation
Linked Lists Linked Lists Representation Traversing a Linked List
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
CHP-5 LinkedList.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Foundation of Computing Systems Lecture 2 Linked Lists.
Review Learn about linked lists
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Data Structures: A Pseudocode Approach with C
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
1 Chapter 3 Arrays, Linked Lists, and Recursion. 2 Static vs. Dynamic Structures A static data structure has a fixed size This meaning is different than.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Chapter 3: Arrays, Linked Lists, and Recursion
Doubly Linked Lists Deleting from the end of the list – Have to traverse the entire list to stop right in front of tail to delete it, so O(n) – With head.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
Linked Lists. 2 Anatomy of a linked list A linked list consists of: A sequence of nodes abcd  Each node contains a value  and a link (pointer or reference)
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Linked List by Chapter 5 Linked List by
COSC 1P03 Data Structures and Abstraction 5.1 Linear Linked Structures A bank is a place where they lend you an umbrella in fair weather and ask for it.
Chapter 5 Linked Lists. © 2004 Pearson Addison-Wesley. All rights reserved 5 A-2 Preliminaries Options for implementing an ADT –Array Has a fixed size.
1 Linked Lists (Lec 6). 2  Introduction  Singly Linked Lists  Circularly Linked Lists  Doubly Linked Lists  Multiply Linked Lists  Applications.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Recursion ITI 1121 N. El Kadri. Reminders about recursion In your 1 st CS course (or its equivalent), you have seen how to use recursion to solve numerical.
Data Structure & Algorithms
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Given a node v of a doubly linked list, we can easily insert a new node z immediately after v. Specifically, let w the be node following v. We execute.
UNIT-II Topics to be covered Singly linked list Circular linked list
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Lecture 6 of Computer Science II
Data Structure By Amee Trivedi.
Lectures linked lists Chapter 6 of textbook
Lecture - 6 On Data Structures
Linked-list.
Data Structures Interview / VIVA Questions and Answers
CSCE 210 Data Structures and Algorithms
Arrays and Linked Lists
Linked Lists.
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
File Organization.
LINKED LIST Dr. T. Kokilavani Assistant Professor
Linked Lists Chapter 5 (continued)
Presentation transcript:

COSC 1P03 Data Structures and Abstraction 5.1 Linear Linked Structures

COSC 1P03 Data Structures and Abstraction 5.2 Dynamic Structures  collections  limitations of static structures (i.e. arrays)  fixed size  waste space  rearrangement of entries  dynamic data structures  change size over time  storage proportional to amount of information  linked structures  nodes (objects) connected together by references  dynamic allocation/deallocation  in array proximity implicit, in linked structure it is explicit  linear linked structures  aka linked lists

COSC 1P03 Data Structures and Abstraction 5.3 Sequentially-linked Structures  each node indicates its successor (via a reference)  first node located via reference  last node has no successor ( null )  each node represents one entity  empty collection has null reference

COSC 1P03 Data Structures and Abstraction 5.5 Representation  dynamic creation  nodes are objects  let entity objects be nodes?  add reference field  disadvantages  object must “know” it is on list  multiple lists  must modify class

COSC 1P03 Data Structures and Abstraction 5.7 Node Wrapper Class  separate class that references entities  wrapper class, mixin, decorator (GoF)  fields  reference ( p.theStudent )  link ( p.next )  constructor  visibility  class  fields  as sequentially-linked structure  general case  initial (empty) state  multiple lists  different sequence of Node s, same entity objects

COSC 1P03 Data Structures and Abstraction 5.11 Operations  insertion  where?  deletion  which node?  traversal  “visit” all nodes  like array traversal  search  special traversal  simple vs exhaustive

COSC 1P03 Data Structures and Abstraction 5.12 Insertion  insert where?  front  end  in some order (e.g. sorted)  at front  new entry points to previous front  list reference points to new entry  algorithm  O(1)  repeated application  reverse order

COSC 1P03 Data Structures and Abstraction 5.15 Deletion  delete which node?  first  last  matching a key  only if not empty  delete first  move list pointer to second node  garbage collection  node  entity  algorithm  O(1)

COSC 1P03 Data Structures and Abstraction 5.18 Traversal  sequential processing  to get to n th node must first get to (n-1) st node  travelling pointer  start at first node  move to node's successor  p = p.next  termination  no more nodes ( p == null )  algorithm  O(n)  vs array traversal  sequential traversal pattern

COSC 1P03 Data Structures and Abstraction 5.23 Search  sequential structure  sequential search  variant of traversal  two exit conditions  found  not found  algorithm  O(n)

COSC 1P03 Data Structures and Abstraction 5.26 Insertion at End of List  for insertion in order  find end of list  traversal  2 travelling pointers  initial state  q is predecessor of p  insert  algorithm  traverse  updating p & q  insert  2 cases  q == null (empty list)  q != null (at end)  O(n)

COSC 1P03 Data Structures and Abstraction 5.29 Deletion of Last Node  must modify second last node  find second last node  traversal  2 travelling pointers  test  algorithm  pre test  error  traverse  delete  2 cases  q == null (only node)  q != null (last node)  O(n)

COSC 1P03 Data Structures and Abstraction 5.32 Insertion in Sorted Order  insert between 2 nodes  criteria  find insertion point  search  2 travelling pointers  insert between p & q  combination of termination conditions (order)  algorithm  search  first entity with greater key  termination on found or end of list  insert  2 cases  q == null (front of list or empty list)  q != null (after q )  O(n)

COSC 1P03 Data Structures and Abstraction 5.35 Deletion of Node by Key  criterion  match key  find deletion point  search  2 travelling pointers  termination and subsequent test  exception  algorithm  search  delete if found  2 cases  q == null (delete first node)  q != null (delete q ’s successor)  O(n)

COSC 1P03 Data Structures and Abstraction 5.38 Insertion at End with Tail reference  O(n) since must find end  remember where end is then O(1)  pair of pointers ( head, tail )  must be sure to update both appropriately  insertion at end  empty list insertion  deletion at front  last node deletion  performance  extra cost is O(1)  deletion of last in O(1) ?  not possible

COSC 1P03 Data Structures and Abstraction 5.46 Symmetrically-linked Structures  each node points to successor and predecessor  traversal in both directions  arbitrary insertion/deletion  extra work in insertion and deletion (extra pointers)  e.g. sorted insertion  e.g. keyed deletion

COSC 1P03 Data Structures and Abstraction 5.50 Circular Linked Structures  sequentially-linked or symmetrically-linked  last node points back to first  single node  traversal from any point  treating each node as head in turn  potential infinite loop in traversal

COSC 1P03 Data Structures and Abstraction 5.54 Header/Sentinel Nodes  operations at front cause special cases  header node  extra node at front of list  never deleted  doesn’t contain data  empty list  traversal  from successor of header  e.g. insertion in sorted order  e.g. keyed deletion  sentinel node  mark end of list  high key value stops search  cost

COSC 1P03 Data Structures and Abstraction 5.61 Lists-of-lists and Multi-lists  lists whose entries are lists  first nodes differ  SubList wrapper  multi-lists  nodes on multiple lists in a lattice  access in various dimensions  e.g. sparse matrices

COSC 1P03 Data Structures and Abstraction 5.66 Working with Linked Structures  encapsulating algorithms into methods  passing list reference as parameter  parameters are by-value?  return new list pointer as function result  other result?  use header node  creation of header?  use instance variable instead of parameter  multiple lists?  encapsulate as list object  list pointer is instance variable  list object can be passed as parameter  comparison of array and linked representations