13 B: Summary of CS1102S CS1102S: Data Structures and Algorithms - - PowerPoint PPT Presentation

13 b summary of cs1102s
SMART_READER_LITE
LIVE PREVIEW

13 B: Summary of CS1102S CS1102S: Data Structures and Algorithms - - PowerPoint PPT Presentation

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules 13 B: Summary of CS1102S CS1102S: Data Structures and Algorithms Martin Henz April 16, 2010 Generated on Friday 16 th April, 2010, 10:48 CS1102S: Data


slide-1
SLIDE 1

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules

13 B: Summary of CS1102S

CS1102S: Data Structures and Algorithms

Martin Henz

April 16, 2010

Generated on Friday 16th April, 2010, 10:48 CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 1

slide-2
SLIDE 2

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules

1

Highlights of CS1102S

2

Java API Support for Data Structures

3

Outlook to Other Modules

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 2

slide-3
SLIDE 3

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Algorithm Analysis (Chapter 2)

Asymptotic behavior: Big-oh, Big-theta, Big-omega Analysing loops Recurrences

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 3

slide-4
SLIDE 4

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Example of Recurrence

Runtime T(N) T(1) = 1 T(N) = 2T(N/2) + N

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 4

slide-5
SLIDE 5

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Example of Recurrence

Runtime T(N) T(1) = 1 T(N) = 2T(N/2) + N Theorem T(N) = O(N log N)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 5

slide-6
SLIDE 6

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Lists, Stacks, Queues (Chapter 3)

Collections (add, contains, remove) Lists: indexed elements

ArrayList: Implementation based on resizable arrays LinkedList: Implementation based on chains of objects

Stacks and queues: position-oriented

Stack: Last-In, First-Out (LIFO) Queue: First-In, First-Out (FIFO)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 6

slide-7
SLIDE 7

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Trees (Chapter 4)

Trees ubiquitous in CS (e.g. expression trees) Search trees for efficient collections of ordered elements Average insertion/retrieval time: O(log N) Worst case: O(N) (linked list)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 7

slide-8
SLIDE 8

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Hashing (Chapter 5)

Collections that exploit mapping of elements (keys) to (nearly) unique hash values Separate chaining: keep linked lists of colliding elements Linear/quadratic probing; double hashing

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 8

slide-9
SLIDE 9

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Priority Queues (Chapter 6)

Collection of ordered elements with efficient deleteMin and insert Idea: use complete binary tree with heap property (implemented by an array) insert: O(log N) and on average using 2.607 comparisons deleteMin: O(log N)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 9

slide-10
SLIDE 10

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Sorting (Chapter 7)

Insertion sort, bubble sort: exchanging adjacent elements: O(N2) Shellsort: use larger step size: Θ(N3/2) Heapsort: Use priority queue for sorting, re-using shrinking array: O(N log N) Mergesort: Divide-and-conquer: Split in half, and merge: O(N log N) Quicksort: Divide-and-conquer: Split using pivot, merge trivial: average and best O(N log N), worst: O(N2)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 10

slide-11
SLIDE 11

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Graph Algorithms (Chapter 8)

Definitions: Section 9.1 Topological sort: Section 9.2 Shortest-Path: 9.3 (excluding 9.3.4, 9.3.5, 9.3.6) Network Flow: 9.4 Minimum Spanning Tree: 9.5.1 Intro to NP-Completeness: 9.7

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 11

slide-12
SLIDE 12

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

Algorithm Design Techniques

Greedy algorithms: example Huffman codes Divide and conquer: sorting, closest-points Dynamic programming: optimal binary search tree Backtracking algorithms: turnpike reconstruction, games

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 12

slide-13
SLIDE 13

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Priority Queues Sorting Graph Algorithms Algorithm Design Techniques

External Algorithms

B-trees: 4.7 External sorting: 7.10 (excluding 7.10.5 and 7.10.6)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 13

slide-14
SLIDE 14

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

1

Highlights of CS1102S

2

Java API Support for Data Structures Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

3

Outlook to Other Modules

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 14

slide-15
SLIDE 15

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

