Data Structures and Algorithms

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

Given the input vector 4, 3, 1, 0, 2, after one iteration of insertion sort, the result will be _______________.

3, 4, 1, 0, 2

If we have a hash table of size 100 using separate chaining, and we have ____ objects stored in the table, the average number of objects per bucket is 0.5.

50

Which of the following is an array representation of a valid binary heap?

6, 3, 5, 2, 1, 4

If our primary function is f(x) = x mod 11, and our secondary hash function is g(x) = 7 - (x mod 7), then for a key value of 8 the first three steps in our probe sequence would be _______________.

8, 14, 20

A tree of N nodes will always have exactly N - 2 edges.

False

An algorithm that iterates a three-dimensional array and performs some calculation on each element would have complexity of at least O(n^4).

False

Assertions are not useful in testing, but they can be used in documenting your code.

False

Elements on the stack can be accessed randomly using stack indices.

False

Every directed graph has at least one topological sort

False

Given a vector of n elements, it takes log n + 2 steps to divide the vector into individual elements by dividing in half at each step.

False

Given a vector of n elements, selection sort will always require 2n swaps to complete the sort.

False

If a directed graph has more than one topological sort then in must contain at least one cycle

False

If using an adjacency matrix representation of a tree or graph, checking to see if two nodes are adjacent requires linear time, O(n).

False

If we determined that an algorithm had complexity of O(n^3 + 17n) we would round up to O(n^4).

False

In C++ a struct is a user-defined data type that can only take certain, enumerated values.

False

In a B-tree, leaves can be at different depths.

False

In a directed graph, if node A is adjacent to node B, then node B must be adjacent to node A

False

In the context of the dynamic equivalence problem, the find operation could result in increasing the number of equivalence classes.

False

In-order traversal on a tree with letters as labels will always produce an alphabetically ordered result.

False

Insertion sort is designed to make the fewest swaps possible.

False

It is a good idea to allow duplicate keys in a hash table.

False

It is so difficult to insert or delete elements in a linked list that linked lists are usually not changed once instantiated.

False

Merge sort is unstable because it is a divide-and-conquer algorithm.

False

On a long probe sequence, we can only probe all elements in our hash table if our stride is a factor of our hash table size.

False

Only one element of a given equivalence class may serve as its representative.

False

Pass-by-reference yields null when the variable is out of scope.

False

Pre-order traversal is generally faster than post-order traversal.

False

Quadratic probing calculates the stride by taking powers of the starting index in our probe sequence.

False

Recursive algorithms are almost always the most efficient way to solve a given problem.

False

Using a random number generator in our hash function is a good way to avoid hash collisions.

False

We declare and initialize a pointer to an int with the following syntax: int ptrFoo = *foo; where foo is an integer.

False

We may apply C++ templates to classes, but not to individual functions.

False

Which of the following trees is a valid AVL tree?

Trees #1 and #3

& is the "address of" unary operator.

True

* is the "contents of" unary operator.

True

A C++ optional is used when we wish to be able to indicate whether or not a value is present.

True

A binary heap is a binary tree with extra properties.

True

A directed, acyclic graph may have more than one topological sort

True

For the dynamic equivalence problem, we can implement both find and union with linear time performance.

True

Functions that divide their working space in half at each iteration typically have O(log n) complexity.

True

Given an adjacency list representation of some directed graph G, the entry for node D is [A, B, E], the entry for node A is [B, Q, R], the entry for node B is [C, D, F], and the entry for node F is [A, R, S], then the graph contains a cycle.

True

Given an adjacency matrix for an undirected graph, the sum of a node's row or column gives the degree of the node.

True

Given suitable inputs, bucket sort and radix sort can outperform comparison-based algorithms.

True

Given the dynamic equivalence problem, we may achieve constant time performance for either union or find but not both.

True

Hash table performance depends in part on the time required to calculate a hash.

True

Horner's method gives us a concise way to calculate polynomials.

True

If an expression tree is correctly written, we can recover RPN using post-order traversal.

True

If our data are more-or-less uniformly distributed in values, then interpolation search can outperform binary search.

True

If we have 5,000 paint brushes, and the maximum number of bristles on a paint brush is 4,000, then we must have at least 1,000 paint brushes with the same number of bristles.

True

In a B-tree, the minimum number of values we can have in a leaf is given by the ceiling of L/2.

True

In a splay tree, we splay on each access.

True

In quicksort, the risk of choosing a bad pivot is that all values (or a very large proportion of values) will fall to one side of the pivot.

True

Insertion sort can be used on-line. That is, we can add elements to the right end of the vector while insertion sort is running and it will still produce a correct result.

True

Pointers store a memory address.

True

Radix sort can sort integers and strings.

True

