CS 101 Exam 2 Review

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

What is a hash table?

-A data structure that offers very fast insertion and searching. - based on an array-maps and index to a location -a hash table uses a hash function to map a key to a location {key}->{locations}

what is double hashing?

-It eliminates both primary and secondary hashing.

What is levelorder traversal?

Begin at root and visit nodes one level at a time

what is a prefix expression?

operator is prefixed to operands, i.e. operator is written ahead of operands

Inorder

- trickles down - if no left go to source

what is quadratic probing?

-Quadratic probes eliminate the clustering of a linear probe. -In a linear probe the primary hash index is x. Subsequent probes go to x+1, x+2, x+3 etc. -In quadratic probing, probes go to x+1, x+4, x+9, X+16, x+25 and so on. (The distance from the initial probe is always the square of the step number)

what are the disadvantages of linear probing?

-clustering, when n > N/2 -removing a key is complicated and inefficient

why does huffman coding always yield shorter encoded messages

-smaller frequency-> added to tree earlier->deeper in tree->longer binary code -larger frequency->added to tree later->shallower in tree->shorter binary code

build the tree: the preorder is "ABDEHCFJG" the inorder is "DBHEAFJCG"

1.Identify the root 2.add it to the tree 3.the left subtree elements are to the left of the root in the inorder Transveral 4. the right subtree elements are to the right of the root in the inorder transversal 5.split the data in preorder 6. recurse on the left data to form the left subtree 7.recurse on the right data to form the right subtree --level order is A,BC,DEFG,HJ--

what is a postfix expression?

A postfix expression is an expression in which each operator follows its operands. The advantage of this form is that there is no need to group sub-expressions in parentheses or to consider operator precedence.

what is the stack

A stack is an array or list structure of function calls and parameters used in modern computer programming and CPU architecture. Similar to a stack of plates at a buffet restaurant or cafeteria, elements in a stack are added or removed from the top of the stack, in a "last in first, first out" or LIFO order.

what is a binary tree?

A tree in which each node can have only two children: a left child and a right child.

Exceptions

Abrupt transfer of control, divide by zero throw -> catch

what is separate chaining

Another way to fix a collision. We create an array that consists of linked list of words instead of the words themselves. Then when a collision occurs, the new item is simply inserted in the list at that index.

What is a greedy algorithm?

Do the best thing at each stage. -makes the optimal choice at each step -does not make decisions by looking at the bigger picture(its greedy) -does not always make the optimal answer

Hash

Hash(key) = key % # H(50), key = 8 -> H(50) = 50%8 = 2

what is open addressing

If collision occurs, items is placed in another slot. There is only one entry per slot so look for another slot include linear quadratic probing and doubling hashing

Unique tree

Inorder + 1 other

BST Run Times Insert - W,A(tree array),B Remove - WAB

Insert W - O(lg n) A - tree - O(lg n) A - array - O(1) Best - O(1) Remove Worst - O(lg n) Avg - O (lg n) Best - O(1)

each binary search tree operations(find, insert, remove) runs in what time

O(h) time where h is the height of tree

what is the total running time of a transversal

O(n)

running time of separate chaining

O(n) time at worst and O(1) time at best

Hash tables - Open - Closed

Open - Linear Probing - Quadratic Probing - Doubling Hashing Closed - Separate Chaining

Traversal Roots Preorder: Postorder: Inorder: Levelorder:

Pre = first Post = last In = bt left and right subtrees Level = first

What is heapifying?

Rearrange a heap to maintain the heap property, that is, the key of the root node is more extreme (greater or less) than or equal to the keys of its children and creating a list

Q

Right most, deepest node

what is a binary search tree?

Same as binary tree, but data is sorted. Right Is Higher, and Left Is Less

Types of linked list

Singly, Doubly

What is postorder traversal?

Visit root of a binary tree after visiting nodes in root's subtrees

What is inorder traversal?

Visit root of a binary tree between visiting nodes in root's subtrees.

What is preorder traversal?

Visit the root before visiting the root's subtrees

what is linear probing

We search sequentially for vacant cells incrementing the index until we find an empty cell. This is called linear probing because it steps sequentially along the line of cells.

singly linked list

a data structure in which each list element contains a pointer to the next list element. Has a head node at the beginning and a tail at the end. Only can move forward or backwards though the entire list.

Circular doubly linked list

a data structure similar to the doubly linked list where the fist element points to the last element and vice versa

Circular Singly Linked List

a data structure similar to the singly linked list where the last node points back to the first element

doubly linked list

a linked list in which each element has both forward and backward pointers.

what is Huffman Code?

a particular type of optimal prefix code that is commonly used for lossless data compression

why does Huffman code always satisfy the prefix property

all characters in the alphabet are leaves

Templates

allow passing function types in using header files doesn't work for char* unless explicit function provided

dynamic array

an array that has not had its size defined and can change as data is appended

vector class

array like container(imitative notion), capable of dynamic expansion and contraction, modified with class methods and STL algorithms

what does inorder traversal yield in binary search tree

ascending order

Applications of a queue

buffer accessed by both producers and consumers

BST find, insert, remove, RT

find() - best at root - recursive -> left small, right big true if can be found insert() - go to end of tree - exception if duplicate remove() - best -> no children = chop - 1 child -> chop & slide up - 2 children -> find min replacement & slide up Analysis RT W - O(n) A - O(lg n) B - O(1)

throw (char*) try catch (int string generic)

generic bc no implicit conversion

Postorder

go down to lowest node, L bias

Preorder

goes down left branch all the way

what is heap sort?

heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum.[2]

Doubling Hashing

if duplicate Offset by 1st collision as new key + 1, repeat until set

Quadratic Probing

if duplicate Offset by squared amount, 1 -> 4 -> 9 -> 16

Sequence Chaining

if duplicate Point to others

Linear Probing

if duplicate move to next available slot

implementations of stacks

in efficient implementations every operation is O(1) time

Dynamic Array Running Times

insert back, remove back, insert first, remove first

what are queues?

is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence.

if header node

points to x node first before node a, b...

huffman algo

remove min from left and right and sum (new key), bias left assign 0 1 down tree

remove min

replace root with Q and shift down

what is the running time of queues

run time is O(1)

Insert min

send to Q

minheap heapify

swap node with lowest value from base until sorted

Linked List Advantages

they also have the runtimes 0(1)->constant time and 0(n). they are very fast


Conjuntos de estudio relacionados

13-4 Paying Withholding and Payroll Taxes

View Set