CS 2420

¡Supera tus tareas y exámenes ahora con Quizwiz!

Total number of possible nodes in a tree

2^height / 2^(height +1) - 1

Min Heap

A complete tree where each root is the smallest of its subtree. Exists to support priority queue

Stable Sorts

A sort that doesn't change the order of identical items. Example B A(1) A(2) sorted would be A(1) A(2) B. Mergesort Insertion sort

Complete Tree

A tree where all levels are filled, except the the bottom row, which is filled left to right. Represented implicitly as an array

Linear Probing

A way of dealing with collisions if hash(key) = H, and the cell at index H is occupied: H + 1 H + 2 H + 3 ... Size of the list must be a prime number to avoid cycles

Quadratic Probing

A way of dealing with collisions and clustering if hash(key) = H, and the cell at index H is occupied: H + 1^2 H+ 2^2 H + 3^2...

Separate Chaining

A way of dealing with collisions and clustering. A table is created with LinkedLists, and if hash(key) = H, and there is an item at index H, then it is added to the end of the LinkedList at that index

Complexity of Binary heaps

Add: O(c) on the average case, O(logN) in the worst case. This is because 75% of the nodes are in the last two rows. delete min: O(logN) on the average find min: O(c)

BST deletion and complexity

After finding the appropriate node (O(logN)): Three cases: 1. delete leaf node - delete node by setting it's parent reference to null. O(c) 2. delete node with one child - reassign it parent's reference to it's grandchild - O(c) 3. delete node with two children - replace item with successor (leftmost item in it's right subtree). Then delete the successor (which will be a leave node) - O(logN) Overall worst complexity is O(N), and best is O(logN).

Binary Search Tree

All items in the left subtree are less than the item in the node all items in the right subtree are greater than or equals to the item in the node

Hexadecimals

Base 16 code, similar to binary

Dijkstra's

Finds the cheapest path keep track of the total path cost from start node to the current node cost of path to next node is total cost so far plus weight of edge to the next node instead of traversing nodes in the order they were encountered, traverse in order of cheapest total cost first

BST insertion and complexity

First must search, and then insert as a leaf node Average: O(logN) worst: O(N) best: O(logN) All depends on how balanced the tree is

Sparse Graph

Graph with few edges More common, E = V (ish)

Dense Graph

Graph with lots of edges Less common, E = V^2 (ish)

Heap Sort

Heap-ify a list using a max heap 'delete' min and put it at the end of the list. Then the heap will repercolate and continue to do this until there is nothing left in the heap. This is an in place sort

Huffman Header

Include the character frequencies to decompress data store the tree using a pre-order traversal first bye is the hex value of the character, the next 8 bytes are the frequency, in hex. After the header is stored in hex, we encode the data in hex You have reached the end of the header when you have all ten 0 bytes

Complete Tree Equations

Left Child: (i*2) + 1 Right Child: (i*2) + 2 Parent: (i-1) / 2

Depth-First Search

Look at the first edge going out of the start node recursively search from the new node upon returning, take the next edge if no more edges, return When visiting a node, mark it as visited so we don't get stuck in a cycle

Adjacency Matrix

Matrix that represents vertices as columns and rows, with entry containing a 1 if an edge exists, and a 0 otherwise used for dense graphs

Complexity of Heap Sort

O(NLogN)

Collisions

Occurs in hash tables. Happens when two different items have the same hash function and go in the same index in an array.

Topological Search

Only works with a graph w/no cycles used for prioritizing tasks (example scheduling) Step through each node in the graph - if any node has in-degree 0, add it to a queue. while the queue is not empty - dequeue the first node, in the queue and add to the sorted list - visit that node's neighbors and decrease their in degree by 1. - if a neighbor's new in-degree is o, add it to the queue.

What was the name of the ethics professor?

Prof. Venkatasubramanian

Add to Min-heap

Put at the end of the heap percolate up, until it satisfies the order property

