Set<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() );
|
|
- Martina Nancy James
- 6 years ago
- Views:
Transcription
1 Advanced Java Concepts Maps and Sets and Miscellany Exercises and Programs 1. This code a) contains a compiler error. b) contains a runtime error. c) displays 1 d) displays 2 2. This code a) contains a compiler error. b) contains a runtime error. c) displays 1 d) displays 2 3. What is displayed? Look up the HashSet class in the API and examine its constructors. This is useful. Set<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() ); Set<String> s = new HashSet<String>(); s.add( "A" ); s.add( "a" ); System.out.println( s.size() ); ArrayList<String> a = new ArrayList<String>(); a.add( "A" ); a.add( "B" ); a.add( "B" ); Set<String> s = new HashSet<String>( a ); System.out.println( a.size() + ", " + s.size() ); 4. What is displayed? (The order is not important.) a) Jane Smith, Joe Smith, Joe Jones b) Jane Smith, Joe Jones c) Joe Smith, Joe Jones d) Jane Smith Map<String, String> m = new TreeMap<String, String>(); m.put( "Smith", "Jane" ); m.put( "Jones", "Joe" ); m.put( "Smith", "Joe" ); Set<String> names = m.keyset(); for ( String nm : names ) System.out.println( m.get( nm ) + " " + nm ); 5. What is displayed? Map<Integer, Integer> m = new TreeMap<Integer, Integer>(); m.put( 1, 2 ); m.put( 3, 4 ); m.put( 5, 6 ); System.out.println( m.containsvalue( 3 ) ); System.out.println( m.put( 5, 12 ) ); System.out.println( m.put( 6, 14 ) ); System.out.println( m.put( 7, 14 ) ); System.out.println( m.remove( 5 ) ); System.out.println( m.remove( 2 ) ); System.out.println( m.size() ); 1
2 6. Practice-It. Do all the problems in the Sets and Maps section of CSE 143 (CS2). The solution for removeevenlength and a brief discussion of iterators is shown below. To traverse and remove items from a set, you must use an Iterator object. Consider the following example (a problem from Practice-It and their solution). public static void removeevenlength(set<string> set) { Iterator<String> itr = set.iterator(); while (itr.hasnext()) { String s = itr.next(); if (s.length() % 2 == 0) { itr.remove(); HashSet and TreeSet implement the Iterable interface which consists of just one method: iterator which returns an Iterator object. An Iterator object has three methods: boolean hasnext() returns true if there are more elements E next() returns the next element throws an exception if there is nothing else void remove() removes from the underlying collection the last element returned by this iterator (optional operation). 7. The Cryptogram Program. A cryptogram is phrase that has been encoded. Each letter has been assigned a new value according to some table. For example, YES encoded might become AGW BALL encoded might become XHAA if Y is replaced with an A, E with a G, and S with a W if B is replaced with an X, A with H, Ls with As Each letter of the alphabet is paired with another letter of the alphabet. All non-letters (e.g. spaces, numbers, punctuation marks, etc.) are not changed. Here is an outline of the Cryptogram class. public class Cryptogram { private Map<String, String > code; // the keys are A to Z // the values are the corresponding letters public Cryptogram(){ code = new TreeMap<String, String>(); initmap(); // continued on the next page 2
3 private void initmap(){ Initialize the map so that each key has a randomly (using Math.random) assigned value with no duplicate values. Obviously the size of the map should be 26 by the time you re done. If you need to fill up a list with the letters of the alphabet (and I m not saying you have to do this), here s a neat way: List<String> letters = new ArrayList<String>(); for ( int n = 65; n <= 90; n++ ) { String s = Character.toString( (char) n ); list.add( s ); // all uppercase letters Why 65 to 90? You should know or find out why. public String encode( String s ){ Convert s to all upper case characters. Given a string this method should replace each letter with its corresponding replacement character. Any character in s that is not in the map should be unchanged. For example, if s is car 4 sale! then the method may return INP 4 UNZO! or something like that. This method must use your map. public String tostring(){ This returns a list of the letters of the alphabet and their corresponding values. Write a short test program which first calls the tostring method. Then the program prompts the user to enter a phrase and it displays the encoded version. You should be able to look at the tostring output and verify that the phrase was properly encoded. 8. Character Frequency Program. Write the getmap method of the CharacterFrequency class. The argument is a text file and it returns a map that indicates how many times each non-space character appears in the file. A link to words.txt is on mrsawyer.com. Treat all letters as lowercase letters. Do not count the number of spaces but it should count all characters, not just letters. import java.util.*; You can use a Scanner object to read a text file. Check out the appendix. public class RunFreq { public static void main( String [] args ){ Map<String, Integer> m = CharacterFrequency.getMap( "words.txt" ); Set<String> set = m.keyset(); for ( String s: set ){ Integer num = m.get( s ); System.out.printf( "%s appears %,8d times\n", s, num ); Sample outputs on the next page. 3
4 Here s my output when the file was words.txt a appears 68,582 times b appears 17,798 times c appears 34,281 times d appears 34,551 times e appears 106,755 times f appears 12,710 times g appears 27,843 times h appears 20,200 times i appears 77,409 times j appears 1,780 times k appears 9,366 times l appears 47,011 times m appears 24,741 times n appears 60,508 times o appears 54,542 times p appears 25,788 times q appears 1,632 times r appears 64,963 times s appears 86,542 times t appears 57,057 times u appears 31,154 times v appears 9,186 times w appears 8,535 times x appears 2,700 times y appears 13,472 times z appears 3,750 times Here s my output when the file was a copy of the school s home web page. " appears 300 times # appears 43 times % appears 2 times & appears 12 times ( appears 2 times ) appears 2 times - appears 55 times. appears 54 times / appears 214 times 0 appears 148 times 1 appears 8 times 2 appears 12 times 3 appears 82 times 4 appears 4 times 5 appears 3 times 6 appears 74 times 7 appears 26 times 8 appears 4 times 9 appears 7 times : appears 71 times ; appears 27 times < appears 266 times = appears 153 times > appears 266 times? appears 2 times _ appears a appears b appears c appears d appears e appears f appears g appears h appears i appears j appears k appears l appears m appears n appears o appears p appears q appears r appears s appears t appears u appears v appears w appears x appears y appears z appears 4 times 291 times 55 times 185 times 112 times 366 times 193 times 74 times 124 times 192 times 3 times 15 times 190 times 66 times 339 times 394 times 120 times 2 times 229 times 120 times 417 times 27 times 42 times 89 times 26 times 54 times 1 times 4
5 Problems related to hash codes and hashing. 9. If b is true, then a) h1 must equal h2 b) h1 might equal h2 c) h1 will not equal h2 10. If h1 equals h2, then a) b must be true b) b might be true or false c) b must be false Assume that the Clown class is well written. Clown c1 = new Clown(); int h1 = c1.hashcode(); Clown c2 = new Clown(); int h2 = c2.hashcode(); boolean b = c1.equals( c2 ); 11. For insertions and retrievals from a hash table to be run efficiently a) the hash function must generate evenly distributed index values based on item's hash codes. b) the load factor must be around 0.75 or less. c) statement A or B d) statements A and B 12. The following Integers are to be inserted (in the order shown) into the hash table below Array Index Key value The hash function is hash code % 11. The hash code of an Integer is the integer s value. Collisions will be resolved with the "hash-and-search" method. Complete the hash table above to show where each value will be stored. 13. When using a hash table and chaining to implement a map, you should calculate the index and then a) always add the new entry to the front of the chain at that bucket. b) always add the new entry to the end of the chain at that bucket. c) either the front or end if you are using a doubly linked list to implement the chain. c) add the entry anywhere in the chain because it is an unordered collection. 5
6 14. A certain hash function h(x) on a key field places records with the following key fields into a hash table Collisions are handled with a rehashing function r(x), which takes as an argument the result of applying h(x). The key values are entered in the order show above to produce the following table: What are h(x) and r(x), respectively? a) key % 20, (result + 13) % 20 b) key % 20, result % 20 c) key % 30, (result + 14) % 20 d) key % 20, (result + 7) % 20 e) key % 30, (result + 7) % Old AP Computer Science AB Free Response Questions. Complete the following problems on either paper or using an electronic digital computer. There are links on mrsawyer.com or use the link below AP Computer Science AB Problem AP Computer Science AB Problem AP Computer Science AB Problem AP Computer Science AB Problem 3 (optional it just looks interesting). 6
CSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4
CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Related classes Consider classes for
More information11/27/12. CS202 Fall 2012 Lecture 11/15. Hashing. What: WiCS CS Courses: Inside Scoop When: Monday, Nov 19th from 5-7pm Where: SEO 1000
What: WiCS CS Courses: Inside Scoop When: Monday, Nov 19th from -pm Where: SEO 1 Having trouble figuring out what classes to take next semester? Wish you had information on what CS course to take when?
More informationWhat are the differences between the Set interface and the List interface?
7.1.1 Explain the effect of the following method calls. Set s = new HashSet(); s.add("hello"); s.add("bye"); s.addall(s); Set t = new TreeSet(); t.add("123"); s.addall(t);
More informationAbstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework
Announcements Abstract data types (again) PS 5 ready Tutoring schedule updated with more hours Today s topic: The Java Collections Framework Reading: Section 7.5 An ADT is a model of a collection of data
More informationCSE 143, Winter 2010 Midterm Exam Key
1. ArrayList Mystery CSE 143, Winter 2010 Midterm Exam Key List (a) [10, 20, 10, 5] (b) [8, 2, 9, 7, -1, 55] (c) [0, 16, 9, 1, 64, 25, 25, 14, 0] Output [0, 10, 20, 10] [0, 0, 8, 9, -1, 55] [0, 0, 0, 0,
More informationBeside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions.
Collections Beside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions. Map: Indexes collections by arbitrary keys. HashSet import java.util.hashset;
More informationAdvanced Java Concepts Unit 9: Graph Exercises
dvanced Java oncepts Unit : Graph Exercises. Which one of the following data structures would be best suited for representing a street map for pedestrians? graph with... a) undirected, unweighted edges.
More informationAdam Blank Lecture 9 Autumn 2016 CSE 143. Computer Programming II
Adam Blank Lecture 9 Autumn 2016 CSE 143 Computer Programming II CSE 143: Computer Programming II Sets and Maps Outline 1 Sets 2 Foreach Loops 3 Maps Alice in Wonderland 1 Count the Number of Distinct
More informationCSE 143X. Accelerated Computer Programming I/II
Adam Blank Lecture 17 Autumn 2015 CSE 143X Accelerated Computer Programming I/II CSE 143X: Accelerated Computer Programming I/II Sets and Maps Outline 1 Languages and Grammars 2 Sets 3 Foreach Loops 4
More informationCSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,
CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding
More informationCollections and Maps
Software and Programming I Collections and Maps Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Array Lists Enhanced for Loop ArrayList and LinkedList Collection Interface Sets and
More informationAP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s).
AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s). a) This code will not compile because a method cannot specify an interface as a parameter. public class Testing { public static void
More informationSome examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani. The Collection Framework
Some examples and/or figures were borrowed (with permission) from slides prepared by Prof. H. Roumani The Collection Framework Collection: an aggregate that can hold a varying number of elements Interface:
More informationAdam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods
Adam Blank Lecture 5 Winter 2019 CS 2 Introduction to Programming Methods CS 2: Introduction to Programming Methods Java Collections Abstract Data Types (ADT) 1 Abstract Data Type An abstract data type
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write
More informationWhat is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one
Iterators What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one 9-2 2-2 What is an Iterator? An iterator is an abstract data
More informationThis can be solved in two lines using a Set. You should pass the list to an appropriate constructor.
Sets and Maps Programs Advanced Java Concepts All these programs are posted on repl.it 1. Write the numunique method. Given a list of numbers, it returns the number of unique values in the list. For example,
More informationCS 307 Final Spring 2011
Points off 1 2 3 4A 4B 4C 5A 5B Total Off Net CS 307 Final Spring 2011 Name UTEID login name Instructions: 1. Please turn off your cell phones and all other electronic devices. 2. There are 5 questions
More informationSoftware 1 with Java. Recitation No. 6 (Collections)
Software 1 with Java Recitation No. 6 (Collections) Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2
More information[Ref: Core Java Chp 13, Intro to Java Programming [Liang] Chp 22, Absolute Java Chp 16, docs.oracle.com/javase/tutorial/collections/toc.
Contents Topic 08 - Collections I. Introduction - Java Collection Hierarchy II. Choosing/using collections III. Collection and Iterator IV. Methods of Collection V. Concrete classes VI. Implementation
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationEXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 END YEAR COMP103 Introduction to Data
More informationAP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested.
AP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested. 1. The Nose class... b) will not compile because the m1 method parameter should be named n, not x. 2. The Ears class...
More informationCIS 265 Exam 2 First Name Last Name
CIS 265 Exam 2 First Name Last Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the data types below does not allow duplicates? 1)
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
More informationCOURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE
COURSE 4 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Inheritance Abstract classes Interfaces instanceof operator Nested classes Enumerations COUSE CONTENT Collections List Map Set Aggregate
More informationTopic 10: The Java Collections Framework (and Iterators)
Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of
More informationDecisions in Java IF Statements
Boolean Values & Variables In order to make decisions, Java uses the concept of true and false, which are boolean values. Just as is the case with other primitive data types, we can create boolean variables
More informationAP CS Unit 7: Interfaces. Programs
AP CS Unit 7: Interfaces. Programs You cannot use the less than () operators with objects; it won t compile because it doesn t always make sense to say that one object is less than
More informationCS 314 Exam 1 Fall 2017
Points off 1 2 3 4 5A 5B Total off Net Score CS 314 Exam 1 Fall 2017 Your Name Your UTEID Circle your TAs Name: Gilbert Jacob Jorge Joseph Lucas Rebecca Shelby Instructions: 1. There are 5 questions on
More informationInterfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations.
Interface Interface definition Interface implementation by classes Benefits of interfaces Implementation of multiple interface Java Collection Framework Interfaces An interface defines a set of methods.
More informationSoftware 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface
Java Collections Framework Collection: a group of elements Based Design: Software 1 with Java Java Collections Framework s s Algorithms Recitation No. 6 (Collections) 2 Collection s Online Resources Collection
More informationThe Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss
The Collections API Mark Allen Weiss Lecture Objectives To learn how to use the Collections package in Java 1.2. To illustrate features of Java that help (and hurt) the design of the Collections API. Tuesday,
More informationSETS AND MAPS. Chapter 9
SETS AND MAPS Chapter 9 The set Functions Required methods: testing set membership (find) testing for an empty set (empty) determining set size (size) creating an iterator over the set (begin, end) adding
More informationJava 1.5 in a Nutshell
Java 1.5 in a Nutshell Including Generics, Enumerated Types, Autoboxing/Unboxing, and an Enhanced for Loop http://java.sun.com/j2se/1.5.0/docs/guide/language/ CS 2334 University of Oklahoma Brian F. Veale
More informationTiming ListOperations
Timing ListOperations Michael Brockway November 13, 2017 These slides are to give you a quick start with timing operations in Java and with making sensible use of the command-line. Java on a command-line
More informationCS 101 Exam 1 Spring 200 Id Name
This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your
More informationAP Computer Science Homework Set 5 2D Arrays
AP Computer Science Homework Set 5 2D Arrays Note: all programs described below should work if the size of the 2D array is changed. P5A. Create a 3x4 2D array of integers. Use a nested for loop to populate
More informationCS 307 Final Spring 2010
Points off 1 2 3 4 5 Total off Net Score CS 307 Final Spring 2010 Name UTEID login name Instructions: 1. Please turn off your cell phones. 2. There are 5 questions on this test. 3. You have 3 hours to
More informationCS 101 Exam 2 Spring Id Name
CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,
More informationAdvanced Java Concepts Unit 2: Linked Lists.
Advanced Java Concepts Unit 2: Linked Lists. The List interface defines the structure of a linear collection. Here are some of its methods. boolean add( E element ) Appends the element to the end of the
More informationUnit 4: Classes and Objects Notes
Unit 4: Classes and Objects Notes AP CS A Another Data Type. So far, we have used two types of primitive variables: ints and doubles. Another data type is the boolean data type. Variables of type boolean
More informationPoints off Total off Net Score. CS 314 Final Exam Spring 2017
Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2017 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.
More informationCSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp
CSE 373 Java Collection Framework reading: Weiss Ch. 3, 4.8 slides created by Marty Stepp http://www.cs.washington.edu/373/ 1 Arrays array: An object that stores many values of the same type. element:
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
More informationAP CS Unit 4: Classes and Objects Programs
AP CS Unit 4: Classes and Objects Programs 1. Copy the Bucket class. Make sure it compiles (but you won t be able to run it because it does not have a main method). public class Bucket { private double
More informationImplementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations
Readings List Implementations Chapter 20.2 Objectives Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Additional references:
More informationתוכנה 1 מבני נתונים גנריים
תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationAP Computer Science Homework Set 5 2D Arrays
AP Computer Science Homework Set 5 2D Arrays Note: all programs described below should work if the size of the 2D array is changed. P5A. Create a 3x4 2D array of integers and fill it with random numbers
More informationCS1083 Week 2: Arrays, ArrayList
CS1083 Week 2: Arrays, ArrayList mostly review David Bremner 2018-01-08 Arrays (1D) Declaring and using 2D Arrays 2D Array Example ArrayList and Generics Multiple references to an array d o u b l e prices
More informationCS11 Java. Winter Lecture 8
CS11 Java Winter 2010-2011 Lecture 8 Java Collections Very powerful set of classes for managing collections of objects Introduced in Java 1.2 Provides: Interfaces specifying different kinds of collections
More informationThis exam is open book. Each question is worth 3 points.
This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More informationCSE 143. Lecture 28: Hashing
CSE 143 Lecture 28: Hashing SearchTree as a set We implemented a class SearchTree to store a BST of ints: Our BST is essentially a set of integers. Operations we support: add contains remove... -3 overallroot
More informationCITS1001 week 6 Libraries
CITS1001 week 6 Libraries Arran Stewart April 12, 2018 1 / 52 Announcements Project 1 available mid-semester test self-assessment 2 / 52 Outline Using library classes to implement some more advanced functionality
More informationStudent s Number: This exam consists of 30 multiple choice questions. Mark your answer to each question in the space provided on this page.
CSE 1020.03 page 1 of 12 Student s Name: Student s Number: Student s CSE ID: Student s Instructor This exam consists of 30 multiple choice questions. Mark your answer to each question in the space provided
More informationpublic static<e> List<E> removeoccurrences(list<e> origlist, E remove) {
CS 201, Fall 2008 Nov 19th Exam 2 Name: Question 1. [10 points] Complete the following generic method. It should return a list containing all of the elements in origlist, in order, except the elements
More informationCMSC 202H. Containers and Iterators
CMSC 202H Containers and Iterators Container Definition A container is a data structure whose purpose is to hold objects. Most languages support several ways to hold objects Arrays are compiler-supported
More informationAP CS Unit 6: Inheritance Notes
AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything
More informationUnit 5: More on Classes/Objects Exercises
Unit 5: More on Classes/Objects Exercises AP CS A 1. Select the TRUE statement. a) This does not compile. b) This does compile.. Select the TRUE statement. a) This does not compile. b) This does compile.
More informationCSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationJava Review: Objects
Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation
More informationFirst Name Last Name ID#
CIS 265 Sect 01 - V. Matos Exam-2 Spring-2015 First Name Last Name ID# (15 pts) MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) In the following
More informationCSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:
CSE143 Midterm Summer 2017 Name of Student: Section (e.g., AA): Student Number: The exam is divided into six questions with the following points: # Problem Area Points Score ---------------------------------------------
More informationPolymorphism: Interfaces and Iteration. Fundamentals of Computer Science
Polymorphism: Interfaces and Iteration Fundamentals of Computer Science Outline A shape object hierarchy Classes that extend Versus classes that implements Java interfaces How Java handles multiple-inheritance
More informationInner Classes. CMSC 433 Programming Language Technologies and Paradigms Spring Example: The Queue Class. Example: The Queue Class (cont d)
CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Inner Classes & Iterators Mar. 6, 2007 Inner Classes Classes can be nested inside other classes These are called inner classes Within
More informationEXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:
More informationCSC 321: Data Structures. Fall 2016
CSC : Data Structures Fall 6 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, primary clustering Ø quadratic probing, rehashing Ø chaining HashSet & HashMap
More informationCSCI 261 Computer Science II
CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 9 Sets and Maps Outline Sets and Baby Set Theory Why Maps? Map: Open Addressing Put Implementation Get Implementation
More information1. AVL Trees (10 Points)
CSE 373 Spring 2012 Final Exam Solution 1. AVL Trees (10 Points) Given the following AVL Tree: (a) Draw the resulting BST after 5 is removed, but before any rebalancing takes place. Label each node in
More informationProblem Grade Total
CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages
More informationCSE 331 Final Exam 3/16/15 Sample Solution
Question 1. (12 points, 3 each) A short design exercise. Suppose Java did not include a Set class in the standard library and we need to store a set of Strings for an application. We know that the maximum
More informationPractice Midterm 1. Problem Points Score TOTAL 50
CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the
More informationDIT960 Datastrukturer
DIT960 Datastrukturer suggested solutions for exam 2017-08-17 1. Assume that n is a non-negative integer, that s is an integer set implemented with a hash table and containing at most n elements, that
More informationInstructions. Grading Box 2. /10 4. /10 1. /10 3. /10 5. /10. Total /50
Instructions 1. Write your answers clearly and succinctly. (a) You will receive no point for an unclear answer. (b) There is no additional deduction for a wrong answer. (c) Do not use red ink. 2. No aids
More informationCOMP 110 Programming Exercise: Simulation of the Game of Craps
COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,
More informationKey Java Simple Data Types
AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 8 More Conditional Statements Outline Problem: How do I make choices in my Java program? Understanding conditional statements Remember: Boolean logic
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 8 More Conditional Statements Outline Problem: How do I make choices in my Java program? Understanding conditional statements Remember: Boolean logic
More informationBuilding Java Programs
Building Java Programs Chapter 11 Sets and Maps reading: 11.2-11.3 2 Languages and Grammars 4 Languages and grammars (formal) language: A set of words or symbols. grammar: A description of a language that
More informationToday's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps
Today's Agenda > To give a practical introduction to data structures > To look specifically at Lists, Sets, and Maps > To talk briefly about Generics in Java > To talk about interfaces in Java Data Structures
More information(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?
CSM B Hashing & Heaps Spring 0 Week 0: March 0, 0 Motivation. (a) In the worst case, how long does it take to index into a linked list? Θ(N) (b) In the worst case, how long does it take to index into an
More informationAP Computer Science Chapter 10 Implementing and Using Classes Study Guide
AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within
More informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More informationThe dictionary problem
6 Hashing The dictionary problem Different approaches to the dictionary problem: previously: Structuring the set of currently stored keys: lists, trees, graphs,... structuring the complete universe of
More informationBuilding Java Programs
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading: 11.2-11.3 2 Exercise Write a program that counts the number of unique words in a large text file (say, Moby Dick or the King James
More informationUniversity of Maryland College Park Dept of Computer Science
University of Maryland College Park Dept of Computer Science CMSC132H Fall 2009 Midterm First Name (PRINT): Last Name (PRINT): University ID: I pledge on my honor that I have not given or received any
More informationBIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic
BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines
More informationEXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 MID YEAR COMP103 Introduction to Data
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationHomework 3 Huffman Coding. Due Thursday October 11
Homework 3 Huffman Coding Due Thursday October 11 Huffman Coding Implement Huffman Encoding and Decoding and the classes shown on the following slides. You will also need to use Java s stack class HuffmanEncode
More informationOracle 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam
Oracle 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 1 QUESTION: 1 Given a pre-generics implementation of a method: 11. public static int sum(list list) { 12. int sum = 0; 13.
More informationAns: Store s as an expandable array of chars. (Double its size whenever we run out of space.) Cast the final array to a String.
CMSC 131: Chapter 21 (Supplement) Miscellany Miscellany Today we discuss a number of unrelated but useful topics that have just not fit into earlier lectures. These include: StringBuffer: A handy class
More informationNotes on access restrictions
Notes on access restrictions A source code file MyClass.java is a compilation unit and can contain at most one public class. Furthermore, if there is a public class in that file, it must be called MyClass.
More informationCSC 321: Data Structures. Fall 2017
CSC : Data Structures Fall 7 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, clustering, rehashing Ø chaining Java hashcode method HW6: finite state
More informationBuilding Java Programs
Building Java Programs Generics, hashing reading: 18.1 2 3 Wednesday Notecards Difference between int[] and List? How does HashSet get sorted? 4 Hashing hash: To map a value to an integer index.
More informationReview. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )
Review CSE 143 Java Hashing Want to implement Sets of objects Want fast contains( ), add( ) One strategy: a sorted list OK contains( ): use binary search Slow add( ): have to maintain list in sorted order
More information