1 / 33

Lecture 41: Course Review

CSC 212 – Data Structures. Lecture 41: Course Review. Final Exam. Thurs., Dec. 15 th from 12:30 – 2:30PM in OM 200 Plan on exam taking full 2 hours If major problem , come talk to me ASAP Exam covers material from entire semester Open-book & open-note so bring what you’ve got

Download Presentation

Lecture 41: Course Review

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 212 – Data Structures Lecture 41:Course Review

  2. Final Exam • Thurs., Dec. 15thfrom 12:30 – 2:30PM in OM 200 • Plan on exam taking full 2 hours • If major problem, come talk to me ASAP • Exam covers material from entire semester • Open-book & open-note so bring what you’ve got • My handouts, solutions, & computers are not allowed • Cannot collaborate with a neighbor on the exam • Problems will be in a similar style to 2 midterms

  3. Inheritance • implements& extendsused for relationships • Both imply there exists anis-arelationship public class Student extends Person {…} public class Cat extends Mammal { … } public class AQ<E> implements Queue<E>{…}

  4. Inheritance • All Java classes extend exactly 1 other class • All fields & methods inherited from the superclass • Within subclass, can access non-private members • Private methods inherited, but cannot be accessed • Classes can implement any number of interfaces • Must implement methods from the interface

  5. Overriding & Hiding • Subclass can override/overload inherited methods • Instance’stype determines which method is called • Parameter list stays the same to override the method • Overload method by modifying parameter list • Field in superclasshidden by redeclaring in subclass • 2 fields with the same name now in subclass • Use the field for variable’s type

  6. Exceptions in Java • throw an exception when an error detected • Exceptions are objects - need an instance to throw • try executing code & catcherrors to handle • try only when you will catch 1 or more exceptions • Do not need to catchevery exception • If it is never caught, program will crash • Not a bad thing– had an unfixable error! • Exceptions listed in methods’ throwsclause • Uncaught exception only need to be listed • Should list even if thrown by another method

  7. Abstract Methods • Methods declared abstractcannot have body • IOU for subclasses which will eventually define it • abstractmethods only in abstract classes • Cannot instantiate an abstract class • But could still have fields & (non-abstract) methods • abstractmethods declared by interfaces • Interfaces cannot declare fields • public abstract methods only in interfaces

  8. Arrays vs. Linked Lists • Concrete implementations used to hold data • Not ADTs • Arrays are easier to use & provide quicker access • Also are impossible to grow • Implementing ADTs harder due to lack of flexibility • Slower access & more complex to use linked lists • Implementing ADTs easier with increased flexibility • Can be singly, doubly, or circularly linked

  9. Stack vs. Queue • Access data with Stackin LIFO order • Last In-First Out is totally unfair (unless always late) • Data accessed in Queue using FIFO order • First In-First Out ensures early bird gets the worm Order read if Stack Order read if Queue

  10. Simplest ADTs

  11. ADT Operations

  12. Iterators & Iterables import java.util.Iterator;import java.lang.Iterable;public interface Iterator<E> {Enext() throws NoSuchElementException;booleanhasNext(); voidremove()throws UnsupportedOperationException;}public interface Iterable<E> {Iterator<E> iterator();}

  13. More Iterator & Iterable • Abstract work in processing with Iterator Iterable<Integer>myList;Iterator<Integer>it;...for (it = myList.iterator(); it.hasNext(); ) {Integer i= it.next(); ...} • Process Iterable objects in an even easier way ...for (Integer i:myList) {...}

  14. IndexList & NodeList • Collection which we can access all elements • Add element before an existing one • Return the 3rd element in List • Loop over all elements without removing them • List ADTs differ in how they provide access • IndexListuses indices for absolution positioning • Can only use relative positions in NodeList • All Lists are Iterable

  15. Sequence ADT • Combines Deque, IndexList, & PositionList • Includes all methods defined by these interfaces • Adds 2 methods to convert between systems • Get Position at index using atIndex(i) • indexOf(pos)returns index of a Position

  16. Sequence ADT • Combines Deque, IndexList, & PositionList • Includes all methods defined by these interfaces • Adds 2 methods to convert between systems • Get Position at index using atIndex(i) • indexOf(pos)returns index of a Position

  17. Trees vs. Binary Trees • Both represent parent-child relationships • Both consist of single "root" node & its descendants • Nodes can have at most one parent • Root nodes are orphans -- do not have a parent • All others, the non-root nodes must have parent • Children not required for any node in the tree • No limit to number of children for non-binary trees • 2 children for node in binary tree is the maximum

  18. Traversal Methods • Many traversals, differ in order nodes visited • Do parent then do each kid in pre-order traversal

  19. Traversal Methods • Many traversals, differ in order nodes visited • Do parent then do each kid in pre-order traversal • Post-order traversal does kids before doing parents

  20. Traversal Methods • Many traversals, differ in order nodes visited • Do parent then do each kid in pre-order traversal • Post-order traversal does kids before doing parents • Do left kid, parent, then right kid in in-order traversal

  21. Visualization of Tree B B A D F A D F C E C E

  22. D C B A Picturing Linked BinaryTree B A C      D

  23. Priority Queue ADT • Priority queue uses strict ordering of data • Values assigned priority when added to the queue • Priorities used to process in completely biased order First you get the sugar, then you get the power, then you get the women

  24. Priority Queue ADT • PriorityQueue yet another Collection • Prioritize each datum contained in the collection • PQ is organized from lowest to highest priority • Access smallest priority only sort of like Queue • min() & removeMin()return priority & value • Implementation not defined: this is still an ADT • Remember that organization & order is theoretical only

  25. Priority Queue ADT • PriorityQueue yet another Collection • Prioritize each datum contained in the collection • PQ is organized from lowest to highest priority • Access smallest priority only sort of like Queue • min() & removeMin()return priority & value • Implementation not defined: this is still an ADT • Remember that organization & order is theoretical only order is theoretical only

  26. Entrys in a PriorityQueue • PriorityQueues use Entryto hold data • As with Position, implementations may differ • Entry has 2 items that define how it gets used • PQ will only use key – the priority given to the Entry • Value is important data to be processed by program

  27. Sequence-based Priority Queue • Simplest implementation of a Priority Queue • Instance of Sequenceused to store Entrys • Many implementations possible for Sequence • But we already know how to do that, so… • Assume O(1) accessand ignore all other details • But how to store Entrys in the Sequence? • Order Entrys by priority within the Sequence -or- • Sequenceunordered & searched when needed

  28. Heaps • Binary-tree based PQimplementation • Still structured using parent-child relationship • At most 2 children & 1 parent for each node in tree • Heaps must also satisfy 2 additional properties • Parent at least as important as its children • Structure must form a complete binary tree 2 5 9 7 6

  29. Hints for Studying • Will NOTrequire memorizing: • ADT’s methods • Nodeimplementations • Big-Oh time proofs • (Memorizing anything)

  30. Hints for Studying • You should know (& be ready to look up): • How ADT implementations work(tracing & more) • For each method what it does & what it returns • Where & why each ADT would be used • For each ADT implementations,its pros & cons • How to compute big-Ohtime complexity

  31. Studying For the Exam • What does the ADT do? • Where in the real-world is this found? • How is the ADT used? • What are the applications of this ADT? • How is it used and why? • How do we implement the ADT? • Given the implementation, why do we do it like that? • What tradeoffsdoes this implementation make?

  32. “Subtle” Hint Do NOT bother with memorization Be ready to lookup &use information quickly

  33. Final Exam Schedule • Lab Mastery Exam is:Tues., Dec. 13thfrom 8:00 – 10:00PM in OM 119 • Final Exam is: Thur., Dec. 15thfrom 12:30 – 2:30PMin OM 200

More Related