Sorted values accumulate on the right end of the vector when using bubble sort.

True

The base case of recursion in quicksort is a single element which is sorted by definition.

True

Using Horner's method in our hash function, and some input string of length n, we calculate a polynomial of degree n - 1.

True

Worst case performance for a binary search tree is O(n).

True

Worst case time complexity for DFS using an adjacency list and adjacency matrix is the same, O(V+E), but the worst case trees are different.

True

nullptr is used to indicate that a pointer points to nothing.

True

std::cout is an output stream object which is synchronized with standard output.

True

Given an input vector "axe", "bib", "arm", "boy", "add", after one iteration of radix sort, the vector will be _______.

"bib", "add", "axe", "arm", "boy"

To get the address of an object we use the following operator:

&

Our secondary hash function should never return the value ________ because if it did, we would never probe beyond the initial position.

0

Given input vector 1, 2, 0, 3, 4, after one iteration of selection sort the result will be ___________.

0, 2, 1, 3, 4

With quadratic probing, the stride size of the fifth step is _______.

25

In a 3-heap, the third level from the root may have up to ____ nodes.

27

Given a vector representation of equivalence classes: 3, 3, 3, 1, 1, 3, 2, there are _______ equivalence classes.

3

Given a vector representation of equivalence classes: 3, 3, 3, 1, 2, 1, 1, after we call find(3, 4), the largest equivalence class will have ___________ elements.

3

Which of the following are self-balancing trees?

AVL tree and splay tree

A tree is a connected, _________, undirected graph.

Acyclic

AVL stands for

Adelson-Velskii and Landis

An AVL tree is an example of a self-_______________ tree.

Balancing

Without a __________, a recursive algorithm may not terminate.

Base case

Double hashing is a method that is designed to avoid ______________ in our hash table.

Clustering

Radix sort works without performing ____________.

Comparisons

Memory leaks are caused when we fail to ______ memory when it is no longer needed.

Deallocate

The number of edges incident to a node determines the node's ______.

Degree

The arrow operator (->) first __________ the pointer and then accesses the target member.

Dereferences

The run time of radix sort on an array of integers depends in part upon the maximum number of __________ among the elements in the array.

Digits

The median-of-three method is used with quicksort to reduce the chance of selecting a bad __________.

Divider / Pivot

The intersection of two (or more) disjoint sets is _____________.

Empty set

Adding an element to a queue is called ____________.

Enqueueing

">>" is the

Extraction operator

A queue operates on a ______ basis. Hint: use an acronym.

FIFO

A leaf has degree 0 because it has no children.

False

In C++ an enum is an aggregate data type that groups individual variables together.

False

The empty set isn't a subset of any set.

False

We want the entries in our hash table to be tightly clustered in order to save space.

False

When probing to insert an object in our hash table, we continue past elements flagged as "deleted" or "removed".

False

When we remove an object from our hash table we reduce our hash table size by one.

False

"Load factor" is the same thing as

Fill percentage

The dynamic equivalence problem involves finding a good solution for performing two operations which we call ____________ and ______________.

Find and Union

Every function call gets its own _________ on the stack, which includes input parameters, local variables, and a return address.

Frame

A queue has two ends, called the [a] and the [b].

Front, Back

During bubble sort, large values tend to move a ______ distance within the vector than smaller values do.

Greater

std::getline() function takes an input file stream object and a variable as required parameters. The variable is used to specify __________.

Hold data fetched by std::getline()

A hash function should return a value that is a valid _______ into the hash table.

Index

The primary operations of a d-heap are delete min (or delete max) and ___________.

Insert

In C++, the << and >> operators perform iostream ____ and ____, respectively.

Insertion Extraction

A stack operates on a ______ basis. Hint: use an acronym.

LIFO

The L parameter for B-tree gives the number of elements that can be stored in a given _________________.

Leaf

Radix sort requires that elements can be sorted in _____________ order.

Lexicographic

Worst case performance for a binary search tree occurs when the tree is ______________.

Linear

One drawback of linked lists is that elements within the list must be accessed in ____________ fashion.

Linear / Sequencial

In a _________ heap, each child must have a value less than or equal to that of its parent.

Max

Two divide and conquer sorting algorithms are _____ and ______.

Merge sort and Quicksort

We allocate space on the heap by using the ______ keyword.

New

Searching a sorted linear structure supporting random access using binary search has a complexity of __________.

O(log n)

The average case time complexity of Quicksort is ____________.

O(n log n)

Time complexity of merge sort is ________.

O(n log n)

Worst case time complexity for heap sort is ________.

O(n log n)

Time complexity of selection sort is ________.

O(n^2)

Space complexity for adjacency list is:

O(|V| + |E|)

Space complexity for adjacency matrix is:

