COMP 2140

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What's the two steps of a hash function?

#1 make the key into a hash code #2 make the integer into an array index --> compression map

branch

(edge) a connection between two nodes

What are the only possibilities of a 2-3 tree if h >1?

1) a root with two children 2) a root with three children

What is the height of a full tree?

2 ^ h - 1

among depth-first and breadth-first search, which one finds the shortest path?

Breadth-first

BigO of radix sort

O(d(N+n))

What should you use when traversing a graph

adjacency list

What's the condition for 2-3 tree nodes with two children when the index value is k1?

(keys of the data in TL) <k1 ≤ (keys of the data in TR)

What are the two kinds of collision resolution?

- open addressing: linear probing - separate chaining

What's the condition for 2-3 tree nodes with three children when the index value is k1, k2?

- the keys of data in Tl < k1 - k1 <= the keys of data in Tm < k2 - k2 <= the keys of data in Tr

what is considered a good hash function?

-minimize collisions -fast to compute

If you are at node heap[i], where is the left child, right child, and its parent?

1) Left child: heap[2i+1] if (2i+1) < heapSize 2) Right child: heap[2i +2] if (2i + 2) < heapSize 3) Parent: heap[(i-1)/2] if 0 <= (i-1)/2

What's special about expression trees?

1. parentheses and operator priorities are not needed 2. (in other words) for any arithmetic expression, there is only one corresponding expression tree

What is the height and running time for search, insert, and delete for a 2-3 tree?

2-3 tree containing n keys --> O(logn) for all

Priority Queues

A priority queue stores items with priorities and has operations : Insert & DeleteMax/DeleteMin

What does it mean for a tree to be heap ordered (partially ordered)?

A tree is heap ordered if, for each node v in the tree, the priority of the item contained in v is greater than (or equal to) the priorities of the items in its children

What possible implementations are there for a priority queue?

Array, LL, BST

What's the BigO for DeleteMax and Insert with array or LL implementation (in priority queue) ? How about BST?

DeleteMax : delete from front O(1) Insert : ordered insert O(n) Both O(n) for BST

What is one implementation of a ADT Table that takes O(1) for all insert, delete, and search?

Hash Table

Closed Hashing

Hash table consists of a fixed amount of storage, and every item is placed in a hash table slot in that limited storage (open addressing)

What is a heap?

Heap is a binary tree that is complete and heap ordered // JUST AN ARRAY

What should stack or queue operations never include?

LOOP

Are dummy nodes helpful all the time?

No, like in a circular linked list Queue

What is the height of the shortest tree with n nodes?

O(logn)

What BigO time does binary search take?

O(logn) : because binary search in an array is dividing the number of items left to be searched by two at each step

What is the height of the worst trees?

O(n)

What's the worst-case search time for a BST?

O(n), same as linked lists

BigO of Insertion sort

O(n^2)

BigO of selection sort

O(n^2)

BigO of quickSort

O(n^2) but in average O(nlogn)

BigO of Merge Sort

O(nlogn)

Parent, children, siblings

Parent is connected directly to its children & children of the same parents are siblings

Open Hashing

Storage is dynamically allocated - items are stored outside the table

Can 2-3 tree have height 0?

Yes

Expression Tree

a binary tree that represents an arithmetic expression composed of binary operators

ADT Table Data

a collection of entries, where each entry contains a key (a unique identifier for the entry) and the rest of the entry

What is an ADT (Abstract Data Type)?

a data structure together with a set of operations

What is a good implementation for a priority queue? and why?

a heap (binary tree stored in an array): O(logn) insert & deleteMax

Leaf

a node with no children

binary tree

a tree in which each node has at most two children

What's the worst height for a 2-3 tree with n keys? The insertion? The deletion?

all O(log2n) -> because it is tallest if most interior nodes have two children - that is, it is at worst a full binary tree

Where is the root shored in a heap?

always stored in heap[0], if the tree is not empty

tree traversal

an organized walk that visits every node once

What is 2-3 tree useful for implementing ADT table?

because the trees are always short

Complete Tree

binary tree of height h is complete if it is full to level h-1 and level h is filled from the left with contiguous nodes

What's a problem with Open addressing?

clustering & collisions become more and more likely as more insertions happen --> makes searches expensive!

binary tree == BST

false

BST Property

for each node j, the values stored in the left child tree of j are all less than the value stored in j, which is less than the all values stored in the right child tree of j

minimum value is BST

found by starting at the root and repeatedly moving to the left child until you reach a leaf

maximum value in BST

found by starting at the root and repeatedly moving to the right child until you reach a leaf

Full / Perfect binary tree

h (height) is full if on every level < h, every node has exactly two children

height of a tree

height of its root

Where are operators stored in an expression tree?

in the interior nodes

What are the values in the interior nodes in a 2-3 tree?

index values to guide a search to the correct leaf

Which method of traversal has an output in sorted order?

inorder traversal

Inorder successor of a node n

is the node n(is) containing the next higher value in the tree

Where are constant operands stored in an expression tree?

leaves

height of a node j

length of a longest path from j to one of its leaf descendants

depth of a node n

length of the path from the root of the tree to n

What is the goal of building a better tree?

make the longest path to be short = short tree OR full/perfect or complete trees

Can a search stop at an interior node?

no, a search MUST end at a leaf

descendant of node k

node j if there is a path from j to k that goes up, never down

ancestor of node j

node k if k is on the path from j to the root

interior nodes

nodes that have at least one child

in-degree of a node

number of edges coming in to the node

out-degree of a node

number of edges going out of the node

length of a path from node j to k

number of nodes on the path from j to k, including both j and k

What is the best way to compute node depths in a BST?

preorder traversal because a node's depth is one greater than its parent's depth; computing the depth of a child depends on the result of computing the depth of its parent

three standard ways to traverse a tree

preorder, postorder, and inorder traversal

Depth-first Traversal

searches all the way down a path before packing up to explore alternatives - it is a recursive, stack-based traversal

What kind of a number should you use as a constant when computing a hash code?

small prime number

Root

starting-point node of the data structure

What is special about the adjacency matrix of an undirected graph?

symmetric around the main diagonal

What is the condition of leaves in a 2-3 tree?

the leaves are all on the same level

level of a node

the length of the path from the node to the root

What creates the shape of the tree?

the order items were inserted

Breadth-first Traversal

visits all nearby vertices first before moving farther away - it is a iterative, queue-based traversal

When are graphs used

when complex relationships among data must be represented

When should you use post-order traversal?

when the task you are performing at a node depends on the results of the task performed at its children

When to use preorder traversal

when the tasks performed at the children of a node depend on the results of the task performed at the node itself (their parent)


Set pelajaran terkait

Chapter 39 & 40 Pathophysiology Quizzes

View Set

Rosetta Stone Arabic Unit 1 Lesson 1

View Set

Chapter 67: Management of Patients with Cerebrovascular Disorders

View Set

Intermediate Accounting 2 Chapter 11 Part 1

View Set