Tutorial 3 - Linked List. Linked List: Revision The concept of ADT List ADT List using Array –Pro & cons  Discussed in T02Q3 and today in Q1! ADT List.

Slides:



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

Lists CS 3358.
Stacks, Queues, and Linked Lists
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
Chapter 24 Lists, Stacks, and Queues
Data Structure Lecture-5
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Sorting (2nd part) & Binary Search Tree
Tutorial 6 Recursion. Sierpinski Triangle Recursive Tree Koch Snowflake Beautiful Recursion: Fractal.
More on Dynamic Memory Allocation Seokhee Jeon Department of Computer Engineering Kyung Hee University 1 Illustrations, examples, and text in the lecture.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Comparison summary Array based (dynamic) Keeps place for up to 4N elements Each element takes 1 memory places Fast accession time Slow removals and insertion.
Data Structures Data Structures Topic #5. Today’s Agenda Other types of linked lists –discuss algorithms to manage circular and doubly linked lists –should.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
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.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
Variations of Linked Lists CS 308 – Data Structures.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Tutorial 5 Linked List Variations, Stack, & Queue.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Tutorial 5 Stack & Queue, Midtest. Last In First Out (LIFO) Stack implemented using Array with top pointer –
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Tutorial 4 Linked List, Stack, & Queue. Linked List: Revision The concept of ADT List ADT List using Array –Pro & cons  Discussed in T02Q3 and today.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 18 Linked Lists, Stacks, Queues, and Priority Queues.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Tutorial 4 – List ADT. List ADT List: –A collection of homogeneous items ordered in linear fashion, e.g. List of names, phone numbers, integers, etc List.
Today’s Agenda  Linked Lists  Double ended Linked Lists  Doubly Linked Lists CS2336: Computer Science II.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
Implementing an ADT Having the JCFs is great – most of the significant data structures are already available But you still may need to implement your own.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Linked List by Chapter 5 Linked List by
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
Queues. Like Stacks, Queues are a special type of List for storing collections of entities. Stacks are Lists where insertions (pushes) and deletions (pops)
CSC 212 Sequences & Iterators. Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
April 27, 2017 COSC Data Structures I Review & Final Exam
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
Week 4 - Wednesday.  What did we talk about last time?  Started linked lists.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
1 CS 132 Spring 2008 Chapter 5 Linked Lists p
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
LINKED LISTS.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
Unit – I Lists.
Week 4 - Monday CS221.
Data structures and algorithms
Doubly Linked List Review - We are writing this code
Linked List Variations
Linked node problem 3 What set of statements turns this picture:
Dynamic Data Structures and Generics
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Dynamic Data Structures and Generics
Programming II (CS300) Chapter 07: Linked Lists
Presentation transcript:

Tutorial 3 - Linked List

Linked List: Revision The concept of ADT List ADT List using Array –Pro & cons  Discussed in T02Q3 and today in Q1! ADT List using Linked List –Basic idea: Slide 17 Linked List Node has 2 parts: –Item/Value/Content  See T03Sup1&2 –Pointers to immediate neighbors Single Linked List –The basic; traversal: head to tail –Usually: insert from head (ok for Stack) –In your lecture notes: BasicLinkList (Slide 26-28), ExtendedLinkedList (Slide 29-36) Generic Java (Slide 37-46) for our custom Basic and Extended LinkedList Linked List Variations: Linked List with Tail Pointer –Can visit the tail very fast –Cannot delete the tail easily…  –In lecture notes (Slide 48-53): TailedLinkedList (revisited in Queue data structure later) Bidirectional Linked List –Two pointers: forward/backward –Can go backwards, Can delete tail! –Extra pointer is overhead  –In lecture notes (Slide 54-58): DoublyLinkedList Circular Linked List –Remember Tail only, Head = Tail.Next –Can visit all node from any node. Generic LinkedList (slide 61-66) for a “bug-free”, “ready-to-use” LL Reserved for next week…

Student Presentation T3 Sup1.Ng Hong Geh Sup2.N/A 1.Koh Xianghua, Nicholas (deferred until next week) 2.N/A 3.N/A 4.Seo Jia Wei David T4 Sup1.Chong Tze Koi Sup2.Chong Tze Koi 1.Tan Miang Yeow 2.N/A 3.N/A 4.N/A T5 Sup1.Wang Ruohan Sup2.Zhang Denan, Zhang Yang 1.N/A 2.N/A 3.N/A 4.N/A T6 Sup1.N/A Sup2.N/A 1.Kuganeswari D/O Kuhanesan (deferred until next week) 2.N/A 3.N/A 4.Koh Jye Yiing 3 Hm… not that good… Anyone wants to take Sup1 & Sup2 questions?

Question Supplementary 1 ListNode First = new ListNode(“first”); ListNode Last = First; ListNode Temp; for (int j = 1; j < 6; j++) if (j % 2 == 0) { Temp = new ListNode(“j = “ + j); Last.next = Temp; Last = Temp; } else First = new ListNode(“j = “ + j, First); Trace this!

Question Supplementary 2 Now, rearrange: J=5  J=3  J=1  first  J=2  J=4 into first  J=1  J=2  J=3  J=4  J=5

Question 1 (MovieDataAnalysis) (Prologue) Array Based ADT (Lect 3, Slide 6-15) –Pros? –Cons? Real question: Insert New Item (Movie ADT) to LinkedList –Ensure that you check for duplicate data! 6

Question 2 (MovieDataAnalysis) Given time period (yearA – yearB) –Get movies that are produced within that range. Methods –1: Scan and select the appropriate movies –2: Copy the list and delete movies that are out of range What if we use Doubly Linked List? Pro and Cons?

Question 3 (MovieDataAnalysis) Given two TopList containing movies, perform: –Intersection –Union –Difference Remember that A-B is not the same as B-A! 8 Person A’s preference:Person B’s preference:

Question 4 (Guess Output) ExtendedLinkedList list = new ExtendedLinkedList(); list.addHead(“ZZZ”); list.addHead(“YYY”); list.addHead(“XXX”); list.addHead(“WWW”); list.addHead(“VVV”); A: ListNode node = list.getHeadPtr(); printList(node); –VVV, WWW, XXX, YYY, ZZZ B: System.out.println(node.next.next.next); –YYY C: node = node.next(), printList(node); –WWW, XXX, YYY, ZZZ D: node = list.getHeadPtr(); list.deleteAfter(node); printList(node); –VVV, XXX, YYY, ZZZ E: ListNode fNode = new ListNode(“FFF”, node); node.next = fNode; printList(node); –VVV, FFF, VVV, FFF, … (infinite) 9

Next Week Revisit the leftover materials from today’s tutorial Revise stack/queue ThisWeek.Next.Next is recess week –Use your recess week carefully! –CS1102 midterm test is just one week after it!