Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.

Slides:



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

1 Linked Lists Continued Lecture 5 Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists ADS2 Lecture 5.
Singly linked lists Doubly linked lists
Lecture 15 Linked Lists part 2
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Arrays: pluses and minuses + Fast element access. -- Impossible to resize.
Stacks, Queues, and Linked Lists
DATA STRUCTURES USING C++ Chapter 5
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
Ceng-112 Data Structures I Chapter 5 Queues.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Elementary Data Structures CS 110: Data Structures and Algorithms First Semester,
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Linked Lists1 Part-B3 Linked Lists. Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data structure consisting of a sequence.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
Chapter 3: Arrays, Linked Lists, and Recursion
CSC 212 – Data Structures Lecture 13: Linked Lists.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
CS212D : DATA STRUCTURES 1 Week 5-6 Linked List. Outline 2  Singly Linked Lists  Doubly Linked Lists  Recursions.
Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile,
English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural.
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Self-Referential Classes A Self-referential class is a class that contains a reference to an object that has the same class type. –A self-referential class.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Lecture5: Linked Lists Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Chapter 5 Linked Lists II
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
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.
Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile,
List Interface and Linked List Mrs. Furman March 25, 2010.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
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.
Arrays Chapter 6. Objectives learn about arrays and how to use them in Java programs learn how to use array parameters and how to define methods that.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
Week 13 - Wednesday.  What did we talk about last time?  NP-completeness.
Data Structure & Algorithms
CSCS-200 Data Structure and Algorithms Lecture
CSE 501N Fall ‘09 10: Introduction to Collections and Linked Lists 29 September 2009 Nick Leidenfrost.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Lecture 6 of Computer Science II
Computer Engineering Department Islamic University of Gaza
Linked lists.
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
Lecture 23: Doubly Linked List
LINKED LISTS CSCD Linked Lists.
Data Structures ADT List
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
Chapter 16 Linked Structures
Linked Lists.
Data Structures & Algorithms
Intro to OOP with Java, C. Thomas Wu By : Zanariah Idrus
Linked lists.
Linked Lists Chapter 5 (continued)
Presentation transcript:

Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR

Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR  Key  Key completes the first word (donkey) and a key starts a car

 Computers best processing huge data sets  Perform specific tasks and output results: Analyze what items often bought together Print & mail tuition bills Compute receipt for groceries  Filter & provide few items for user to choose from Personalized recommendations from Amazon Google’s list of matching web pages Systems to determine stock to be reordered  Most of year examines how to organize data  Space and time issues must be evaluated as factor Computers Use Collections

 Already know simple way to organize data: array  Primitives or references can be stored in entries  Create matrices with entries referring to another array  Arrays of generic type can limit code rewriting public class ScoreLog { private int count; private T[] s; public ScoreLog(){ s = (T[]) new Object[100]; } public void addScore(T newScore) { s[count] = newScore; count += 1; } public T getLastScore() { return s[count - 1]; } // More code goes here, but I’m out of space! How Could We Do This?

Why Not Arrays?  Many limitations arise when using arrays  Must specify unchangeable size when created Pirate[] rum = new Pirate[1]; Pirate[] h2o = new Pirate[ variable ]; rum = new Pirate[60]; // old rum was lost! h2o = rum; // h20 now alias to rum’s instance  Waste memory requiring maximum size for array // Each Amazon.com customer uses 400+MB of RAM! Rating[] hertz = new Rating[ ];

 Provide simple way of storing & accessing data  When needed, moving data around is difficult  Cannot resize an array without copying entire thing  If array allocated too small, then program crashes  Waste memory if too large an array is allocated  But access times are really, really fast Arrays

 Provide simple way of storing & accessing data  When needed, moving data around is difficult  Cannot resize an array without copying entire thing  If array allocated too small, then program crashes  Waste memory if too large an array is allocated  But access times are really, really fast Arrays

When Memory Is Too Large

 Linked lists adjust size to reflect current needs  Implementation that avoids array’s sizing problems  First recursive structure you will use this year  There exist many linked list implementations  Best depends on situation and how it will be used  Each approach has own strengths & weaknesses Better Option

 Linked lists adjust size to reflect current needs  Implementation that avoids array’s sizing problems  First recursive structure you will use this year  There exist many linked list implementations  Best depends on situation and how it will be used  Each approach has own strengths & weaknesses best determined by situation  Recurring refrain: best determined by situation  Understanding each implementation very important Better Option

 Linked lists are linear sequence of nodes  “Thingy” is definition of “Node”  Each Node contains:  Element reference to data stored in Node  Link to next Node in linked list Singly Linked List elem Node node

 Linked lists are linear sequence of nodes  “Thingy” is definition of “Node”  Each Node contains:  Element reference to data stored in Node  Link to next Node in linked list Singly Linked List

public class Node { private T elem; private Node next; public Node(T e, Node n) { elem = e; next = n; } public T getElement() { return elem; } public Node getNext() { return next; } public void setElement(T newE) { elem = newE; } public void setNext(Node newNext) { next = newNext; } } 1 st Node Class (of many)

public class SList { private Node head; private int size; public SList() { head = null; // Make an empty list size = 0; } public boolean isEmpty() { return (head == null); } public T getFirstElement() { // Handle situation when list is empty return head.getElem(); } } Singly Linked List

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head elem

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head elem n

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head elem n

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head elem n

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head elem n

Inserting at Head Algorithm addFirst( elem ) Node n = new Node (); n.setElement( elem ); n.setNext( head ); head = n head

Removing an Internal Node  Linked list's length equals number of elements  Requires unlinking Node from the linked list  Nothing fancy needed, just adjust previous next link  Node 0nly existed via links, so this does all we need

Removing an Internal Node  Linked list's length equals number of elements  Requires unlinking Node from the linked list  Nothing fancy needed, just adjust previous next link  Node 0nly existed via links, so this does all we need head

Removing an Internal Node  Linked list's length equals number of elements  Requires unlinking Node from the linked list  Nothing fancy needed, just adjust previous next link  Node 0nly existed via links, so this does all we need head

Removing an Internal Node  Linked list's length equals number of elements  Requires unlinking Node from the linked list  Nothing fancy needed, just adjust previous next link  Node 0nly existed via links, so this does all we need head

Removing an Internal Node  Linked list's length equals number of elements  Requires unlinking Node from the linked list  Nothing fancy needed, just adjust previous next link  Node 0nly existed via links, so this does all we need head

Removing the Head

 Resized with each addition or removal  Linked list's head node has nothing to unlink  No previous node whose next field to be updated  Instead, just need to advance where head refers head = head.next; head

Removing the Head  Resized with each addition or removal  Linked list's head node has nothing to unlink  No previous node whose next field to be updated  Instead, just need to advance where head refers head = head.next; head

Removing the Head  Resized with each addition or removal  Linked list's head node has nothing to unlink  No previous node whose next field to be updated  Instead, just need to advance where head refers head = head.next; head

Removing the Head  Resized with each addition or removal  Linked list's head node has nothing to unlink  No previous node whose next field to be updated  Instead, just need to advance where head refers head = head.next; head

Your Turn  Get into your groups and complete activity head

For Next Lecture  Read GT3.3 – 3.4 for Wednesday  How to insert an element into the middle of list?  Item in the middle of list can be accessed, how?  Are we limited to singly-linked lists?  Angel also has programming assignment #1  Pulls everything together and shows off your stuff