Docsity

CS2110 Final Exam Preparation, Study notes of Algorithms and Programming

Toggle sidebar
bg1
CS#2110.######################################Final#9:00-11:30,#Tuesday,#17#May,#Barton#Hall#Center#
The CS2110 Final is optional. As soon as possible, we
will post grades for A8 and tentative course letter
grades. You will answer a 1-question assignment on the
CMS: Do you accept the letter grade or will you take
the final? This question will become available at the
same time that we post the tentative letter grades.
If you walk into the final room, you must complete the
final. For example, you may not decide half way
through the final that you don’t want to take it.
A few students missed one of the two prelims and are
required to take the final unless other arrangements have
been made.
Taking the final may lower or raise your course grade.
Our past experience: taking the final changes the letter
grade for very few —fewer than 10 in a course of 200,
mostly raises.
Conflicts. If there is a chance you may take the exam
and you have a conflict, please email Megan Gatch,
[email protected], immediately. How we handle con-
flicts depends on how many conflicts there are. We de-
fine “conflict” as having another final at the same time
or having more than two finals within a 24-hour period,
thus following university policy.
Quiet room / extra time. If Cornell allows you extra
time or a quiet room for the exam, please email Megan
Gatch, mlg34@cornell.edu, so that we know how many
there are of you. Room: TBA.
Review session: Java. Fri , 13 May. 10AM. Gates G01
Review session: Data structures, algorithms, concurren-
cy. Fri , 13 May.11AM. Gates G01
Overall length and balance of the exam. Similar to
past CS2110 exams, but it will be 150 minutes long.
Piazza note @472, Supplemental Study Notes, contains
material that will be useful in studying for the final.
Everything that could be on P1 or P2 could be on the
final. We spell this out in more detail below.
Programming. Being able to write correct code in Java
is absolutely critical. You should have skill in using
arrays, Strings, loops (while, for, and for-each), writing
procedures, functions, constructors, etc. You will be
asked to write at least one recursive method.
JAVA. Know the basics of Java. Use the summary giv-
en for both prelims and the JavaSummary (ppt slides)
on the course website. You may be asked about any-
thing in these references, including access modifiers,
abstract classes, and interfaces. In addition, know about
inner classes, nested static classes, and enums. You will
not be asked questions about reading/writing files. See
the P1 and P2 review handouts for more details.
Java Collection Hierarchy. Basic understanding of
how to use Collection<T>, List<T>, Set<T>, Ar-
rayList<T>, HashSet<T>, and HashMap<T>. Know the
basic methods in each, including their expected and
worst-case runtimes: how to create an object of that
class, add an element, remove an element, determine the
size (number of elements). If a question requires any
methods other than the basic ones, they will be given to
you.
Specific Java Interfaces. Be able to use interface
Comparable (what method is required?).
Know that if a Collection or one of its subinterfaces/
subclasses implements interface Iterable, the foreach
statement (e.g. for (Integer d : arraylistofinteger) {…})
can be used to iterate over such collections.
Know how to use interface Iterator<T>.
GUIs: Know the three basic things needed to be able to
listen to some event: (1) implement a particular inter-
face, which means, (2) writing the method that will be
called when the event happens, and (3) registering an
object that contains the method with the component on
which the event occurs.
We do not expect you to remember the interface and
method needed for each kind of event. It’s the overall
process, the concept, that is important.
Analysis of algorithms. Big-O complexity notation, the
definition of O(f(n)). Definition of best-case, worst-
case, and expected (average) case order of execution.
The notion that this may count execution not of every
statement but of crucial actions (e.g. number of array
comparisons, number of array-element swaps).
Proofs. Rigorous arguments for establishing the big-O
complexity of algorithms. Be prepared to show that an
algorithm is correct through clear logical reasoning.
Searching. Linear search. Binary search in an ordered
array. Be able to write these. Know their expected- and
worst-case time.
Sorting. Understand the following sorting methods,
their worst-case and expected-case execution times, and
their space complexity: insertion sort, selection sort,
merge sort, quick sort, heap sort. Be able to write each
of these, perhaps leaving parts of the algorithms in Eng-
lish (see end of this review for what we expect).
Concept of stable sorting.
Lower bound for comparison sorts. NOT ON FINAL
Abstract data types (ADTs). An ADT is just a set of
values together with (primitive, or predefined) opera-
tions on them and the idea that we may expect the prim-
itive operations to have certain properties, e.g. O(1) cost
and O(n) space. How we can define an ADT in Java by
pf3

