CS 240 Week 2.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Object Oriented Programming with Java
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
CS18000: Problem Solving and Object-Oriented Programming.
CS252: Systems Programming Ninghui Li Program Interview Questions.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Boggle Game: Backtracking Algorithm Implementation
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
CS 240 Week 2. Introduction to Project 2 Command Line Syntax java Spell word -- source file hard wired into program Run Demo.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Programming Assignment #4 Binary Trees
Chapter 10 Classes Continued
CS 46B: Introduction to Data Structures July 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Multiple Choice Solutions True/False a c b e d   T F.
Binary Search Trees. BST Properties Have all properties of binary tree Items in left subtree are smaller than items in any node Items in right subtree.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
CS 240 Week 3. List’Em java Grep [-r] directoryName fileSelectionPattern substringSelectionPattern Run Demo java LineCount [-r] directoryName fileSelectionPattern.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Lecture Objectives  To learn how to use a Huffman tree to encode characters using fewer bytes than ASCII or Unicode, resulting in smaller files and reduced.
Data Structures Week 6: Assignment #2 Problem
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
CompSci Maps  Maps are another way of organizing data  Keys and Values  Each key maps to a value  Some keys can map to the same value  Can.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
CPS 506 Comparative Programming Languages Syntax Specification.
Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Tries Data Structure. Tries  Trie is a special structure to represent sets of character strings.  Can also be used to represent data types that are.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Compsci 201 Recitation 10 Professor Peck Jimmy Wei 11/1/2013.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
1. What is it? It is a queue that access elements according to their importance value. Eg. A person with broken back should be treated before a person.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Week 15 – Monday.  What did we talk about last time?  Tries.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Generic Trees—Trie, Compressed Trie, Suffix Trie (with Analysi
Tries 4/16/2018 8:59 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Tries 07/28/16 11:04 Text Compression
CS240: Advanced Programming Concepts
Data Structures and Design in Java © Rick Mercer
Tries 5/27/2018 3:08 AM Tries Tries.
Agenda Warmup AP Exam Review: Litvin A2
Week 6 - Wednesday CS221.
Heaps and Priority Queue
8.1 Tree Terminology and Applications
Lab 10 - Quicksort.
Interface.
An Introduction to Java – Part I, language basics
Interfaces.
CS240: Advanced Programming Concepts
Chapter 8 Class Inheritance and Interfaces
EE 312 Final Exam Review.
Program: Mini Phone Book 2/11/2016
Presentation transcript:

CS 240 Week 2

Introduction to Project 2 Command Line Syntax java Spell word -- source file hard wired into program Run Demo

Basic Algorithm Look up word in dictionary If found List the word Comparison is case insensitive If found List the word Else if a similar word is found List the most similar word Else Indicate no word found See project description for syntax The input word must consist of 1 or more letters

Dictionary Must Be Represented as Trie A tree like structure defined recursively Root node Internal nodes (sub-Tries) Leaf nodes have no sub-Tries Each node contains A count A value > 0 represents the number times a word in the dictionary (represented by a path through the tree to the current node) appears in the dictionary. 26 Sub-Tries having the values ‘a’..’z’ The Trie (or root of the Trie) contains The number of words in the dictionary The number of nodes in the dictionary

Trie Operations Constructor Methods add(String word) find(String word); int getWordCount() Int getNodeCount() What to do about getting the frequency? Add the method int getFrequencyFor(String word) Change the return type of find(String) to int The result is the frequency of the word If there is no word in the Trie return 0 (or -1)

What Does It Mean for a Word to Be Similar to Another Word Edit Distance Deletion distance Transposition distance Alteration distance Insertion distance Edit Distance 1 and 2

Making the Output Deterministic One word is “more similar” than another word Based on the following priorities A word that is has an edit distance of one has a higher priority than one that is has an edit distance of 2 If both words have the same edit distance then select the one that appears more frequently in the dictionary If two words appear equally often in the dictionary then pick the one the is alphabetically first.

Additional String Operations s.toLowerCase() s.toUpperCase() StringBuilder Building strings using “+” is expensive StringBuilder strBuilder = new StringBuilder() strBuilder.append(String) Can be anything that has a toString method or atomic type strBuilder.delete(int, int) strBuilder.setCharAt(int,char) Code Examples

Interfaces Interaction contract Keyword “implements” At any place in a java program you an have variables of the interface type Object in variables must be instance of an implementing class Keyword “implements” Like .h file in concept (conceptually similar to abstract class) Contains Constants (static and final) Method signatures You must provide an implementing class

Interface Example StudentListInterface.java: The interface ArrayStudentList.java: implements StudentListInterface.java ArrayListStudentList.java: implements StudentListInterface.java TestingStudentListInterface.java

Interesting Addition of For Loops for(String s = “”; s != null; s = f.readLine()) … Use of finally Example Code testFile – put in same directory as Example Code