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.

Slides:



Advertisements
Similar presentations
Stacks using Linked Lists. Stack Data Structure As we already know, stacks are linear data structures. This means that their contexts are stored in what.
Advertisements

Chapter 24 Lists, Stacks, and Queues
CS252: Systems Programming Ninghui Li Program Interview Questions.
Data Structures and Algorithms (60-254)
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
Sorting (2nd part) & Binary Search Tree
Tutorial 6 Recursion. Sierpinski Triangle Recursive Tree Koch Snowflake Beautiful Recursion: Fractal.
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.
COMP 110 Introduction to Programming Mr. Joshua Stough.
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.
Stacks, Queues, and Deques
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
Tutorial 5 Linked List Variations, Stack, & Queue.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Tutorial 7 Sorting & Complexity Analysis (Almost) always asked in exam! e.g. a. Derive algorithm for this problem! b. What is the time complexity of your.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
Tutorial 5 Stack & Queue, Midtest. Last In First Out (LIFO) Stack implemented using Array with top pointer –
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
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.
A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
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.
Tutorial 10 Heap & Priority Queue. Heap – What is it? Special complete binary tree data structure –Complete BT: no empty node when checked top-down (level.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
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.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
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.
Linked List by Chapter 5 Linked List by
Chapter 15 Linked Data Structures Slides prepared by Rose Williams, Binghamton University Kenrick Mock University of Alaska Anchorage Copyright © 2008.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
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.
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.
April 27, 2017 COSC Data Structures I Review & Final Exam
Linear Data Structures
Breadth-first and depth-first traversal Prof. Noah Snavely CS1114
C++ Review STL CONTAINERS.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
Week 4 - Wednesday.  What did we talk about last time?  Started linked lists.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
CISC220 Spring 2010 James Atlas Lecture 10: Queues.
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Stack, Queues, and Priority Queues: Linked List Based
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Week 4 - Monday CS221.
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 15 Lists Objectives
structures and their relationships." - Linus Torvalds
Principles of Computing – UFCFA3-30-1
Stacks, Queues, and Deques
Stacks, Queues, and Deques
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Data Structures and Algorithms for Information Processing
Queues Model Operations Pointer Implementations Array Implementation
Stacks, Queues, and Deques
structures and their relationships." - Linus Torvalds
Presentation transcript:

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 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 (  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. –Good for Round Robin stuffs Generic LinkedList (slide 61-66) for a “bug-free”, “ready-to-use” LL Done Last Week…

Student Presentation T3 1.Koh Xianghua, Nicholas 2.N/A 3.Sean Lim Wei Xinq T4 1.Tan Miang Yeow (Done Last Week) 2.N/A 3.Chua Kien Chuan Chris T5 1.N/A 2.N/A 3.N/A T6 1.Kuganeswari D/O Kuhanesan 2.Chow Jian Ann 3.Chow Jian Ann 3 This week marks the end of this bidding system… Some students have not participate at all!

Question 1 (MovieDataAnalysis) Insert New Item (Movie ADT) to LinkedList –Ensure that you check for duplicate data! 4

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! 6 Person A’s preference:Person B’s preference:

Tutorial 5 Preview

Stack: Last In First Out (LIFO) Stack Implemented using Array with top pointer – Best Implementation? –Using Single Link List with head pointer, demo: – Stack

Queue First In First Out (FIFO) Queue implemented as Circular Array – Queue implemented as Single Link List with Tail Pointer –Head pointer for dequeue –Tail pointer for enqueue –We reverse their role because of the pointer directions Best Implementation? –Use Circular Single Link List –Save one more pointer as head = tail.next…

Student Presentation T3MainBackup 1.Cai JingfangChng Jiajie 2.Li HuanNur Liyana Bte Roslie 3.Zhang JianfeiTan Kar Ann 4.Tanvir IslamJessica Chin Zet Sze T4MainBackup 1.Choy Qian Ning, JLiew Hui Sun 2.Goh Khoon HiangLi Yawen 3.Hanyenkno AfiTan Peck Luan 4.Ng Xue Lin SherilynWong Suet Teng, Melissa T5MainBackup 1.Joyeeta BiswasOng Kian An 2.Teo Sim Yee StephanieTan Yan Hao 3.Wu ShujunWang Ruohan 4.Liu NaZheng Yang T6MainBackup 1.Zhang ChaoWang Shuling 2.Chua Yu Tong LauraRasheilla Bte Rajah 3.Koh Yi Ting BrendaLow Wei Chen Gerard J 4.SiddharthaGan Zhi Wei James 10 Since some students still have not tried at all Therefore, I have to assign 4 random students to do tutorial 5 (Please just treat this as mid-test preparation, you have 1 week recess!)

Question 1 (Applications) Show us 7 applications of Stacks Show us 7 applications of Queues 11

Question 2 (Stack: Reorder) Algorithm to reorder items using one stack! Requires thinking on Stack operations: push, pop, top/seek Hint: Try the sample input-output manually! Derive patterns and write your algorithm! 12

Question 3 (Stack for Sorting) Find algorithm to sort items using two stacks! Requires thinking on Stack operations: push, pop, top/seek Hint: try sorting these simple numbers using two stacks: –{7, 5}  {5, 7} –{1, 5, 3}  {1, 3, 5} –{4, 3, 2, 1}  {1, 2, 3, 4} Derive patterns and write your algorithm! 13

Question 4 (Queue) What if Queue ADT is implemented using TailedLinkedList but in different way! Think about the pros and cons of this strategy! 14

Next Week (Recess) Use your recess week carefully! –CS1102 midterm test is just RecessWeek.getNext()! –For those who are assigned to do Tutorial 5, you have 1 week buffer! –Recess != holiday!! However >.< –I will be taking my holiday leave… –Going back to Jakarta Sep 08 –You can me but my response will be slower…