lecture21

lecture21 - CS111: Intro to Computer Science Lecture 21...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 21 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 21 Recursion
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 21 Linked List Linked List public class Node { char data; Node next; } data ‘a’ next Data ‘b’ next Data ‘c’ next null public class Foo{ … Node lst … } lst
Background image of page 2
CS111: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 21 Linked List Linked List Stores a sequence of data items Like array, but instead of “who is nth”, says “who is next” See Node.java, NodeOps.java, Party.java (revised Nov. 10), PartyNode.java
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 21 Inserting Inserting Insert after node here: newNode.next = here.next here.next = newNode Insert at head: newNode.next = head head = newNode (note: this may have to be done in the calling method) Cost: O(1) (not including cost of finding here)
Background image of page 4
CS111: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 21 Deleting Deleting Delete after node here: here.next = here.next.next Delete head: head = head.next (note: the assignment may have to be done in the calling method) Cost: O(1) (not including cost of finding here)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 21 Deleting Deleting Special cases: List already empty Deleting only node in the list
Background image of page 6
CS111: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 21 Find by data Find by data Node place = head; place = place.next; } Time cost: O(n)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 21 Find by index Find by index Node place = head; ct = 0; place = place.next; ct++; } Time cost: O(n)
Background image of page 8
CS111: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 21 Time Costs Time Costs O(1) O(n) Find by index Find by content Delete Insert O(n) O(n) O(n) O(1) O(n) O(1) Ordered Array Linked List
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 10 Lecture 21 Space Cost Space Cost Linked list: One extra space per node plus one per list Array of objects: ditto, plus max array length ever needed Array of eg ints: max array length ever needed Example: need to store 1000 ints in one of 100 lists/arrays Lists: 2100 spaces Arrays: 100,000 spaces
Background image of page 10
CS111: Slides for Prof. Steinberg ʼ s lecture 11 Lecture 21 Linked lists Linked lists vs vs ordered arrays ordered arrays Linked Lists: Extra space for pointers No maximum size Insert/delete fast once you know where Ordered Arrays: Extra space to expand into Maximum size set at creation Access by index quick
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 12 Lecture 21 Merging ordered lists
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/01/2011 for the course 198 111 at Rutgers.

Page1 / 44

lecture21 - CS111: Intro to Computer Science Lecture 21...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online