Primitives (values are stored in memory)
 char
 int
 boolean
 double
HashSet is backed up by a Hashing scheme
Collections
 Lists
 Sets

Maps
Hashing

A search method
Average case O(1) search
Associate a number with every key, use the number to sto
Linkedlist vs ArrayList
https:/docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
int: By default, the int data type is a 32bit signed two's complement integer, which has a minimum value of
231 and a maximum value of 2311.
float: The floa
DUKE UNIVERSITY
Department of Computer Science
Test 2 Solutions: CompSci 100e
PROBLEM 1 :
(Hash (6 pts)
In the Markov assignment, the WordNgram class encapsulated N words/strings so that the group of N words
can be treated as a key in a map.
public class
Plan for Today
Tries for Autocomplete
Binary Tree Review
Acknowledgements
Notes from Arun Ganesh
Using tries for autocomplete
To completely eliminate our
dependence on the terms which dont
start with our prefix, lets use a trie
instead of an array to
Final Exam Review Questions
PROBLEM 1 :
(Short ones (14 points)
1. For each of the following methods and data structures in the matrix below, give the BigOH. If worstcase and
averagecase are different, note that.
search
insert
delete
findMin
unsorted A
DUKE UNIVERSITY
Department of Computer Science
Test 2 Solutions: CompSci 100e
PROBLEM 1 :
(Short Ones (9 points)
A. Explain briefly (i.e. one sentence can be enough) why the following optimizations are helpful. That is,
why do the listed algorithms provid
DUKE UNIVERSITY
Department of Computer Science
Test 2 Solutions: CompSci 100e
PROBLEM 1 :
(Short Ones (18 points)
In each of following, describe a scenario where one Java library (java.util) class is preferable to another.
For full credit, you should refe
DUKE UNIVERSITY
Department of Computer Science
Test 2 Review Questions
PROBLEM 1 :
(Short Answer)
A. In order to use the class Point containing fields x and y in a HashSet, you are considering multiple hash
functions. Of these hash functions, which one wo
Test 2
NetID:
13
Throughout this test, assume that the following classes and methods are available. These classes are taken
directly from the material used in class. There should be no methods you have never seen before here.
Definitions
public boolean eq
Comp Sci 1: Sample Final
Page 1 of 15
Comp Sci 1: (Sample) Final Exam
CLOSED BOOK
90 min Final Exam
NAME_Net ID_
DISCLAIMER!
This is a sample final used previously. You can use it to see the kind
of questions you might find. Absence of items on this final
Discussion 10:
Autocomplete
Slides adapted from Arun Ganesh
1
Assignment Overview
In this assignment, you will be completing the following three classes:
Term.java
BinarySearchAutocomplete.java
TrieAutocomplete.java
In doing so, you will practice the f
A SSIGNMENT 7
C OURSE : COMPSCI 330
Due on March 6th, 2017
55 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each step
of the procedure, establish its correctness, and then analyze its overall running
A SSIGNMENT 9
C OURSE : COMPSCI 330
Due on April 3rd, 2017
105 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each step
of the procedure, establish its correctness, and then analyze its overall running
A SSIGNMENT 6
C OURSE : COMPSCI 330
Due on February 27th, 2017
60 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall runn
A SSIGNMENT 10
C OURSE : COMPSCI 330
Due on April 17th, 2017
50 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each step
of the procedure, establish its correctness, and then analyze its overall runnin
A SSIGNMENT 8
C OURSE : COMPSCI 330
Due on March 22th, 2017
55 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each step
of the procedure, establish its correctness, and then analyze its overall running
A SSIGNMENT 3
C OURSE : COMPSCI 330
Due on February 1, 2017
60 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall running
A SSIGNMENT 5
C OURSE : COMPSCI 330
Due on February 15th, 2017
30 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall runn
A SSIGNMENT 4
C OURSE : COMPSCI 330
Due on February 8th, 2017
30 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall runni
A SSIGNMENT 1
C OURSE : COMPSCI 330
Due on January 18, 2017
20 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall running
A SSIGNMENT 2
C OURSE : COMPSCI 330
Due on January 25, 2017
30 points total
General Directions: If you are asked to provide an algorithm, you should clearly define each
step of the procedure, establish its correctness, and then analyze its overall running
DUKE UNIVERSITY
Department of Computer Science
Test 1 Solutions: CompSci 201
PROBLEM 1 :
(Short Ones (14 points)
A. [9pts] Give brief examples where one would be more appropriate that the other.
For example
Data structures: HashSet vs. TreeSet
HashSet: l
What Is an Object?
An object is a software bundle of related state and behavior. Software objects are often used to model the
realworld objects that you find in everyday life. This lesson explains how state and behavior are represented
within an object,
Plan for the week
Recursion
Linked Lists
Directories
APTs
TypingJob, SpreadingNews, etc.
DNA for Discussion
Setup for Autocomplete/Trees
Tools: Solving Computational Problems
Algorithmic techniques and paradigms
Bruteforce/exhaustive, greedy alg
Discussion 2
Review (515 minutes)
Questions about NBody or git installation?
Pick 12 groups to discuss their solution to avgValuesInFile from FileIntro.java
Review Java documentation for the following classes:
Scanner
StdDraw
Scanner (515 minutes)
1
Discussion 2
Review (515 minutes)
Questions about NBody or git installation?
Pick 12 groups to discuss their solution to avgValuesInFile from FileIntro.java
Review Java documentation for the following classes:
Scanner
StdDraw
Scanner (515 minutes)
1
Plan for This week
Recursion & Recurrences
Binary Trees
Autocomplete
Binary Search
Tries
Toward understanding rats and
cheese
http:/www.cs.duke.edu/csed/newapt/ratroute.html
Key Ideas here
Create a twod char[][] array for the board
Find cheese and