Data Structures Final Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

True/False A deque is a sequence container that allows both insert and delete operations from one end of the list, and only from the same end.

False

True/False The following declaration is legal in C++11: string& str = "Goodbye!"

False

True/False: In the C++ STL, class std::set is implemented using a hash table

False

True/False: Quick sort is a stable sort algorithm

False

What is the process of topological sort?

Find a node with indegree = 0 assign it a rank reduce the indegrees of the vertices in its adjacency list

What is topological sorting?

Given a directed acyclic graph G and two vertices i, j, if there is an edge from i to j, then i is ordered before j. For this to work, there must be a node with no indegree

True/False: Any sequence container can be converted to a binary search tree with O(N) run time complexity

True

List the growth rates in terms of fastest to slowest

c - constant log(N) - logarithmic log^2(N) - log squared N - linear N log N N^2 - quadratic N^3 - Cubic 2^N - Exponential

What was the original design for Shell Sort's sort increment?

h = floor(size/2); Then h would be reduced by half each loop

True/False: An insert operation into a hash table is O(1)

True

True/False: A graph is considered complete when there is an edge between every pair of vertices

True

True/False: A graph is simple iff its path is also simple

True

What are the two popular representations of graphs?

Adjacency List, and Adjacency Matrix

In a doubly linked list class, which of the following member function is NOT O(1)? (a) destructor (b) push_front() (c) pop_back() (d) move assignment operator

(a) Destructor The destructor will ALWAYS be O(N) regardless of the container

Suppose a Card class has this constructor: Card(int val = 2, char suit = 'c'); Which of the following is NOT a legal declaration of an object? (a) Card c{}; (b) Card c(10); (c) Card c{6, 'd'}; (d) Card c(); (e) All of these are legal object declarations

(d) Card c( ); A legal version of what this person intends would be: Card c; Their version is either calling a constructor with no parameters, or trying to use the one with two default values

When building a B-tree for accessing large data sets that are stored on a disk, which of the following tree types should be used as a basis? (a) a Binary Search Tree (b) an AVL tree (c) a complete binary tree (d) M-ary search tree

(d) M-ary tree A b-tree is an M-ary tree that has balancing conditions.

What kind of sequence container would be the best choice for quickly inserting a new data item as the 3rd element of the container? (a) vector (b) stack (c) queue (d) linked list

(d) linked list

Which of the following post-fix notation matches this infix expression? (18 - y) / (x + 4) * (z / 6) (a) 18 y - x 4 + z 6 / * / (b) 18 y x / - 4 z * 6 / + (c) 18 y x 4 + / z 6 / * - (d) 18 y - x 4 + / z 6 / *

(d). 18 y - x 4 + / z 6 / *

True/False: A pre-order traversal can be performed on any tree

True

What is the maximum number of nodes in a complete binary tree with height 6?

127. Total number of nodes = 2^(h+1) - 1 2^(6+1) - 1 = 128 - 1 = 127

In which kind of tree would there be a rule that says the value of each node must be less than or equal to that of the node's children?

A Partially Ordered Tree

What is the basic idea of a shell sort?

After each iteration of i, the elements h_i spaces apart are sorted, where h_i is the sort increment

An object that is used to move through and access elements in a container in a generic way, regardless of the container chosen, is called ...

An iterator

What is an undirected connected graph?

An undirected graph G is connected iff, for each pair of vertices u, v, there is a path that starts at u and ends at v

What is the time complexity of Shell Sort?

Big-O (N^2)

Name a few sorting algorithms that have on average O(N^2) run time complexity

Bubble sort, Insertion sort, shell sort

True/False The following declaration is legal in C++11: auto str = "Hello world!";

True

What is Stable sorting?

If the same element is present multiple times, then it retains its original position. Example: If you are sorting words by frequency and want it to be a stable sort, then if the words "the", "and", "test" all occur the same amount of times, then it will be printed out as "the", "and", then "test"

What is the difference between the BFS approach and Dijkstra's algorithm?

In the unweighted approach, BFS, the assumption is that the weight associated to each edge is 1, with Dijkstra's algorithm you use the weight of the edge instead of 1

What is insertion sort?

Insertion sort is a sorting algorithm that requires p-1 passes in order to sort every element of a data structure. It has a run time complexity of O(N^2) and after p passes, elements 0 - p and in order. At the worse case: the elements are in reverse order and require a runtime of O(N^2). At the best case: the elements are already sorted and runs O(N)

What is the average number of inversion on an array of N distinct elements?

N(N-1)/4

What is the run time of topological sort?

O(|V|^2)

What is the basic idea of Merge sort?

Recursively divides N elements in half until its a single element, and then sorts neighboring elements. As it's recursing back up to it's full size, it will be sorting the pre-sorted elements into the proper order The merging of two sorted halves is O(N), BUT, the time complexity of the total merge sort is O(NlogN)

What is an Adjacency List?

Requires O(|V| + |E|) space, where |x| denotes the magnitude of x. Each node maintains a list of it's neighbors

