14
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing contains (051) or add (021) Other tree questions Other Java Collections Framework questions SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Embed Size (px)

Citation preview

Page 1: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

CS2852Week 8, Class 2 Today

Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown)

Tomorrow: Quiz Implementing contains (051) or add (021) Other tree questions Other Java Collections Framework questions

SE-2811Slide design: Dr. Mark L. Hornick

Content: Dr. HornickErrors: Dr. Yoder

1

Page 2: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Muddiest points on this lecture from 051

Complete and full definitionsExactly what is important about the Java Collection Framework. Aside from the general properties of frameworksWhat benefit does a pre-order traversal have?Complete vs Full vs that third type [perfect] of treedifferences between full and completeWhen a tree is completeHow to implement the different traversalshow to do pre order traversal

SE-2811Dr.Yoder 2

Page 3: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Mudiest points on this lecture from 021

difference between complete and fullThe reason and need for the implementation of trees in adding/multiplying in a high level language

SE-2811Dr.Yoder 3

Page 4: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Outcomes for Today (051)

Java Collection Framework Define the term adaptor class and be able to implement

a simple adaptor class, e.g., stack, queue Describe the design flaw found in

the Queue<E> interface found in the Java Collection Framework

SE-2811Dr.Yoder 4

Page 5: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Outcomes for Today (both)

Interpret and write Java code using the TreeMap and TreeSet classes

Implement a recursive contains() method Describe how elements are removed from a

binary search tree State and explain the asymptotic time complexity

of the following methods from a TreeSet: add(E), clear(), contains(Object), isEmpty(), remove(Object), and size()

SE-2811Dr.Yoder 5

Page 6: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Pre-order traversal

An Euler tour, Source: Wiki:Tree_traversal 6

Page 7: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

In-order traversal

An Euler tour, Source: Wiki:Tree_traversal7

Page 8: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Post-order traversal

An Euler tour, Source: Wiki:Tree_traversalSE-2811Dr.Yoder 8

Page 9: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Level-order traversal

An Euler tour, Source: Wiki:Tree_traversalSE-2811Dr.Yoder 9

Page 10: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

A tree where every non-leaf node has two children

A tree with all levels completely filled

Full tree

SE-2811Dr.Yoder 10

Perfect tree

A tree with all but the lowest level completely filled. The lowest level must have all nodes on the left

Complete tree

Page 11: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

A compilation goal

Compile expressions like x*y+5

Into code that only uses the low-level commands push(int) – push an integer value onto the stack mult() – pop the top two items, push their product add() – pop the top two items, pus their sum int pop() – pop the result, this is the value of the

expression

SE-2811Slide design: Dr. Mark L. Hornick

Content: Dr. HornickErrors: Dr. Yoder

11

Page 12: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

Muddiest Point

Wait for the slides, or follow this link to answer both questions at once: http://bit.ly/1Mow5a3

SE-2811Dr.Yoder 12

Page 13: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

SE-2811Dr. Josiah Yoder 13

http://bit.ly/1Mow5a3

Page 14: CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing

SE-2811Dr. Josiah Yoder 14

http://bit.ly/1Mow5a3