Partial preview of the text

Download CS2110 Final Exam Preparation and more Study notes Algorithms and Programming in PDF only on Docsity!

The CS2110 Final is optional. As soon as possible, we will post grades for A8 and tentative course letter grades. You will answer a 1-question assignment on the CMS: Do you accept the letter grade or will you take the final? This question will become available at the same time that we post the tentative letter grades_._ If you walk into the final room, you must complete the final. For example, you may not decide half way through the final that you don’t want to take it. A few students missed one of the two prelims and are required to take the final unless other arrangements have been made. Taking the final may lower or raise your course grade. Our past experience: taking the final changes the letter grade for very few —fewer than 10 in a course of 200, mostly raises. Conflicts. If there is a chance you may take the exam and you have a conflict, please email Megan Gatch, [email protected], immediately. How we handle con- flicts depends on how many conflicts there are. We de- fine “conflict” as having another final at the same time or having more than two finals within a 24-hour period, thus following university policy. Quiet room / extra time. If Cornell allows you extra time or a quiet room for the exam, please email Megan Gatch, [email protected], so that we know how many there are of you. Room: TBA. Review session : Java. Fri , 13 May. 10AM. Gates G Review session : Data structures, algorithms, concurren- cy. Fri , 13 May.11AM. Gates G Overall length and balance of the exam. Similar to past CS2110 exams, but it will be 150 minutes long. Piazza note @472, Supplemental Study Notes , contains material that will be useful in studying for the final. Everything that could be on P1 or P2 could be on the final. We spell this out in more detail below. Programming. Being able to write correct code in Java is absolutely critical. You should have skill in using arrays, Strings, loops (while, for, and for-each), writing procedures, functions, constructors, etc. You will be asked to write at least one recursive method. JAVA. Know the basics of Java. Use the summary giv- en for both prelims and the JavaSummary (ppt slides) on the course website. You may be asked about any- thing in these references, including access modifiers, abstract classes, and interfaces. In addition, know about inner classes, nested static classes, and enums. You will not be asked questions about reading/writing files. See the P1 and P2 review handouts for more details. Java Collection Hierarchy. Basic understanding of how to use Collection, List, Set, Ar- rayList, HashSet, and HashMap. Know the basic methods in each, including their expected and worst-case runtimes: how to create an object of that class, add an element, remove an element, determine the size (number of elements). If a question requires any methods other than the basic ones, they will be given to you. Specific Java Interfaces. Be able to use interface Comparable (what method is required?). Know that if a Collection or one of its subinterfaces/ subclasses implements interface Iterable, the foreach statement (e.g. for (Integer d : arraylistofinteger) {…}) can be used to iterate over such collections. Know how to use interface Iterator. GUIs : Know the three basic things needed to be able to listen to some event: (1) implement a particular inter- face, which means, (2) writing the method that will be called when the event happens, and (3) registering an object that contains the method with the component on which the event occurs. We do not expect you to remember the interface and method needed for each kind of event. It’s the overall process, the concept, that is important. Analysis of algorithms. Big-O complexity notation, the definition of O(f(n)). Definition of best-case, worst- case, and expected (average) case order of execution. The notion that this may count execution not of every statement but of crucial actions (e.g. number of array comparisons, number of array-element swaps). Proofs. Rigorous arguments for establishing the big-O complexity of algorithms. Be prepared to show that an algorithm is correct through clear logical reasoning. Searching. Linear search. Binary search in an ordered array. Be able to write these. Know their expected- and worst-case time. Sorting. Understand the following sorting methods, their worst-case and expected-case execution times, and their space complexity: insertion sort, selection sort, merge sort, quick sort, heap sort. Be able to write each of these, perhaps leaving parts of the algorithms in Eng- lish (see end of this review for what we expect). Concept of stable sorting. Lower bound for comparison sorts. NOT ON FINAL Abstract data types (ADTs). An ADT is just a set of values together with (primitive, or predefined) opera- tions on them and the idea that we may expect the prim- itive operations to have certain properties, e.g. O(1) cost and O(n) space. How we can define an ADT in Java by

