1 / 9

CS240: Advanced Programming Concepts

Explore Trie data structure, methods like hashCode and equals, edit distances, exceptions, and tips for Lab 2. Learn to handle exceptions gracefully and efficiently. Understand how to work with immutable strings, build and test a Trie class, and implement spell-checking algorithms using edit distances.

shieldsa
Download Presentation

CS240: Advanced Programming Concepts

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. CS240: Advanced Programming Concepts Week 3 Tuesday

  2. Announcements • Due date for Evil Hangman lab… • Tuesday September 20th… Yep.

  3. Lab 2 Read/Walk Through • Trie data structure (see next slide) • Characters as indexes • Use a char • Use a hashmap • Methods to override… • toString() • Can we use/reuse anything here when checking for equivalence? • hashCode() • equals() • Equals method() – review hashCode… • Similarity of words • Cumulative edit distance <= 2 • Four edit distances • Deletion • Transposition (adjacent) • Alteration • Insertion

  4. Data Structure: Trie

  5. Exceptions • Exceptions provide a standardized way of gracefully handling… “situations” • try { <some statements> } • This is the block of code that might fail for some reason • throw <Throwable object> • throw new <exception type>; • catch(<ExceptiontType> <name>) • This block of code is your exception handler for the specified exception type. This is where you have a chance to respond gracefully to an otherwise potentially ugly situation, or perhaps to simply handle a specific (“exceptional”) circumstance. • finally { <some statements> } • “The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.” https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html

  6. Lab 2 Tips and Tricks • Take advantage of help sessions! • Make it work, THEN make it fast • Strings are immutable… • http://www.javapractices.com/topic/TopicAction.do?Id=29 • http://www.javapractices.com/topic/TopicAction.do?Id=15 • Build your Trie class first • How might you build/test this data structure?

  7. Lab 2 Tips and Tricks Continued • Spell checking: • Step one: Be able to identify a word in the dictionary • Throw an exception if you don’t find it • Step two: generate all possible variations of a word that are and edit distance of 1 from the desired word – search for these in the dictionary • Select from those found using the priority rules provided • If none found – proceed to step three • Step three: using the list of words with an edit distance of 1 from the entered word, generate all possible words with an edit distance of 1 from these words (these are the words with an edit distance of 2 from the entered word…) • Select from those found using the priority rules provided • If none found – throw the exception…

  8. Packages • Demo • Simple: Woodfield example • A bit more complex: Rodham example

  9. Creating Copies of Objects • .clone() • https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#clone() • Copy constructors • Demo: CopyConstructorDemo

More Related