The Top-level Collection Interface

public interface Collection <Any> extends Iterable <Any> { int size ( ) ; boolean isEmpty ( ) ; void clear ( ) ; boolean contains ( Any x ) ; boolean add ( Any x ) ; / / sic boolean remove ( Any x ) ; / / sic java . u t i l . I t e r a t o r <Any> i t e r a t o r ( ) ; }

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 15

slide-16
SLIDE 16

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

The List Interface in Collection API

public interface List <Any> extends Collection <Any> { Any get ( int idx ) ; Any set ( int idx , Any newVal ) ; void add ( int idx , Any x ) ; void remove ( int idx ) ; L i s t I t e r a t o r <Any> l i s t I t e r a t o r ( int pos ) ; }

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 16

slide-17
SLIDE 17

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

ArrayList and LinkedList

public class ArrayList <Any> implements List <Any> { . . . } public class LinkedList <Any> implements List <Any> { . . . }

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 17

slide-18
SLIDE 18

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

Iterators

public interface I t e r a t o r <Any> { boolean hasNext ( ) ; Any next ( ) ; void remove ( ) ; }

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 18

slide-19
SLIDE 19

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

ListIterators

public interface L i s t I t e r a t o r <Any> extends I t e r a t o r <Any> { boolean hasPrevious ( ) ; Any previous ( ) ; void add ( Any x ) ; void set ( Any newVal ) ; }

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 19

slide-20
SLIDE 20

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

TreeSet

Implements Collection Guarantees O(log N) time for add, remove and contains

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 20

slide-21
SLIDE 21

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

AbstractMap<K,V>

Basic operations V get(K key): Returns the value to which the specified key is mapped. V put(K key, V value): Associates the specified value with the specified key in this map.

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 21

slide-22
SLIDE 22

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

AbstractMap<K,V>

Basic operations V get(K key): Returns the value to which the specified key is mapped. V put(K key, V value): Associates the specified value with the specified key in this map. Other operations containsKey(key), containsValue(val), remove(key)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 22

slide-23
SLIDE 23

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

TreeMap

Extends AbstractMap Guarantees O(log N) time for put, get, containsKey, containsValue, remove

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 23

slide-24
SLIDE 24

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

HashMap

Extends AbstractMap Uses separate chaining with rehashing Rehashing is governed by initial capacity and load factor, set in constructor

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 24

slide-25
SLIDE 25

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

HashSet

Implements Collection using HashMap

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 25

slide-26
SLIDE 26

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

PriorityQueue

Implements Collection Efficient implementation of heap data structure Operation names:

deleteMin is called “poll” insert is called “add” (of course)

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 26

slide-27
SLIDE 27

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

Sorting

Generic sorting supported by class Collections

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 27

slide-28
SLIDE 28

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

Sorting

Generic sorting supported by class Collections Uses mergesort in order to minimize number of comparisons

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 28

slide-29
SLIDE 29

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

Sorting

Generic sorting supported by class Collections Uses mergesort in order to minimize number of comparisons Sorting of built-in numerical types supported by class Arrays

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 29

slide-30
SLIDE 30

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules Collections, Lists, Iterators Trees Hashing PriorityQueue Sorting

Sorting

Generic sorting supported by class Collections Uses mergesort in order to minimize number of comparisons Sorting of built-in numerical types supported by class Arrays Uses efficient implementation of quicksort, to take advantage of tight inner loop.

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 30

slide-31
SLIDE 31

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules

Algorithm-related Modules

CS3233 Competitive Programming CS3230 Design and Analysis of Algorithms CS4231 Parallel and Distributed Algorithms CS5206 Foundation in Algorithms

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 31

slide-32
SLIDE 32

Highlights of CS1102S Java API Support for Data Structures Outlook to Other Modules

Programming-languages-related Modules

CS2104 Programming Language Concepts CS3210 Parallel Computing CS3211 Parallel and Concurrent Programming CS4215 Programming Language Implementation CS4216 Constraint Logic Programming CS5205 Foundation in Programming Languages

CS1102S: Data Structures and Algorithms 13 B: Summary of CS1102S 32