DUKE UNIVERSITY
Department of Computer Science
Test 1: CompSci 100e Solutions
PROBLEM 1 :
(Short Ones (18 points)
A. [4pts] For each of the following objectoriented programming terms, summarize the distinction between
the two terms. Your answer should be
DUKE UNIVERSITY
Department of Computer Science
Test 1 Review: CompSci 201
During the test, you may consult your one (1) sheet of notes and no other resources. You may not use any
computers, calculators, cell phones, or other human beings. Your answers may
DUKE UNIVERSITY
Department of Computer Science
Test 1 Solutions: CompSci 100e
PROBLEM 1 :
(Short Ones (30 points)
A. [9pts] For each of the following statements, state whether the statement is true or false and briey
justify your answer.
I. A O(n log n) a
DUKE UNIVERSITY
Department of Computer Science
Test 1 Solutions: CompSci 100e
PROBLEM 1 :
(Short Ones (12 points)
A. Give two distinct advantages of using an ArrayList (e.g. ArrayList<String> list) versus an array
(e.g. String[] a).
1. an ArrayList can gr
CS201 Discussion 12
HUFFMAN + ERDOSNUMBERS
Huffman Compression
Today, well walk through an example of Huffman compression. In Huffman compression, there
are three steps:
1. Create a Huffman tree
2. Get all the encodings from our Huffman tree
3. Encoding t
CS 201 Discussion 9
BSTS + RECURSION
BST review
A binary search tree is:
A tree (a group of nodes, where one is the root and every other node is some other nodes child)
Binary (each node has a left and right child. If no child exists, the child is actua
CS201 Discussion 2
TODAYS TOPIC: A GENERAL APPROACH FOR SOLVING
PROBLEMS IN CS201
Never Lose Your Work!
We are going to quickly teach you how to use Duke Box to back
up your files.
This way, you should never lose your work for this class (or
others) due t
Discussion 1 Getting Started
This discussion is just about getting you up to speed with the tools.
Installing eclipse and ambient
Follow all of the instructions to install eclipse with the ambient plugin. There is a video guide
here that shows the whole p
CS 201 Discussion 5
BIGOH REVIEW
A step by step approach to finding BigOh
runtime
You learned about BigOh in lecture on Friday. Heres a summary of how you can find the BigOh
runtime of a snippet of code.
1. Determine how many steps (assigning variable
Discussion 11
APT REVIEWS AND GRAPH ALGORITHMS
Before we begin
Any questions on Autocomplete? Well have time in discussion where if you were able to
complete APT Set 6 without issue, you can work on Autocomplete, so well be able to tackle
coding questions
CompSci 201 Rocks!
Data Structures
and
Algorithms
Fun before Work
Connect with your neighbors:
Which colleges did you consider?
Why did you choose Duke?
Go to the class webpage under Sakai
CompSci 201
September 2, 2015
Remembering that I'll be dead s
CS201 Discussion 7
MARKOV AND RECURSION
Before we begin
Any questions about the midterm solutions?
Making a Markov Map
Recall that in Markov, were trying to make a map of all kgrams to all kgrams that follow them
in the source text. We also note which k
CS201 Discussion 8
RATROUTE + LINKEDLISTS
RatRoute continued
Last discussion, we talked about how RatRoute, and how the number of paths from any point to
the cheese is the sum of the number of paths from the two adjacent points in the direction of
the che
CS201 Discussion 10
DRAWTREE + TRIES
DrawTree
First instinct: recursion
As a very generic structure, we could tackle this problem as follows:
draw():
Find the root
draw(root)
draw(root):
Write the line for the root
For each child element of root:
draw(chi
CS 201, Test 1 Name:
Net ID:
Discussion Time:
Place:
1. Comm Std (1) 2. Callback (3) 3. Big Oh (15) 4. Analysis (20) 5. Maps (16) 6. Sorting (20) Total (75)
Tip: Use the topics list above to pick topics based on your comfort level. Clearly mark any contin
import java.util.*
delimiter \s+ space, \Z end of file input.useDelimiter(delimiter);
Scanner: newScanner(newFile(sourcefile);Scannerinput=newScanner("bananaman");
System.out.printf ("%8.2f", 10.3456); will print out taking 8 space, with 2 decimal places
CS201 Discussion 4
Debugger, JohnSort
1
Using the Debugger
Ambient help page on the Eclipse Debugger
Eclipse documentation on Debug View
Debugging Advice
Using the Debugger
Using the Debugger
Step Over
Step Into
Step Return
Resume
Terminate
The Debugger I
DUKE UNIVERSITY
Department of Computer Science
Test 2 Solutions: CompSci 100e
PROBLEM 1 :
(Short Ones (9 points)
A. Explain briey (i.e. one sentence can be enough) why the following optimizations are helpful. That is,
why do the listed algorithms provide
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
Control structures: if(Boolean)/else/while/dowhile/for/break
Runtime/Bigoh/Recurrence: loop n times, recurse n
times = O(n), recursion: continuously compute value (ex:
recurrence = T(n/2), for mergesort/combining
multiple=mult*T(N/mult)+cn
Just sort it!:
Eric Tang
CS201 Midterm 2
Sorting

Selection Sort: Find minimum value in array and exchange with first entry, then repeat again
o
Uses N2/2 compares and N exchanges to sort array of length N
Insertion Sort: Insert one entry at a time and compare with exi
CS201 Midterm 2
Sorting
Selection Sort: Find minimum value in array and exchange with first entry, then repeat again
o
Uses N2/2 compares and N exchanges to sort array of length N
Insertion Sort: Insert one entry at a time and compare with existing entrie
DUKE UNIVERSITY
Department of Computer Science
Test 1: CompSci 201
Name (print):
Community Standard acknowledgment (signature):
Problem 1
value
14 pts.
Problem 2
22 pts.
Problem 3
6 pts.
Problem 4
11 pts.
Problem 5
17 pts.
TOTAL:
70 pts.
grade
This test h
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
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
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
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