slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Tutorial 4 Linked List, Stack, & Queue PowerPoint Presentation
Download Presentation
Tutorial 4 Linked List, Stack, & Queue

Loading in 2 Seconds...

play fullscreen
1 / 15

Tutorial 4 Linked List, Stack, & Queue - PowerPoint PPT Presentation


  • 476 Views
  • Uploaded on

Tutorial 4 Linked List, Stack, & Queue. Linked List: Revision. Done Last Week…. 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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Tutorial 4 Linked List, Stack, & Queue' - bastien


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
linked list revision
Linked List: Revision

Done Last Week…

  • The concept of ADT List
  • ADT List using Array
    • Pro & cons  Discussed in T02Q3and 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<E> (slide 61-66) for a “bug-free”, “ready-to-use” LL 
student presentation
Student Presentation
  • T3
    • KohXianghua, Nicholas
    • N/A
    • Sean Lim Wei Xinq
  • T4
    • Tan MiangYeow (Done Last Week)
    • N/A
    • Chua Kien Chuan Chris
  • T5
    • N/A
    • N/A
    • N/A
  • T6
    • Kuganeswari D/O Kuhanesan
    • Chow Jian Ann
    • Chow Jian Ann

This week marks the end of this bidding system…

Some students have not participate at all!

question 1 moviedataanalysis
Question 1 (MovieDataAnalysis)
  • Insert New Item (Movie ADT) to LinkedList
    • Ensure that you check for duplicate data!
question 2 moviedataanalysis
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?

2008 2007 2007 2008 2006

question 3 moviedataanalysis
Question 3 (MovieDataAnalysis)
  • Given two TopList containing movies, perform:
    • Intersection
    • Union
    • Difference
      • Remember that A-B is not the same as B-A!

Person A’s preference:

Person B’s preference:

stack
Stack
  • Stack: Last In First Out (LIFO)
  • Stack Implemented using Array with top pointer
    • http://www2.latech.edu/~box/ds/Stack/Stack.html
  • Best Implementation?
    • Using Single Link List with head pointer, demo:
    • http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/LinkListAppl.html
queue
Queue
  • First In First Out (FIFO)
  • Queue implemented as Circular Array
    • http://maven.smith.edu/~streinu/Teaching/Courses/112/Applets/Queue/myApplet.html
  • Queue implemented as Single Link List with Tail Pointer
    • Head pointer for dequeue
    • Tail pointer for enqueue
    • We reverse their rolebecause of the pointer directions
  • Best Implementation?
    • Use Circular Single Link List
    • Save one more pointer as head = tail.next…
student presentation1
Student Presentation
  • T3 Main Backup
    • CaiJingfangChngJiajie
    • Li HuanNurLiyanaBteRoslie
    • Zhang Jianfei Tan Kar Ann
    • Tanvir Islam Jessica Chin ZetSze
  • T4 Main Backup
    • Choy QianNing, J LiewHui Sun
    • GohKhoonHiang Li Yawen
    • HanyenknoAfi Tan Peck Luan
    • Ng Xue Lin Sherilyn Wong Suet Teng, Melissa
  • T5 Main Backup
    • JoyeetaBiswasOngKian An
    • TeoSim Yee Stephanie Tan Yan Hao
    • Wu Shujun Wang Ruohan
    • Liu Na Zheng Yang
  • T6 Main Backup
    • Zhang Chao Wang Shuling
    • Chua Yu Tong LauraRasheillaBte Rajah
    • Koh Yi Ting Brenda Low Wei Chen Gerard J
    • Siddhartha GanZhi Wei James

Since some students still have not tried at allTherefore, 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
Question 1 (Applications)
  • Show us 7 applications of Stacks
  • Show us 7 applications of Queues
question 2 stack reorder
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!
question 3 stack for sorting
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!
question 4 queue
Question 4 (Queue)
  • What if Queue ADT is implemented using TailedLinkedListbut in different way!
  • Think about the pros and cons of this strategy!
next week recess
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 19-25 Sep 08
    • You can email me but my response will be slower…