CSCI 311 FINAL 2019

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

List the five red black tree properties

1) every node is either red or black 2) the root is black 3) every leaf (t.nil) is black 4) if a node is red, then both its children are black 5) for each node, all paths from the node to descendant leaves the same # of black nodes

A spanning tree is a unuique

false

How to find the tree maximum:

go through the tree roots to the right most node to find the maximum

PRim's Algorithm may be applied to both directed and undirected graphs.

false

How to find the tree minimum in a binary search tree:

go through the tree roots left recursively until you hit NULL. The node whose left is NULL is the min-value.

Name a sorting algorithm we have studied that is not stable

heapsort

IF TSP takes 1 microsecod to solve when n = 12, how long to solve when n = 20.

in microseconds: 2.43 x 10^18 in years: 7.7 x 10^16

If you have an array of elements to sort that are already in almost sorted order, which of the following sorts would give the best performance?

insertion sort

The part of the data that is used for sortung is called the _____

key

Give the number of levels in a recursion tree for merge sort as a function of n:

lgn + 1

Name a sorting algorithm we have studied that has a tight bound

merge sort or heap sort

The expected time to search for a key in the hash table is O(1). State the two assumptions regarding the hash function that are made in the analysis leading to this rexpected time.

1. HASH functions is o(1) 2. Uniform Distribution on the keys over the available slots

The expected time to search for a key in a hash table is O(1). State the two assumptions regarding the hash function that are made in the analysis leading to this expected time.

1. Hash is a constant O(1) 2. It performs a united distribution on the keys over the available slots

Give two properties of a max-heap that makes one useful in a sorting algorithm (such as heapsort).

1. Max values at the top 2. operations on the heap are O(lgn)

For what two characteristics of input would INSERTION-SORT be a good choice for a sorting alogrithm?

1. small input size 2. the data we are sorting is already in order or almost in order

Edge between vertices in the same tree of in different trees - no ancestor/descendent relationship

Cross Edge

Edge(u,v) where v is a descendant of u, but is not a tree edge

Forward edge

State the Binary-Search-Tree property

If y is in left subtree of t, then y.key<= x.key if y is in right subtree of t the y.key >= x.key

Let n = the number of elements to be sorted. Insertion sort has the property that it is adaptive. What does this mean in terms of the running time? Use asymptotic notation in your answer.

Insertion sort is adaptive because if the elements are nearly sorted or are sorted the run time reaches O(n)

A heap can support any priority-queue operation on a set of size n in _____ time

O(lg n)

A function that describes how the time to solve TSP grows is

O(n!)

Give the runtime complexity for the worst case of QUICKSORT

O(n^2)

Give the upper bound on the runtime of INSERTION-SORT

O(n^2)

Give the runtime complexity for Merge SOrt using asymtptoic notation.

O(nlgn)

give the upper bound on the runtime of Merge-Sort

O(nlgn)

Give the runtime complexity for the best case of QUICKSORT

OMEGA(nlogn)

Give the lower bound on the runtime of Insertion-Sort

Omega(n)

Give the lower bound n the runtime of Merge-Sort

Omega(nlgn)

What advantage do we gain by randomizing the selection of the pivot in partition?

Randomizing the selection of pivot gives you a better chance to not get the worst case run time.

A sort that is ______, benefits from the existing order of the input to improve the bound on runtime.

adaptive

A sort that is _______ benefits from the existing order of the input to imrpove the bound on runtime.

adaptive

An _____ sort benefits from the existing order of the input to improve the bound on runtime.

adaptive

The amount of effort to solve TSP depends on

amount of cities

Select the loop invariant that can be used to show the correctness of INSERTION SORT

at the start of eahc iteration of the for loop, the elements to the left of j are sorted.

Which of the following algorithms will discover all vertices at distance k from the starting vertex before discovering any vertices at distance k+1?

breadth first search

Which of the following algorith,s will provide us with information about the structure of a graph?

depth-first search

what must be true for f(n) to be theta(n)? Make use of asymptotic notation in your answer.

f(n) = O(n) = Omega(n) or f(n) = Omega(n) = O(n) The upper and lower bounds must be equal in order for f(n) = theta(n).

Let g(n) = n(lg n) be an asymptotically tight bound for f(n). Express this fact using asymptotic notation

f(n) = theta(n lg n )

A red black tree with n internal nodes will always have height <= lg(n)

false

Merge Sort is an in place sorting algorithm

false

The PARTITION fucntion of QUICKSORT creates two partitions of the input subarray, with both partitions in sorted order.

false

The Traveling Salesman Problem (TSP) has an efficient solution

false

Name two sorts we have studied that are "divide and conquer" algorithms

merge-sort and quick-sort

Give the order of growth of runtime for the worst case input to INSERTION SORT

n^2

Let n = the number of elements to be sorted. What characteristic od the input generates the worst case running time for insertion sort? Using asymptotic notation, give the worst case running time for insertion-sort.

When the elements aere in reverse order O(n^2)

The loop invariant for BUILD-MAX-HEAP states

nodes A [i + 1] ... A.length] are each the root of a max heap

Give the function definitions for determining the array index of the parent, left child, or right child, from an array index i

parent(i) = floor(i/2) left(i) = 2i right(i) = 2i + 1

A sort is said to be _____ if equivalent keys are not reordered in the sorted output.

stable

In a _____ sort, equivalent keys are not reordered in the sorted output.

stable

EDGE (u,v) where u is a descendant of v

Back edge

Give the runtime complexity for the average case in quicksort

THETA(nlogn)

In the dpeth first forest. Found by exploring the edge (u, v)

Tree Edge

A loop invariant is

a property that holds true before and after each iteration of a loop

A loop invariant is

a property that holds true before and after each iteration of a loop.

How to find Successor of a node:

successor of a node x is the node y such that y.key is the smallest key greater than x.key

Let g(n) = n(lg n) be an asymptotically tight bound for f(n). Express this fact using asymptotic notation

theta(nlgn)

What are rotations used for in tree algorithms

to balance the tree

A red-black tree with n internal nodes has height at most 2lg(n + 1)

true

How to find the predecessor of a node:

x is the node with the greatest key smaller than x

Give a formula for how many edges a spanning tree will have in terms of the number of vertices, |V|.

|V| - 1


Conjuntos de estudio relacionados

ATI Pharmacology End of Chapter 26

View Set

MKTG 3010 Exam Two, SmartBook 2.0 Chapter 5 Assignment, IBM Chapter 4, Man3025 Chapter 5 LS

View Set

Section 4 Practice Quiz Questions

View Set

Mod 1 Breast/Female Reproductive Disorders

View Set

Semester 1-3 BIO Topics Grade 12 (EXAMS)

View Set