CS2420-Exam-2
The height of a binary search tree does not affect the Big O runtime of the insert operator
False
Which of the following is not typically implemented using recursion?
Insertion Sort
A stack is sometimes called a ___________ data structure
LIFO
Removing an element from the stack is a _______________ operation
O(1)
What is the Big O runtime to find an element in a sorted array using binary search?
O(log n)
What is the Big-O runtime of a binary search on an array data structure?
O(log2(n))
What is the Big-O runtime of a sequential search on an array data structure?
O(n)
Insertion sort has a Big O runtime of _________ in the worst case?
O(n^2)
What is the Big O runtime of the summationTable function below: summationTable(int* arr, int size){ for(int i=0; i<size; i++){ for(int j=0; j<size; j++){ cout << arr[i] + arr[j] << " "; } cout << endl; } }
O(n^2)
A ___________ data structure is usually a good fit for data that needs to be processed in the order it arrived
Queue
Dijkstra's algorithm is used to find the _____________
Shortest Path
Which data-structure follows the LIFO (last in first out) model
Stack
Big-O runtime analysis is a(n) ___________ measurement
Theoritical
A stack can be built using
an array or list
Which data-structure follows the FIFO (first in first out) model
correct Queue
Write a max function that compares two values and returns the one with the larger value. Use templates so that your one function can be used to compare ints, floats, doubles, chars, etc.
template<typename T> T Max(T x, T y){ if(x>= y){ return x; }else return y; }
he destructor is executed when
the object goes out of scope
The following hash table and hash function use linear probing. Where (which index) will the value 17 be inserted? Note: E denotes an Empty cell. Hash function: H(x) -> x % table_size
0
When using a hashtable, the hash function should always return a value between _________?
0 and tablesize
Binary trees have at most
2 children
ssume that the code shown here corresponds to the stack structure shown below. What is the value of iptr? int main(){ int x = 5; int* iptr = &x; }
200
Insertion sort has gone through a few iterations and its current state is shown below. What will be the order of the list on the next iteration? sorted | unsorted 3 7 | 5 1 22
3 5 7 | 1 22
Assume an integer is stored using 4 bytes. Suppose iptr is an int* that currently points to memory address 300. What will be the value of iptr after iptr++ is executed?
304
The following hash table and hash function use quadratic probing. Where (which index) will the value 22 be inserted? Note: E denotes an Empty cell. Hash function: H(x) -> (x*3) % tablesize 0 E 4 E E E 12 E E E
7
8 / \ 13 9 / \ / 4 6 7 What is the PreOrderTraversal of the above tree?
8 13 4 6 9 7
Forgetting to delete dynamically allocated memory results in ________________?
A memory leak
What is the output of this code? #include <iostream> using std::cout; class A{ public: void foo(){ cout << "A"; } }; class B : public A{ public: void foo(){ cout << "B"; } }; int main(){ A aObject; B bObject; A* aptr = &bObject; aObject.foo(); bObject.foo(); aptr->foo(); }
A,B ,A
The compiler can automatically generate the following functions:
All of these (correct) Copy Assignment Operator Destructor Default Constructor
In a binary search tree,
All of these : Node values are larger than the data in their left subtrees Nodes have at most two children Node values are smaller than the data in their right subtrees
A graph has an Euler circuit if
All vertices are of even degree
A stack is typically implemented using a(n)____________ as the underlying data-structure
Array or Linked-List
A queue is typically implemented using a(n) _______________ as the underlying data-structure
Array or Linked-list
A heap is a form of
Binary Tree
Which is not one of the four software engineering principles discussed in the textbook?
Construction
Running two algorithms 1000 times and comparing the average elapsed time is an example of _________?
Empirical analysis
Items can be added to either end of a queue
False
You can create an instance of an abstract class
False
Where is memory allocated when you use the new keyword in C++?
Heap
You have data in an unsorted array that is constantly changing (items are being added and removed on a regular basis). Most of the time you do not need to access the data in any particular order. Once in a while you need to find a particular value. Should you first sort the data and the use a binary search or should you just use a linear search
Linear search
Which algorithmic runtime would you generally prefer (all else being equal)?
O (log n)
The Big O runtime to build a heap is?
O( n log n)
Adding an element to the stack is a _____________ operation
O(1)
In an array accessing the nth element takes ____________ time
O(1)
What is the Big O runtime of the char_at found below: char char_at(int pos){ if ( pos < 0 || pos > size){ throw out_of_range("pos is outside the bounds of the string") } return cstr[pos]; }
O(1)
Heapsort is __________________ in the worst case
O(n logn)
Quicksort is ________________ in the average case
O(n logn)
Bubblesort is ________________ in the best case
O(n)
In a linked list accessing the nth element takes ____________ time
O(n)
What is the Big O runtime of the find function found below: int find(char x, string str){ for(int i=0; i<str.size(); i++){ if(str[i] == x){ return i; } } return -1; }
O(n)
What is the Big O runtime to find an element in an array using linear search?
O(n)
A _____________ queue can be used when some items should take precedence of other items
Priority
A heap is often used to implement a ______________ data structure
Priority Queue
In a linked list data must be accessed ___________.
Sequentialy
What type of data structure would you use to keep track of undo/redo operations?
Stack
A pure virtual function does not have an implementation.
True
An AVL tree is a binary search tree.
True
A graph is a collection of ___________ and ______________
Vertices, Edges
Which function adds an item to the queue?
addQueue
Graphs are commonly represented using
an adjacency matrix
An abstract class has
at least 1 pure virtual method
A good hash function should __________
be easy to compute and minimize collisions
To create a class in C++ use the ________ keyword
class
Which is not a technique for dealing with collisions
clustering
If two different values have the same hash key it is called a ___________
collision
What is the Big O runtime to add an item to a queue?
correct O(1)
What is the Big O runtime to push an item onto a stack?
correct O(1)
What is the Big O runtime to remove an item from a queue?
correct O(1)
What is the Big O runtime to remove an item from a stack?
correct O(1)
Merge sort has a Big O runtime of _________ in the worst case?
correct O(n log(n))
Quicksort has a Big O runtime of _________ in the worst case?
correct O(n^2)
In order to perform a binary search on an array what must be true about the data stored in the array?
data stored in array
A queue can be implemented using ___________ as the underlying data structure
either a linked list or an array
A constructor can be a pure-virtual constructor.
false
A singly linked list can be traversed in which direction?
forward
A doubly-linked list can be traversed in which direction?
forward and backward
A priority queue is often implemented using a ______________ datastructure
heap
If a hash table is using chaining to deal with collisions, what happens when a collision occurs while inserting a new value?
if it is chaining then next value will be insert under this value
Using the last element the array as the pivot for quicksort produces poor performance______________________________
if the list is mostly ordered
An abstract data type specifies
methods/operations
A minimum heap will have the __________ value at the top of the heap
minimum
A common function for hashing is
modulo
A simple graph has
no loops , no parallel edges
A heap is _____________
partially ordered
Deleting node in a binary tree should be done
postOrder
Which member access specifier allows access to a data member from both inside and outside the class?
public
Which method is used to add data to the stack?
push
Which method is used to retrieve the last element added to the stack without removing it from the stack?
top
To use a dynamically allocated array you must also use pointers
true
What is the output of the following program? #include <iostream> using std::cout; using std::endl; int main(){ int x = 5; int* iptr = &x; x = 3; *iptr = 7; cout << x << endl; }
x = 7