O(|V|^2)

Equivalence classes form a ____________ of the underlying set.

Partition

A connected component is a graph in which a ___________ exists between any two nodes in the graph.

Path

For the dynamic equivalence problem, which of the following is used to improve the performance of union:

Path Compression and Weighted Union

A minimal implementation of a stack would need to support [a] and [b] operations.

Push, Pop

This algorithm works by recursively partitioning elements on either side of an element called the pivot or divider: ____________.

Quicksort

Three sorting algorithms with O(n log n) complexity are ______, ______, and ______.

Quicksort, merge sort, and heap sort

Splay tree and AVL tree attain balance by using tree _____________.

Rotation

We call a sorting algorithm ____________ if repeated elements in the input appear in the same relative positions in the sorted output.

Stable

The amount by which we increment our index when linear probing is called the ______________. This is typically set to 1.

Stride

A pointer to the current object of a given class is called ______.

This

While friendship is a relation, it is not an equivalence relation because it violates the requirement of __________________.

Transitive

If our hash function is not "onto" or "surjective" then there will be indices into our hash table that are never used.

True

We may implement hash table with separate chaining using a vector of vectors or a vector of linked lists.

True

When probing on an insert we are looking for a position that is flagged as "empty" or "removed."

True

When probing to find an object in our hash table, we continue past elements flagged as "deleted" or "removed".

True

We use a std::_______________ object to read from files.

ifstream

Given set A = {"goldfish", "turtle"} and set B = {x ∈ ℤ | x mod 2 = 0} is

the set of all even integers and "goldfish" and "turtle"

Given some equivalence relation R and equivalence class [q] where q is a representative of the class, then the set of all elements x in [q] are those elements for which ________________ is true.

x R q / q R x

The correct ascending lexicographic order of 273, 028, 031, 101, 099, 156 is __________.

028, 031, 099, 101, 156, 273

Given an in-place implementation of heap sort, with the input vector a valid max heap: 4, 3, 0, 2, 1, after the first iteration, the vector will be _______.

3, 2, 0, 1, 4,

Given the input vector 4, 3, 2, 1, 0, after one iteration of bubble sort, the vector will be ______________.

3, 2, 1, 0, 4

Rather than searching for an item, we access an item in a hash table by ___________________ its index.

Calculating

std::setprecision() determines the number of _________ that will be displayed for floating point numbers.

Decimal places

In a polynomial, the term with the largest exponent is the ________ term.

Dominating / Dominant

The find operation, in the context of the dynamic equivalence problem, takes two parameters and returns a boolean indicating whether or not the two operands are members of the same _____________.

Equivalence class

In the array representation of a binary heap, with 1-indexing, if a node's index, i, is ______ we can find the index of its parent with i / 2.

Even

Best case performance for a binary search tree is O(log n).

False

Best case performance for a binary search tree is O(n log n).

False

Bubble sort can be used on-line. That is, we can add elements to the right end of the vector while bubble sort is running and it will still produce a correct result.

False

Bucket sort and radix sort are general-purpose sorting algorithms.

False

If an expression tree is correctly written, there is no way to recover RPN, even when using post-order traversal.

False

If two objects are both related to the same third object then they must belong to the same equivalence class.

False

Separate chaining requires that objects within each bucket are sorted on a key field.

False

Sorted values accumulate on the right end of the vector when using selection sort.

False

The adjacency matrix for a directed graph must be symmetric about its diagonal.

False

The height of a tree is the distance from the root to the nearest leaf.

False

The higher the load factor or "fill percentage" the less likely it is that we have a hash collision on the next insert operation.

False

The range of our secondary hash function should be [0, table size].

False

The structure of an AVL tree changes with each access

False

The time complexity of topological sort is O(|V| x |E|).r

False

The worst case search performance for an AVL tree is O(n log n)

False

There is an algorithm for finding the root of an unrooted tree.

False

Two equivalence classes may have elements in common.

False

When merging two vectors, merge sort will begin by comparing the rightmost position of both vectors and taking the least element of the two.

False

Splay tree takes advantage of ________________ to speed access to frequently accessed values

Locality of reference

The more clustering we have in our hash table, the ___________ our probe sequences become.

Longer

To insert, we create a bubble at the first empty position and ______________ until we find a suitable position for the newly inserted value.

Percolate up

When we allocate space on the heap, we get a _________ to the new object.

Pointer

If we have a hash table with linear probing, If we remove items from the hash table and don't mark the position as "removed" or "deleted", then we can break the ________________________.

Probe sequence

Radix sort can sort numbers with any base (e.g., base 10, base 2, base 3, etc.)

Radix sort and bucket sort

Two algorithms that use a distribute-and-gather approach are _______ and _______.

Radix sort and bucket sort

