Lecture Notes 12
Priority Queues
Reference: Data Structures and Algorithm Analysis, C. Shaffer,
pp. 170171, 180187.
Priority Queues
Problem: We want a data structure that stores records as they
come (insert), but on request, releases the record with the g
Lecture Notes 2
Recursion
A recursive definition is one which uses the word being defined in
the definition.
Such definitions are very useful in many areas of computer
science.
We will see that it is a powerful programming tool.
We will explore recurs
Lecture Notes 5
Algorithm Analysis
Ref: Data Structures and Algorithm Analysis, C. Shaffer, chapter
3.
Algorithm Efficiency
There are often many approaches (algorithms) to solve a problem.
How do we choose between them?
At the heart of computer program de
Lecture Notes 14
Sorting (cont.)
Reference: Data Structures and Algorithm Analysis, C. Shaffer,
pp. 253256.
Sorting (cont.)
14-2
Sorting Lower Bound
We would like to know a lower bound for all possible sorting
algorithms.
Sorting is O(n log n) (average, w
Lecture Notes 3
Polymorphism
Ref: Lewis & Loftus Java Software Solutions, Ch. 9.
Polymorphism is an object-oriented concept that allows us to create
versatile software designs
We will cover:
defining polymorphism and its benefits
using inheritance to cr
Lecture Notes 4
Math background
Ref: Data Structures and Algorithm Analysis, C. Shaffer, chapter
3.
Set concepts and notation
Common functions
Proofs
Summations
Recurrence Relations
Math background
Set notations
cfw_7, 2, 8 The set consisting of the
CIS 114, Fall 2014
Practice problems
Prof. J. Calvin
Notes:
You may refer to algorithms, data structures, and results that
we covered in class.
When asked to describe an efficient algorithm, you may give
an algorithm that is efficient in either the aver
Lecture Notes 10
Dictionaries
Ref: Data Structures and Algorithm Analysis, C. Shaffer, pp.
131137.
Often want to insert records, delete records, search for records.
Required concepts:
Search key: Describe what we are looking for
Key comparison
Equality
Lecture Notes 7
Node Lists
Node List ADT
The Node List ADT models a sequence of positions storing
arbitrary objects
It establishes a before/after relation between positions
Generic methods:
size(), isEmpty()
Node Lists
Accessor methods:
getFirst(), ge
Lecture Notes 9
Queues
Ref: Data Structures and Algorithm Analysis, C. Shaffer, pp.
125130.
Queues
The Queue ADT
The Queue ADT stores arbitrary objects
Insertions and deletions follow the first-in first-out scheme
Insertions are at the rear of the queu
Basic AFS commands
The following commands should be more than enough for our purposes. If you
want more information on one of these commands, or any other, the man command
will provide it. For example, type
man ls
to get all the options and information ab
Lecture Notes 11
Binary (Search) Trees
Reference: Data Structures and Algorithm Analysis, C. Shaffer,
pp. 145153, 163170.
Binary Trees
A binary tree is made up of a finite set of nodes that is either empty
or consists of a node called the root together wi
Lecture Notes 1
Introduction
Ref: Data Structures and Algorithm Analysis, C. Shaffer, pp.
320.
Introduction
1-2
Goals of this Course
1. Learn the commonly used data structures and algorithms.
2. These form a programmers basic toolkit.
3. Understand how to
Prof. J. M. Calvin
New Jersey Institute of Technology
A Public Research University
The Master of Science in
Computational Biology
Course Information
email: [email protected]
Office: GITC 4311
web: http:/web.njit.edu/calvin
Office Hours: Tue. 3:10-3:55, Th.
Lecture Notes 13
Sorting
Reference: Data Structures and Algorithm Analysis, C. Shaffer,
pp. 223257.
Sorting
Each record contains a field called the key.
Linear order: comparison.
Measures of cost:
Comparisons
Swaps
Sorting
Priority Queue Sort
To sort ar
Lecture Notes 8
Stacks
Ref: Data Structures and Algorithm Analysis, C. Shaffer, pp.
117124.
The Stack ADT
The Stack ADT stores arbitrary objects
Insertions and deletions follow the last-in first-out scheme
Think of a spring-loaded plate dispenser
Main
import random
def getPlayerNames():
' Prompt the two players for their names and return
these two strings.'
print()
player1 = input('Name of first player: ')
player2 = input('Name of second player: ')
return player1, player2
def boardSetup(boardSize, numT
import random
def getPlayerNames():
' Prompt the two players for their names and return
these two strings.'
print()
player1 = input('Name of first player: ')
player2 = input('Name of second player: ')
return player1, player2
def boardSetup():
boardSize =
' Trapdoors & Catapults is a digital version of Chutes & Ladders.
RULES:
PLAYERS. There are two players. Humans are prompted for two names, but
all subsequent action is handled by the program.
BOARD. The board consists of spaces numbered 0 through 99.
Ten
Honors Introduction To Computer Science II
CS 114H
Practice Exam
Practice Practice
Practice
Do not open this exam until instructed to do so. The exam consists of 6 problems. Please check that you
have all the pages.
The answers to the exam problems should
CIS 114, Fall 2014
Practice problems
Prof. J. Calvin
Notes:
You may refer to algorithms, data structures, and results that
we covered in class.
When asked to describe an efficient algorithm, you may give
an algorithm that is efficient in either the aver