declaring an interface. Know the meaning of amortizing the cost of an operation. Knowledge of particular ADTs. Know the following ADTs and their basic operations: stack, queue, set, pri- ority queue, heap. Be able to design and write: An implementation of a stack in an array; an implementation of a queue in an array using wraparound, so that removing the first and putting something at the end are constant time opera- tions; an implementation of a heap and priority queue in an array. Linked lists. Describe the data structure used to imple- ment singly linked lists, doubly linked lists, and circular lists, and each of these with a header. Know the ad- vantages of each. Be able to write code on how to insert or delete an element. Hashing. The idea of a hash function and the basic idea of hashing. Solving collisions using linear or quadratic probing; why, when using such probing, one can’t simp- ly remove an element by setting the array element in which it appears to null. Load factor, and the fact that if it is ½, at most 2 probes are expected in searching for a value. Chaining (solving collisions using a linked list of values that hash to the same address). Trees. Definition of a tree and the general terminology associated with trees —node, child, sibling, parent, leaf, etc. Notion of a balanced tree. Data structures to implement trees. Be able to write a tree traversal —both breadth-first and depth-first. Be able to write code to perform operations on trees, such as finding the depth of tree, finding an element, etc. Binary search trees (BSTs): Definition. Write algorithm to search a BST for a value, know its order of execution time. Graphs. Two major data structures for a graph: adja- cency matrix and adjacency list. Advantages/ disad- vantages of each (in terms of the complexity of the primitive graph operations). Topological sorting of a DAG. Bipartite graphs and vertex coloring. Be able to code breadth-first and depth-first search and understand when each is useful. Dijkstra’s shortest path algorithm. While we will not ask you to write it, we may ask you questions about it —e.g. for a node w in each of the three sets of nodes, what does L[w] contain? What is its loop invariant? For a connected graph of n nodes, what is the order of exe- cution of the algorithm? What data structure do you use for one of the sets to achieve it? Which representation of the graph leads to a better execution time – adjacency matrix or adjacency list? Minimal spanning trees. Be able to express Prim’s algorithm and Kruskal’s algorithm at a high level – not an implementation —how do they pick the next edge to add to the spanning tree? Understand key concepts that arise when proving the correctness of programs. Know what we mean by specifications, preconditions, postconditions, the Hoare triple, and invariants (class invariant, loop invariant). Be familiar with the lectures that used these terms and be able to answer questions about them. If the pre- and post-conditions are given by array diagrams (as we did for selection sort, partition algorithm, etc.), be able to draw a diagram that generalizes the pre- and post- condition —as a possible invariant. Concurrency. Be familiar with two issues seen when two or more threads of execution are running concur- rently, perhaps both referring to and changing shared variables: race conditions and deadlock. Java implementation of threads. Know how one cre- ates a thread and starts it running. Be able to use key- word familiar synchronized and the methods wait, noti- fy, and notifyAll within a synchronized block. Under- stand the bounded-buffer problem as discussed in lec- ture. Be prepared to edit existing code using keyword syn- chronized to make it thread safe.