Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Computation and Problem Solving Class 32: The Java® Collections Framework Prof. Steven R. Lerman and Dr. V. Judson Harward.
Java Programming: Advanced Topics 1 Collections and Utilities.
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
JAVA Programming (Session 7) When you are willing to make sacrifices for a great cause, you will never be alone. Instructor:
The ArrayList Class and the enum Keyword
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Lecture 3 Introduction to Collections Advanced Java Programming 1 dr inż. Wojciech Bieniecki
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L16 (Chapter 22) Java Collections.
hashing1 Hashing It’s not just for breakfast anymore!
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Sets and Maps Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
1 The Map ADT © Rick Mercer. 2 The Map ADT  A Map is an abstract data type where a value is "mapped" to a unique key  Also known as Dictionary  Need.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Hash Functions and the HashMap Class A Brief Overview On Green Marble John W. Benning.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
(c) University of Washington14-1 CSC 143 Java Collections.
1 Sets and Maps Starring: keySet Co-Starring: Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
The Java Collections Framework (Part 2) By the end of this lecture you should be able to: Use the HashMap class to store objects in a map; Create objects.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Hash Tables1   © 2010 Goodrich, Tamassia.
Chapter 18 Java Collections Framework
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
CIS Intro to JAVA Lecture Notes Set 7 7-June-05.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
13-1 Sets, Bags, and Tables Exam 1 due Friday, March 16 Wellesley College CS230 Lecture 13 Thursday, March 15 Handout #23.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Hashing as a Dictionary Implementation Chapter 19.
RED-BLACK TREE SEARCH THE FOLLOWING METHOD IS IN TreeMap.java:
Chapter 11 Hash Anshuman Razdan Div of Computing Studies
“Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.” – Margaret Meade Thought.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Maps Nick Mouriski.
Week 9 - Friday.  What did we talk about last time?  Collisions  Open addressing ▪ Linear probing ▪ Quadratic probing ▪ Double hashing  Chaining.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 15: Sets and Maps Java Software Structures: Designing and Using.
1 Maps, Stacks and Queues Maps Reading:  2 nd Ed: 20.4, 21.2, 21.7  3 rd Ed: 15.4, 16.2, 16.7 Additional references: Online Java Tutorial at
Collections Dwight Deugo Nesa Matic
CSE 143 Lecture 11: Sets and Maps reading:
Hashing By Emily Nelson. The Official Definition Using a hash function to turn some kind of data in relatively small integers or Strings The “hash code”
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Click to edit Master text styles Stacks Data Structure.
Sixth Lecture ArrayList Abstract Class and Interface
Week 8 - Wednesday CS221.
JAVA COLLECTIONS LIBRARY
Java Software Structures: John Lewis & Joseph Chase
null, true, and false are also reserved.
L5. Necessary Java Programming Techniques
Hashing in java.util
Web Design & Development Lecture 6
Presentation transcript:

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation

Mainly used in Pattern Matching with strings In Theoretical Computer Science to represent Atomatons and Regular Languages Can be implemented using Java and many other languages. Eg: boolean b = Pattern.matches("a*b", "aaaaab"); in Java. Eg: regex(?n, Chicago, i) in SPARQL.

1. a*b => aaaaa……….b OR b [1 or 0 as followed by 1 b] 2. a + b => aaaa……….b OR ab [at least 1 a followed by 1 b] 3. (a|b) => Either a OR b. 4. (a|b)*bb => aaaa…….bbORbbb………bb

Important APIs and Interfaces a. java.util.regex b. java.util.regex.Pattern c. Serializable [Interface]

public final class Pattern extends Object implements Serializable _____________________________________________________________________________ Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches(); ~ boolean b = Pattern.matches("a*b", "aaaaab");

Here's an example, MatcherDemo.java, that counts the number of times the word "dog" appears in the input string. import java.util.regex.Pattern; import java.util.regex.Matcher; public class MatcherDemo { private static final String REGEX = "\\bdog\\b"; private static final String INPUT = "dog dog dog doggie dogg"; public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); // get a matcher object Matcher m = p.matcher(INPUT); int count = 0; while(m.find()) { count++; System.out.println("Match number " + count); System.out.println("start(): " + m.start()); System.out.println("end(): " + m.end()); }

Hashtable was part of the original java.util and is a concrete implementation of a Dictionary. Hashtable stores key/value pairs in a hash table. When using a Hashtable, you specify an object that is used as a key, and the value that you want linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table. Hash Table Class

Hashtable( ) //default constructor Hashtable(int size) //creates a hash table that has an initial size specified by size Hashtable(int size, float fillRatio) //creates a hash table that has an initial size specified by size and a fill ratio specified by fillRatio. Hashtable(Map m) //creates a hash table that is initialized with the elements in m.

1. boolean contains(Object value) //Returns true if some value equal to value exists within the hash table. Returns false if the value isn't found. 2. boolean containsKey(Object key) //Returns true if some key equal to key exists within the hash table. Returns false if the key isn't found. 3. boolean containsValue(Object value) //Returns true if some value equal to value exists within the hash table. Returns false if the value isn't found. 4. Enumeration elements( ) //Returns an enumeration of the values contained in the hash table. 5. Object get(Object key) //Returns the object that contains the value associated with key. If key is not in the hash table, a null object is returned. 6. boolean isEmpty( ) //Returns true if the hash table is empty; returns false if it contains at least one key. 7. Enumeration keys( ) //Returns an enumeration of the keys contained in the hash table. 8. Object put(Object key, Object value) //Inserts a key and a value into the hash table. Returns null if key isn't already in the hash table; returns the previous value associated with key if key is already in the hash table. 9. void rehash( ) //Increases the size of the hash table and rehashes all of its keys. 10. Object remove(Object key) //Removes key and its value. Returns the value associated with key. If key is not in the hash table, a null object is returned.

HashMap class uses a hashtable to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets.

HashMap( ) //default hash map HashMap(Map m) //initializes the hash map by using the elements of m HashMap(int capacity) //initializes the capacity of the hash map to capacity HashMap(int capacity, float fillRatio) //initializes both the capacity and fill ratio of the hash map by using its arguments

1. boolean containsKey(Object key) //Returns true if this map contains a mapping for the specified key. 2. boolean containsValue(Object value) //Returns true if this map maps one or more keys to the specified value. 3. Set entrySet() //Returns a collection view of the mappings contained in this map. 4. Object get(Object key) //Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key. 5. boolean isEmpty() //Returns true if this map contains no key-value mappings. Basically same as Hash Table………………..