import java.util.Scanner;
import java.io.*;
/*
* Rishab Chhabra
* 109 622 927
* Homework 4
* R04
* Gustavo Poscidonio
* Mahsa Torkaman
* @author Rishab
*/
public class Kiosk
cfw_
private static boolean loaded;
/*
* Runs a basic menu to set up and use a ki
CSE214 COMPUTER SCIENCE II
SAMPLE MIDTERM EXAM
1. For each of the following algorithms performed on a collection of n integers, write down its
worst-case order of complexity as a function of n in simplified Big O notation. Assume that
the most efficient d
Order of Complexities
1. Arrays, ArrayLists, LinkedLists
Find element by index
Find element by value
Clone a list
Array
O(1)
O(n)
O(n)
Add element to interior
Remove element from
interior
Add element to end
Remove element from end
ArrayLi
st
O(1)
O(n)
O(n
The Patriot Act
Do you want to donate your
freedom for your safety?
Do you want your private
information expose to
government?
Introduction
TheUSA PATRIOT Act:
anAct of Congress
signed into law byPresidentGeorge W. Bush
on October 26, 2001
Its title
Assignment 4
CSE 214
This assignment is about using dierent ways of sorting a given set of objects. To illustrate how
the same objects can be sorted in dierent ways, you are required to rst implement a class called
Laptop. Each laptop instantiated by this
Splay Trees
Lecture 26
Steven S. Skiena
What about non-uniform access?
AVL/red-black trees give us worst case
query and update operations, by
keeping a balanced search tree. But when I access with non-uniform probability, a
skewed tree might be better:
I
Midterm Exam
Name: Signature:
ID #: Section #:
INSTRUCTIONS:
You may use either pen or pencil.
Check to see that you have 5 exam pages plus this cover (6 total).
Look over all problems before starting work.
Your signature above signs the CSE 214 Honor
Midterm Exam
Name: Signature:
ID #: Section #:
INSTRUCTIONS:
You may use either pen or pencil.
Check to see that you have 4 exam pages plus this cover (5 total).
Look over all problems before starting work.
Your signature above signs the CSE 214 Honor
AVL Trees
Lecture 24
Steven S. Skiena
AVL Trees
An AVL tree is a binary search tree in which the heights of the left and right subtrees
of the root differ by at most 1, and the left and right subtrees are again AVL trees.
Therefore, we can label each node
Red-Black Trees
Lecture 25
Steven S. Skiena
Red-Black Tree Definition
Red-black trees have the following properties:
1. Every node is colored either red or black.
2. Every leaf (NIL pointer) is black.
3. If a node is red then both its children are black.
Sequential and Binary Search
Lecture 19
Steven S. Skiena
Sequential Search
The simplest algorithm to search a dictionary for a given key is to test successively
against each element.
This works correctly regardless of the order of the elements in the list
Priority Queues and Heapsort
Lecture 18
Steven S. Skiena
Who's Number 2?
In most sports playoffs, a single elimination tournament is used to decide the
championship.
The Marlins were clearly the best team in the 1997 World Series, since they were the
only
Mergesort and Quicksort
Lecture 17
Steven S. Skiena
Faster than O(
) Sorting?
Can we find a sorting algorithm which does significantly better than comparing each
pair of elements? If not, we are doomed to quadratic time complexity.
Since sorting large num
Tree Structures
Lecture 21
Steven S. Skiena
Trees
`I think that I shall never see a poem as lovely as a tree.
Poems are wrote by fools like me, but only G-d can make a tree.'
- Joyce Kilmer
We have seen many data structures which allow fast search, but no
Arrays and Access Formulas
Lecture 20
Steven S. Skiena
One-dimensional Arrays
The easiest way to view a one - dimensional array is as a contiguous block of memory
locations of length (# of array elements) (size of each element)
Because the size (in bytes)
Hashing
Lecture 21
Steven S. Skiena
Hashing
One way to convert form names to integers is to use the letters to form a base
`alphabet-size' number system:
To convert `STEVE' to a number, observe that e is the 5th letter of the alphabet, s is
the 19th lette
Recursion
CHAPTER 8
Definitions/Basics
A method is called a recursive method if it calls itself.
Every recursive method should have a base case (a.k.a stopping
case).
The base case cannot be recursive.
Without a base case, we will have what is called
Hv Ame uoHEmv Q76:
my AN Emu mgr;
5 a 3 E
8 Am Emu moH<o H9 2 3 >2 H H m can >L
my 3 E3 HuHEH HE 82585 5532 OH. > swim :5 9: 59.3
0v 3 33 078 w HESAH Haw b v. mmmism v. H N
H
a G Emu 508350 :5 on8<ch8 mEH 050300.83 OH. x
H
Binary Search Trees
The bad things about what we know
Arrays
Fixed size
Inserting a new element requires shifting all subsequent elements by 1.
Once the array is full, insertion of new elements is not possible.
Linked Lists
Accessing the "# element
TREES
Tree Structure
A tree structure is a way of representing hierarchical data.
In computer science, a tree is an abstract data type that simulates this.
The data structure is defined recursively.
A tree consists of nodes.
Each node consists of (i)