Java review
part 1: classes & objects
Objects
Data structures literally, storage containers
for data constitute object knowledge
Operations an object can perform on data are
its actions
Object know
Graphs II:
Trailblazing
Paths
In an undirected graph, a path of length n
from u to v, where n is a positive integer, is a
sequence of edges e1, , en of the graph such
that f(e1)=cfw_x0,x1, f(e2)=cfw_
Graphs
The ultimate data structure
graphs
1
Definition of graph
Non-linear data structure consisting of
nodes & links between them (like trees in
this sense)
Unlike trees, graph nodes may be
completel
B-trees:
Theyre not just binary anymore!
btrees
1
The balance problem
Binary search trees provide efficient search
mechanism only if theyre balanced
Balance depends on the order in which
nodes are a
Binary Trees
trees
1
Basic terminology
Finite set of nodes
(may be empty - 0
nodes), which
contain data
First node in tree is
called the root
trees
2
Basic terminology
Each node may be
linked to 0,
Queues II:
Applications
queues2
1
Palindrome recognition
Palindrome: collection of characters that
reads the same backwards and forwards
Examples:
otto is a palindrome
34543 is a palindrome
snub
Queues
Data structures that wait their turn
queues
1
Queue characteristics
FIFO: first in, first out
insertion of items occurs at one end,
removal occurs at the other end
first item inserted is the
Stacks II
Adventures in Notation
stacks2
1
The trouble with infix .
Rules for expression evaluation seem
simple - evaluate expression left to right,
results of each sub-expression becoming
operands t
Stacks
The unorganized persons data
structure
stacks
1
Stack characteristics
Entries are ordered in terms of access -both insertion and removal take place at
same spot (top of stack)
Specialized typ
Generic Programming
*Really* reusable code
First, a bit of history
Since Java version 5.0, Java has borrowed a page
from C+ and offers a template mechanism,
allowing programmers to create data struc
Linked Lists II
The rest of the story
linklist2
1
Adding/removing in the middle
of a list, part deux
Up to now, we have performed operations
on nodes in the middle of a list with a
crucial assumption
Linked Lists
Its a conspiracy!
1
Linked list: a data structure used
to represent an ordered list
Consists of a sequence of nodes
A node consists of a data item and a
reference to the next node - the
Container Classes
Bags & Sequences
containers
1
Operations on a Bag
Constructors
default: creates bag with capacity of 10
with int argument: creates bag with specified
capacity
containers
2
Operati
Hashing II:
The leftovers
hashing2
1
Hash functions
Choice of hash function can be important
factor in reducing the likelihood of
collisions
Division hashing: key % CAPACITY
Certain table sizes are
Recursion
just in case you didnt love
loops enough
Recursion
A recursive method is a method that
contains a call to itself
Often used as an alternative to iteration
when iteration is awkward or in
Hashing
Its not just for breakfast anymore!
hashing
1
Hashing: the facts
Approach that involves both storing and
searching for values
Behavior is linear in the worst case, but
strong competitor with
Algorithm Analysis & Program
Testing
An introduction
bigointro
1
Time Analysis: reasoning about
speed of algorithm
Need to decide how time will be measured
actual performance time: not always accura
Time & Date Representation in
Java
Date class
An object of type Date represents an instance in
time
Part of java.util.* (requires import statement)
A new Date object is automatically set to the tim
Class design guidelines
Most of this material comes from
Horstmann, Cay: Object-Oriented
Design & Patterns (chapter 3)
1
Encapsulation
Classes can be implemented many different
ways
each has advanta
Arrays in Java
data in bulk
Array
Homogeneous collection of elements
all same data type
can be simple type or object type
Each element is accessible via its index
(random access)
Arrays are, loos
Sample Final Exam
1) Convert each of the following expressions into its equivalent prefix, postfix or infix expressions (in
other words, provide the alternatives to the one given):
a) prefix expressio
Sample Exam 2
1. Consider the array below, in its initial state. Arrays A and B represent the same array after four data items
have been sorted using one of the sorting algorithms discussed in class.