• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/79

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

79 Cards in this Set

  • Front
  • Back
What is Polymorphism?
Permits parent class to dynamically take behaviour of descendent class
What does Method Overloading do?
Allows there to be two methods with the same name but different signatures
What is the algorithm for rotating a binary tree root to the right

1. copy root.left --> temp


2. set root.left --> temp.right


3. set temp.right --> root


4 set root --> temp

What does the static keyword mean?
static means that the method or class belongs to the TYPE and not the INSTANCE of a class. A static member cannot be referenced through an instance. Instead it is referenced through the type name
What does the override keyword mean?
The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method property
What is an Interface?
An interface contains only the signatures of methods properties

a class can only have...

one parent class

a child class exhibits AT LEAST...

the same behaviour as the parent class

A class can implement multiple...

interfaces

A class MUST implement all methods defined in the

interface

What is Stack topIndex when the stack is empty?

-1

How does the Stack work? What are its main methods?

LIFO: last in, first out


OR


FILO: first in, last out




Methods:


Push(T item): adds item to top of stack


Pop(): grabs item from top of stack


Peek: returns top item of stack

How does a Queue work? What are its main methods?

FIFO: first in, first out


OR


LILO: last in, last out




Methods:


Offer : adds element to back of queue


Peek: returns element at front of queue


Poll: takes element at front of q

What is a Hash Table

Data structure that maps keys to values

How does the hashing of a Hash Table work?

Distributes key/value pairs across an array of buckets




hash = hashfunc(key)


index = hash % array_size




`hash` is independent of array size, and is reduced to an index (number between 0 and array_size - 1) using modulo operator

Why is does the hash table use modulo with prime numbers?

when you're repeating over a set space, you're going to provide an even distribution across your hash space.

What is a binary heap?

A tree-based data structure where each row is filled out from left to right. The goal is to fully saturate all rows.

What are the two types of binary heaps?

Max Heap: value of each node is less than or equal to its parent (largest value at root)




Min Heap: value of each node is greater than or equal to its parent (smallest value at root)

Given a binary heap stored in an array and an element at position n, how do you find its parent?

n / 2

Given a binary heap stored in an array and an element at position n, how do you find its left child?

2 * n

Given a binary heap stored in an array and an element at position n, how do you find its right child?

2 * n + 1

First 10 prime numbers (for hash tables)

2, 3, 5, 7, 11, 13, 17, 19, 23 and 29

What is the IComparable interface?

Defines a generalized comparison method for classes

How should you implement the IComparable interface?

Generally, return an integer (1, 0, -1) to show the sorted order of two instances of the same class




-1 = this.object precedes object being compared to


0 = equal


1 = this.object is greater than object being compared to




public int CompareTo(Item other)


{


if (this.Number < other.Number)


return -1;


else if (this.Number == other.Number)


return 0;


else if (this.Number > other.Number)


return 1;


}

How does Binary Heap array implementation work



How does Binary Heaps Delete/Percolate Down work?

(assuming max heap)




1. Delete root node


2. Take element at bottom, right-most position and place it at root


3. Compare new root with children, swap if out of order


4. Continue until correct order

How does a Fix Heap/Heap Sort work with the Binary Heap?

It is a recursive Delete and Percolate down operation to return a sorted array.




1. Delete root and place in array


2. Perform Percolate Down to find next root in correct order


3. Continue steps 1 and 2 until heap is empty


4. Return the sorted array

What is a binary tree

Simple tree data structure that is either:




a) empty


b) a node with a left and right binary tree

How does a pre-order traversal work?

1. Root


2. Descent left subtree


3. Descent right subtree

How does post-order traversal work?

1. Ascend left subtree


2. Ascend right subtree


3. Root

How does in-order traversal work?

1. Descend left subtree

2. Root


3. Descend right subtree


What is the definition of a Binary Search Tree?

All values in the left subtree are less than the root value




All values in the right subtree are greater than the root value

How to perform insert in a Binary Search Tree?

1. Start at root


2. If new node smaller than current node, go left. Otherwise go right


3. If we reach a node with no children (a leaf node), insert new node to the left if smaller, insert new node to the right if larger

What are the three cases for Deletion in a Binary Search Tree?

1. If the node has no children, remove it


2. If the node has 1 child, remove the node and replace it with its child


3. If the node has 2 children, find the smallest node in the right subtree and replace deleted node with this node.

What are the properties of a Red Black Tree?

It is a self-balancing Binary Search Tree




1. Every node is Red or Black


2. Root node is Black


3. All leaf (nil) nodes are Black


4. If a node is Red, both of its children are Black


5. The path from any node to a descendant nil node MUST have the same number of black nodes (this is called the Black Height)






All operations (Insert, Delete etc) are performed like it is a Binary Search Tree, after operation is complete, you then rebalance the tree to satisfy the properties above.