What is simple sorting?

Sorting that only compares neighboring elements, such as insertion and bubble.

True/False: A complete binary tree is most easily represented with a vector

True

Describe the basic structure of the partition algorithm for quick sort

Swap pivot with last element and create two iterators i,j. have i start at the first element and move forward have j start at the last element and move backwards while(i < j) have i move forward until it finds an element larger than the pivot have j move backwards until it finds an element smaller than the pivot if (i < j) swap(i, j) swap pivot with S[i] At this point the pivot is in its proper spot.

What is the generic recursion relationship?

T(n) = 2^k * T(N/(2^k)) + k*N

What does weight mean for graphs?

The cost parameter associated with each edge

What is indegree?

The indegree of v = the number of edges {u, v}

How do you find the length of a path of N vertices

The length of any path of N vertices is N-1

What is the length of a path?

The number of edges along a path

What is in-place sorting?

The sorting of a data structure that does not require any external data structure for storing the intermediate steps

What is external sorting?

The sorting of records not present in memory

What is the cost of a path?

The sum of the weights along the edges of the path

True/False An Adjacency Matrix with few edges is considered wasteful

True

True/False An insert operation at the from of a vector is O(N)

True

True/False If H is a digraph that is NOT strongly connected, but it's undirected version of the graph is connected, then it is considered weakly connected

True

True/False In standard sequence containers like vector or linked list, a const_iterator can refer to different items but cannot be used to change them

True

True/False Quick sort is an in-place sort algorithm

True

True/False A vector typically takes overall less memory storage that a linked list that stores the same data elements

True, This is because the linked-list also needs to keep track of the pointers for the next element

True/False Any algorithm that sorts by exchanging adjacent neighbors requires a big-omega of N^2 time.

True. The average number of inversions is Omega(N^2) The average number of swaps required is Omega(N^2)

True/False: It possible to achieve sub-quadratic time complexity for Shell sort?

True. This is only possible if the comparison increments are chosen properly

What are the two kinds of graphs that we studied

Undirected and Directed (Digraphs)

What are the two ways to find the shortest path in a graph?

Unweighted shortest path: Breadth First Search Weighted Shortest path: Dijkstra's algorithm

What is the definition of an undirected graph?

When the edge E consists of two elements such that {v, u} is the same as {u, v}

When does a collision happen in a hash table that maps <key, value> pairs?

When two entries with different keys have the same hash value

Which of the following data structures is the best choice that will store a map of key/value pairs such that the keys can be maintained in sorted order? (a) binary search tree (b) hash table (c) Linked list (d) Binary heap

(a) Binary search tree The key word in the question is that the pairs are maintained in a sorted order

Which of the following is the "move assignment operator" for class MyList, allowing the calling object to trade dynamic resources with the parameter object? (a) MyList& operator(MyList&& m); (b) MyList(MyList&& m); (c) MyList& operator=(const MyList&& m); (d) MyList& operator=(const MyList&& m);

(a) MyList& operator=(MyList&& m); We cannot have the const keyword for m since we want to modify it's resources

Which of the following functions does NOT allow an Employee r-value to be passed as a parameter? (a) int Start(Employee& e); (b) int Start(Employee e); (c) int Start(const Employee& e); (d) int Start(Employee&& e); (e) All of these allow r-value to be passed in

(a) int Start(Employee& e);

Which of the following is NOT a good principle in designing a good hash function: (a) It should be a one-to-one function. (b) It should use all parts of the key (c) It should use the order of information in the key (d) It should result in an even distribution of hash values for different inputs. (e) All of the above should be followed

(a). It should be a one-to-one function. If the hash function is a one-to-one function, then it would be easy to break the hash function once it's solved for one value.

Which of these growth rates analyses generally indicates the worst (i.e. the slowest) algorithm for increasingly large data sets/inputs? (a) Theta(N) (b) Theta(2^N) (c) Theta(N log N) (d) Theta(N^2)

(b) Theta(2^N)

In C++, a function object (a functor) is created by declaring: (a) an object from a class with an overload of operator[] (b) An object from a class with one or more overloads of operator() (c) a function to have the same name as the class (d) an object from a class with a move assignment operator

(b) an object from a class with one or more overloads of operator( )

Which of the following statements is TRUE about priority queues? Assume that without loss of generality the smallest element has the highest priority. (a) Inserts take longer than deletes because data must be maintained in order (b) Inserts and deletes can both be achieved in O(log N) (c) When two elements have equal priority, the first one inserted will be removed first. (d) A priority queue must be implemented with a linear sequence container (e) None of the above are true

(b). Inserts and deletes can be achieved in O(log N)

Which of these is a sequence container that restricts insert operations to only one end of the list, and deletion operations to the other end of the list? (a) Doubly Linked List (b) Stack (c) Queue (d) Deque (e) All of the above

(c) Queue

In the complexity analysis of an algorithm's run time T(N), which of the following represents an Upper Bound on the algorithm's growth rate? (a) T(N) = U(N^2) (b) T(N) = Omega(N^2) (c) T(N) = Big-O(N^2) (d) T(N) = Theta(N^2)

