Linked Lists (continued). Maintaining Order Creating an ordered list 3 Baltimore head Rome Seattle Toronto  (1) Insert node containing (reference to.

Slides:



Advertisements
Similar presentations
1 Linked Lists Continued Lecture 5 Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists ADS2 Lecture 5.
Advertisements

Singly linked lists Doubly linked lists
Linked Lists.
PRESENTED BY MATTHEW GRAF AND LEE MIROWITZ Linked Lists.
Data Structure Lecture-5
Bubble Sort Algorithm 1.Initialize the size of the list to be sorted to be the actual size of the list. 2.Loop through the list until no element needs.
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Review Learn about linked lists
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
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.
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
Chapter 4 Linked Lists Anshuman Razdan Div of Computing Studies
Chapter 3: Arrays, Linked Lists, and Recursion
Grade 12 Computer Studies HG
1 Linked Lists (continued (continued)) Lecture 5 (maybe) Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists Append/Circular.
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.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
Data Structures Using Java1 Chapter 4 Linked Lists.
CSC 213 – Large Scale Programming Lecture 15: Heap-based Priority Queue.
1 Data Structures. 2 Motivating Quotation “Every program depends on algorithms and data structures, but few programs depend on the invention of brand.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
Linked List by Chapter 5 Linked List by
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Linked Lists Chapter 4. Linked Structures: Motivations Arrays have fixed size –Problematic for data structures of arbitrary size Arrays order items physically.
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
1ADS Lecture 11 Stacks contd.. ADS Lecture 113 Singly Linked list-based Stack Top of stack is head of list (can insert elements at head in constant.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Linear Data Structures
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
CS-2852 Data Structures LECTURE 5 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
CS 46B: Introduction to Data Structures July 23 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Data Structure & Algorithms
CSCS-200 Data Structure and Algorithms Lecture
Single Linked Lists Objectives In this lesson, you will learn to: *Define single linked list *Identify the following types of linked lists: Single linked.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
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.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
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.
Understanding General Software Development Lesson 3.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
LINKED LISTS.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Lecture 6 of Computer Science II
Sequences 6/18/2018 8:51 PM C201: Linked List.
Doubly Linked List Review - We are writing this code
Linked lists.
Linked Lists head One downside of arrays is that they have a fixed size. To solve this problem of fixed size, we’ll relax the constraint that the.
Sequences 9/18/ :20 PM C201: Linked List.
Chapter 20: Binary Trees.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Chapter 21: Binary Trees.
More Linked Lists and Loops Based on slides by Ethan Apter
Chapter 16 Linked Structures
Linked Lists.
Linked lists.
Linked Lists Chapter 5 (continued)
Presentation transcript:

Linked Lists (continued)

Maintaining Order

Creating an ordered list 3 Baltimore head Rome Seattle Toronto  (1) Insert node containing (reference to ) the string “Paris” Starting from head proceed until reach a node with string > ”Paris”. Then insert node containing “Paris” before this node. Need to insert node containing “Paris” between nodes containing “Baltimore” and “Rome” ADS2 Lecture 4

Creating an ordered list contd. 4 Baltimore head Rome Seattle Toronto  Paris Create node containing string “Paris” pointing to the “Rome” node. Baltimore head RomeSeattleToronto  Paris Make node “Baltimore” node point to “Paris” node. As we progress along the list, Need to keep a record of the previous node visited. ADS2 Lecture 4

5 (2) Go back to the original list. Insert node containing (reference to ) the string “Aberdeen” Starting from head proceed until reach a node with string>”Aberdeen”. Then insert node containing “Aberdeen” before this node. Need to insert node containing “Aberdeen” at the head of the list. No “previous node” in this case. Add to head as before. Creating an ordered list contd. (3) Go back to the original list. Insert node containing (reference to ) the string “Verona” Starting from head proceed until reach a node with string>”Verona”. But this doesn’t happen – we reach null. We can add to the end of the list without needing a “last” instance variable (see Lecture 3) as we are keeping copy of “previous node”. Baltimore head Rome Seattle Toronto  ADS2 Lecture 4

6 Baltimore head Rome Seattle Toronto  Verona Allocate new node containing “Verona”, pointing to null Creating an ordered list contd. Make previous node point to “Verona” node Baltimore head Rome Seattle Toronto  Verona So in general to insert a node containing string myString, starting from head proceed until reach null or a node with string>myString. Remember: Do not try to check the contents of a node if it is null. ADS2 Lecture 4

Creating an ordered list contd.

What do you think of this as a way of documenting code?

Know that we have order, how can isPresent exploit it?

Check it out

remove/delete

Removing all nodes containing a given value Baltimore head Rome Seattle Toronto  To remove all nodes containing string “Rome”: Start at head and proceed along list. If a node temp contains the String “Rome” - Redirect prev to point to the node pointed to by temp continue

pattern/template

Found what we are looking for?

The actual removal of a node

Removing head of list

The actual removal of a node Removing an arbitrary node

… otherwise, move on

… advance the cursor

dog cat owl doghen dog head s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

dog cat owl doghen dog head cursor prev s = “dog”

Know that we have order, how can isPresent exploit it? Below, linear search on a sorted array of strings. Note early stopping condition. Can we incorporate this into isPresent above for linked lists?