Constructing a Binary Trie

Put each node into a priority queue where the character with the least occurrences is higher priority. Break ties with the ASCII value of the leftmost node take the first two items out of the queue and construct a trie, with the root being the sum of the character frequencies.Put the trie back in the queue and repeat the first item taken out of the queue is always the left child. Make sure to include a end of file character

Breadth-First Search

Put the starting node in the a queue while the queue is not empty, queue the current node. for each unvisited neighbor of the current node, mark the neighbor as visited and put the neighbor into the queue.

In place sorts

Quicksort Heap sort Selection sort shell sort

Tree Terminology

Root: the start of a tree Parent: a root of a sub tree. A parent can only have two children in a binary tree Children: the nodes of a subtree. In a binary tree, each child can have one parent. Leaf Node: Nodes with no children Nodes: Any leaf of a tree

Red-Black trees

Self balancing tree BST with additional structure property: the longest path from the root to any leaf is no more than twice as long as the shortest path from the root to any other leaf in the tree A node is either red or black the root is black if a node is red, it's children must be black every path from a node to null link must contain the same number of black nodes

AVL trees

Self- balancing tree Adelson, Velskii, and Landis Uses rotations to re-balance the tree

Delete from heap

Switch the root with the last item in the tree and delete that item. Percolate the root down until you satisfy the order property

Load Factor

The fraction of the table that is full. For quadratic probing keep it to .5 to avoid cycles. For separate chaining it is defined as the average length of the Linked Lists If the load factor is reached, the table size is increased and everything is rehashed.

Balanced Tree

The height of the left and right sub-trees of any node can differ by at most 1.

Depth

The number of 'hops' it takes to get back to the root

BFS complexity

Worst Case: O(V+E)

DFS complexity

Worst Case: O(V+E)

Dijkstra's Complexity

Worst Case: O(V+E)*O(logV)

Binary Trie

a binary tree in which a left branch represents a 0 and a right branch represents a 1

Edge

a link between two vertices can be weighted and directional

Graph

a set of vertices connected by edges A tree is a subset of graphs A linked list is a graph

Adjacency List Complexity

confirming the existence of an edge for a vertex is O(E) iterating through all fo the edges is O(E) space complexity is O(V + E)

Adjacency Matrix comlexity

confirming the existence of an edge for a vertex is O(c) iterating through all the edges is O(V^2) space complexity is O(V^2)

Huffman compression

count occurances of each character in a string for each character, create a leaf node to store the character and count place each leaf node into a priority queue construct the binary trie write header with binary trie information compress string using character codes

Height

depth of the deepest node

Adjacency List

each vertex stores an array of adjacent vertex indices, usually as a linked list used for sparse graphs

Min-Max Heap

for any node E at even depth, E is the minimum element in its sub-tree for any node O at odd depth, O is the maximum element in its subtree

BST searching

if it's balanced O(logN), if it's not, O(N).

In-degree

number of edges it has incoming (degree of incoming edges)

Tree traversals

pre-order - will result in the complete replication of a tree (topologically sorted) In-order - prints the nodes in ascending order (for a bst) post-order - (doesn't result in a specific ordering) *remember flags*

AVL double rotation

switch roles of the deepest unbalanced node's child and grandchild. Then switch the roles of the deepest unbalanced node with new child while maintaining order property.

AVL single rotation

switch the roles of the deepest unbalanced node with child while maintaining the order property.

Hash Table

uses a hash function to add something to an index of an array. constant time operations Must be careful of collisions


Conjuntos de estudio relacionados

IASSC - Yellow Belt Practice Questions

View Set

Hinkle Chapter 29: Management of Patients With Complications from Heart Disease

View Set

insurance chapter 5: life insurance underwriting and policy issue

View Set

INTIMATE PARTNER ABUSE AND STALKING

View Set

Chapter 1- The Purchasing Function: An Overview

View Set