(c) T(N) = Big-O(N^2)

In a typical hash table implementation, what is the underlying storage container that should always be used, regardless of how collisions are handled? (a) linked list (b) binary tree (c) vector/array (d) stack

(c) Vector/Array

In the following code, what does the std::move() function call do? string a = "Data"; string b = "Structures"; b = std::move(a); (a) It swaps the strings a and b (b) It copies the string a into the string b. (c) It returns an r-value reference to the string variable a. (d) It moves the internal resources of the string a to the string b

(c). It returns an r-value reference to the string variable a

True/False A queue is the best data structure to use for implementing a depth-first search

False, queues are best for breadth first searches, while stacks are better for depth first searches

What are the three ways to pick a pivot? List the pros and cons of each

1. Use the first element. ONLY works if the input is random if the input is sorted or mostly sorted the partitions would be huge. 2. Use a random element for the pivot works well, even if the elements are sorted or mostly sorted. However, it isn't effective if the pivot isn't completely random, and PRNG are expensive to use. 3. Median of the three Take the first, last, and middle (or close to middle) value, and of these three select the median value.

Consider the stack based algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of open '(' parentheses that will appear on the stack at any one time when the algorithm analyzes this sequence: ( ( ) ( ( ) ( ) ( ( ) ) ) ( ) )

4 Read this question as: What is the most ( that will be present on the stack during the running of this algorithm

What is a tree?

A data structure that represents a connected graph with no cycles

What is meant by the term "simple path"

A path is simple iff all vertices, except maybe the first and last, and distinct.

What is a path?

A sequence of vertices such that there is an edge for each consecutive vertex.

What is a heap sort?

A sorting algorithm that builds a minHeap(O(N)), and then performs the deleteMin function(O(logN)). The total time complexity is O(NlogN) Requires an extra array to store the deleted elements - This can be avoided by using a heap to store the sorted values, and by using a maxHeap instead of a minHeap

What is bubble sort?

A sorting algorithm that is simple and uncomplicated. It compares neighboring elements and swaps them when our of order. Created by two nested loops and has a runtime of O(N^2)

What is an adjacency matrix?

For a matrix A[n][n], the space required is O(N^2) For an unweighted graph: A[i][j] = 1 if there is an edge between i and j else A[i][j] = 0 For a weighted graph: Instead of assigning 1s and 0s, assign the weight between i and j This representation is wasteful if the graph is spares

Explain Big-O, Big-Theta, and Big-Omega from the following code segment: int list[A][B]; for(int i = 0; i < A; i++) for(int j = 0; j < B; j++) { std::cout << list[i][j] << ' '; if(list[i][j] < 0) break; }

Big-O: The big-O of this code segment is O(N^2), because at worst, both for-loops would be iterated through fully. Big-Omega: The big-Omega of this segment is Omega(N), because in the best case scenario, only the outer loop would need to be iterated though Big-Theta: The big-Theta does not exist for this code segment because the Big-O and big-Omega do not match.

True/False log^k N = Theta(N) for any constant k

False

True/False: A priority queue must be implemented with a binary heap data structure

False

True/False: Dijkstra's Algorithm allows for negative numbers

False

True/False: In a hash table, separate chaining is a collision strategy that finds another vector index for storing an element if there is already one at the original index

False

True/False: The height of a node in a rooted tree can always be obtained by subtracting the depth of the node from the height of the whole tree. i.e. : treeHeight - nodeDepth

False

True/False: If in a digraph H, for each pair of vertices u, v, there is a path that starts at u and ends at v, then H is considered weakly connected.

False, in this case H would be considered strongly connected

True/False: In a Digraph, when the edge {u, v} is present, then the edge {v, u} is also present

False, on a digraph when the edge {u, v} exists then the edge {v, u} is not necessarily present

What is the basic idea of quick sort?

For quick sort, first you pick a pivot point partition the list into two subsets, elements less than the pivot and element greater than the subset. then return subset 1, pivot, then subset 2. Where subset 1 is all elements less than pivot, and subset 2 is all elements greater than pivot.

What is the single-source shortest-path-problem

Given a graph G = (V, E) and a distinguished vertex s find the shortest path from s to every other vertex in G

What does Adjacency mean?

Given graph G = (V, E) vertex w is adjacent to vertex v iff {w, v} exists in E

Which sorting algorithms have a big-O time complexity of NlogN?

Heap sort, Merge sort, and Quick sort

True/False Quicksort is the fastest known sorting algorithm, in practice

True


संबंधित स्टडी सेट्स

Lecture 1 "Audience Response" Questions

View Set

Chapter 37 (Cardiovascular/Hematologic Disorders)

View Set

PADI Open Water DIve Course Summary

View Set

World History - Chapter 13.4 - Spain and Portugal

View Set

Driver and Boater Manual Study Guide

View Set

Clinical Inquiry Exam 2 KEY TERMS

View Set

environmental geology exam review

View Set