When using double hashing, the secondary hash function is used to calculate the ______________.

Stride

The ______________ property of d-heaps states that every level of the tree must be full with the possible exception of the most distant level from the root.

Structure

Accessing an element in a linked list has O(n) complexity.

True

All pointers must specify the type of the object to which they point.

True

An adjacency list representation is an array or vector each element of which is a linked list.

True

Best case complexity of bubble sort is O(n).

True

Best case complexity of insertion sort is O(n)

True

Binary search trees have an arity of two.

True

Bubble sort can terminate early if we keep track of whether or not we've made a swap during a given iteration.

True

Bubble sort will run faster than selection sort on a vector that is already sorted.

True

By repeatedly deleting min or deleting max in a priority queue we will remove all elements in their priority order.

True

Double rotation rotates the edge between the target node and its parent twice, but the parent node changes in the process.

True

For any implementation of a hash table, insert, find, and remove methods will have the same complexity.

True

If using an adjacency matrix representation of a tree or graph, we can check to see if two nodes are adjacent in constant time, O(1).

True

If we have a hash table with at least one entry at each index, all subsequent insertions will result in a hash collision.

True

If we have an algorithm performing a calculation requiring three nested loops, its time complexity will be at least O(n^3).

True

In AVL and splay trees, it is often the case that rotation will require us to find a new parent for a particular node.

True

In a B-tree, the M parameter determines the maximum number of children a given node can have.

True

Insertion sort is faster than bubble sort or selection sort because it only looks at one unsorted element at a time and ignores the others.

True

Interior nodes of a tree have a degree of at least two.

True

It is possible to rotate a subtree without rotating the rest of the tree.

True

The worst case for quicksort is when the input is a sorted list.

True

The worst case search performance for an AVL tree is O(log n)

True

There exist sorting algorithms that work without comparing elements.

True

There is a unique, one-to-one correspondence between nodes in a binary heap and the indices of its array representation.

True

When using a Horner hash, we're actually calculating a polynomial on some (prime) number where our input key determines the coefficients and the degree of the polynomial.

True

When we search for prime numbers > 2, we only need to check odd numbers.

True

With heap sort we can sort elements in ascending order using a max heap, and sort elements in descending order using a min heap.

True

With templates, we can create containers that work with different datatypes.

True

A good hash function distributes its output values as ___________ as possible.

Uniformly

Bucket sort works best when values to be sorted are ________ distributed.

Uniformly

When working with disjoint sets representing equivalence classes we often wish to perform two operations: find and _________.

Union

Given set A = {"dog", 4, "cat", 3, 2, "pony"} and set B = {"hawk", "dog", 3, 7}, the intersection A ∩ B is:

{3, "dog"}

We say T(N) = O(f(N)) if there are positive constants c and n_0 such that T(N) ____ cf(N) with N ≥ n_0.

To pass-by-reference we use the ________ operator with a parameter to our function

&

The "contents of" operator, used to dereference pointers is:

*

The heights of left and right subtrees of each node in an AVL tree can differ by at most ______________.

2

Given a node X, with two subtrees, alpha and beta, the hight of alpha is 4, the height of beta is 6. This could be a _________.

BST or splay tree

A zig-zig case is where the first and second generation nodes are both left children. The zag-zag case is where they are both right children.

False

When performing an in-order traversal, we explore a node's ________________ first, before marking it as visited.

Lift subtree

The divide-and-conquer algorithm for maximum subsequence sum runs in _________________ time.

O(n log n)

Each node in a singly-linked list includes some data and a ___________ to the next node in the list.

Pointer

A binary heap is just a special case of a d-heap.

True

A d-heap may have any integer value for d greater than 1.

True

A leaf node has left and right subtrees of height 0.

True

A single node is a valid tree.

True

A tight bound is one where the upper bound and lower bound are equal.

True

If there is more than one path between any nodes in a graph, then the graph is not a tree.

True

If there is only one instantiation of a templated class with a single datatype, the compiler will generate code to support only that datatype.

True

One use of operator overloading is to make C++ "aware" of how to compare classes you create.

True

The amount of memory available to the C++ stack is fixed.

True

We can use either min heap or max heap for implementation of a priority queue.

True

When deleting a node, splay tree first splays a node to the root before deleting.

True


Set pelajaran terkait

CSCI 304 Networking and Security Chapter Four

View Set

Unit 4 Variables, Conditions, and Functions

View Set

NU142- Chapter 1: Health Care Delivery and Evidence-Based Nursing Practice

View Set

Chapter 1 Introduction to Statistics

View Set

Ch. 10-12 Urinary System, Spleen, Retroperitoneum

View Set

2.1: Deterministic Finite Automata

View Set

Saunders Mental Health Questions

View Set