Red Black Tree Balancing: What is Case 1?

Case: Uncle of the new node is Red




Solution: Recolor!


-Grandparent becomes Red


-Parent and Uncle become Black

Red Black Tree Balancing: What is Case 2?

Case: Uncle is Black, Parent is a Right Child




Solution: Left rotate around parent of new node




This then leads to Case 3 for more rebalancing

Red Black Tree Balancing: What is Case 3?

Case: Uncle is Black, New Node is a Right Child




Solution:


-Parent and Grandparent of new node become Black


-Right rotate around Grandparent

In general, what are the steps for Binary Search?

*assume array is ordered lowest to highest




1. Given a target, X


2. Find the midpoint of the array with equation: (low + high) / 2


3. If X == midpoint, return true


4. If X < midpoint, recursive call to binary search on the subarray of the midpoint to the last element


5. If X > midpoint, recursive call to binary search on the subarray of the first element to the midpoint

Algorithm for balancing a LL tree

rotate parent right

Algorithm for balancing a LR tree

1. rotate child left


2. rotate parent right

Algorithm for balancing a RR tree

rotate parent left

Algorithm for balancing a RL

1. rotate child right


2. rotate parent left

Set method that does union

setA.addAll(setB) =




setA union setB

Set method that does intersection

setA.retainAll(setB) =




setA intersect setB

Set method that does subtraction

setA.removeAll(setB) =




setA minus setB

Map method for retrieving an element

map.get(Object key)

Map method for adding an element

map.put(K key, V value)

Qualities of a good hash table

1. size of table much > # of values


2. hash algorithm that chooses "random" location in table

What is "chaining"

Using another data structure (linked list) in place of a hash bucket so multiple values can be stored in same bucket

what is a "collision" in a hash table

when a value is added to a bucket that already has a value in it.

what is quadratic probing

when a hash table collision occurs, add the element to a cell n distance from original hash based on quadratic equation

performance of open addressing hash tables

c = 1/2(1+ 1/(1-L)) where




c = comparisons


L = load factor

performance of chaining

c = 1 + (L/2)




c = comparisons


L = load factor

big-O performance for hash table

O(1) expected; worst case O(n)

big-O performance for unsorted array

O(n)

big-O performance for binary search tree

O(log n); worst case O(n)

recursive algorithm for greatest common divisor

if n is a divisor of m


gcd(m, n) = n


else


gcd(m, n) = gcd(n, m%n)

recursive binary search algorithm

if the array is empty


return -1


else if the middle element matches the target


return middle element


else if the target is less than the middle element


recursively search the elements before the middle


else if the target is more than the middle element


recursively search the elements after the middle

Stack applications

finding palindrome


balancing parenthesis



implementation of stack

array = O(1)


list = O(n)


vector = O(n) and all methods are accessible

application of queue

operating systems, printers

implementation of queue

double linked list = O(1)


single linked list = O(1)


circular array = O(1)



storage requirements of queue implementation

circular array = 1/2


single linked list = 1


double linked list = 1.5

what is a deque

double-ended queue




ArrayDeque recommended implementation

unit testing

tests smallest pieces of the software

integration testing

tests interaction among the units

system testing

tests the whole program in the context in which it will be used

acceptance testing

system testing designed to demonstrate that the program meets it's functional requirements

black-box testing

tests the item based on its interfaces and functional requirements

white-box testing

tests the unit with knowledge of it's internal structure

JUnit test framework

a test harness is a program written to test a method or class. it provides known inputs for a series of tests and compares the results with known results

test driven development

writing tests and methods in parallel

what is an expression tree

(x+y)*((a+b)/c)

(x+y)*((a+b)/c)

what is a Huffman Tree












Examples: 
 d : 10110 
 e : 010

Examples:


d : 10110


e : 010

algorithm for searching a binary tree

1.if thetree is empty


2. return null (targetis not found)else if the target matches the root node's data


3. return the data stored at the rootnodeelse if the target is less than the root node'sdata


4. return the result of searching theleft subtree of the rootelse5. return the result of searching theright subtree of the root

full binary tree

A full binary tree is a binary tree where
all nodes have either 2 children or 0 children (the leaf nodes)

A full binary tree is a binary tree whereall nodes have either 2 children or 0 children (the leaf nodes)

perfect binary tree

A perfect binary tree is a
full binary tree of height n with exactly 
2n – 1
nodes
In this case, n = 3
and 2n – 1
= 7





2

A perfect binary tree is afull binary tree of height n with exactly 2n – 1nodes


In this case, n = 3and 2n – 1= 72

complete binary tree

A complete binary tree is a
perfect binary tree through level n - 1 with some extra leaf nodes at level n (the
tree height), all toward the left

A complete binary tree is aperfect binary tree through level n - 1 with some extra leaf nodes at level n (thetree height), all toward the left