Data Structures Final Exam

Ace your homework & exams now with Quizwiz!

What types of notation are used for lower, upper, and lower _ upper bounds?

O notation is used for upperbound (worst case), Omega is used for best case (lower bound) and Theta is used for a growth rate that is both an upper and lower bound

What is Merge sort's runtime complexity?

O(N log N)

What is the space complexity of a linked list?

O(N)

What is the runtime complexity of selection sort?

O(N^2)

What is Shell Sort's runtime complexity?

O(N^3/2)

What is HeapSort's worst-case runtime?

O(NlogN)

What is a BST's worst case search runtime complexity?

O(log2N) + 1

If a condition value for that a loop is executed is halved at each iteration - what is the algorithms run-time complexity?

O(logN)

What is the only sorting algorithm that is not a comparison sorting algorithm?

Radix sort

Which sorting algorithm uses a gap value to jump between elements, and is difficult to adapt to linked lists for this reason?

Shell sort

What are some sorting algorithms that are difficult to adapt to sort linked lists?

Shell sort, quick sort, Heap sort

Why are sorting algorithms for arrays generally more difficult to adapt to singly-linked lists than to doubly-linked lists?

Singly-linked lists do not support backward traversal

When more than 1 of the list's nodes contains the search key, ListSearch returns _____ node containing the key.

The first

What are the two requirements a graph must have for there to be a minimum spanning tree made of it?

The graph must be weighted and connected. A connected graph contains a path between every pair of vertices The graph can be directed or undirected

What notable features do recurrence relations have?

They are used to judge runtime complexity for recursive algorithms - they will have "T" on both sides of the equation, rather than just one of them.

What is the Open addressing collision resolution technique?

This is a collision resolution technique where collisions are resolved by looking for an empty bucket elsewhre in the table

How does a depth-first-search work?

This is a traversal that visits a starting index, then visits every vertex along each path starting from that vertex to the path's end, before backtracking.

True/False - ShellSort will properly sort an array using any collection of gap values - provided the collection contains 1

True

How to choose the pivot in Quicksort?

Want it to be in the middle as much as possible. Median-of-three picks the ends and the median value and sorts all three. Then it uses the middle value as the first pivot.

What is QuickSort's runtime complexity?

Worst case O(n^2) Average case O(NlogN)

Removing at index 0 of an arraylist yields what kind of runtime?

Worst case runtime

A hash table with a direct has function is called

a direct access table

Each hash table array element is called a

bucket

What index is an element re-inserted into after a resize operation is triggered?

element % new table size

A binary tree is full if

every node contains 0 or 2 children

The head of a circular linked list is often referred to as the

start node

What are the relational properties that must be observed in a valid max-heap?

1) The root node is always the maximum node 2) every parent node is greater than it's children

What are the child indices for a node at index 6?

2 * i + 1, 2 * i +2 2 * 6 + 1 = 13 2 * 6 + 2 = 14

For quicksort - how many partitioning levels are required for a list of 8 elements?

3 levels 1 - (a,b,c,d)(e,f,g,h) 2 - (a,b)(c,d)(e,f)(g,h) 3 - (a)(b)(c)(d)(e)(f)(g)(h)

What is a recursive algorithm's base case?

A case where a recursive algorithm completes without applying itself to a smaller subproblem (necessary for a recursive algorithm to terminate)

When would inserting a new node to an AVL tree result in no height value changes for all ancestors?

A new node is inserted as a child of an internal node with 1 child

What is a trie?

A trie is a tree representing a set of strings. Each node represents a single character and has at most one child per distinct alphabet character. Each string has a terminal node - which is a node that represents the end of a string in the trie

A traversal through a circular linked list is similar to a traversal through a standard linked list except for what?

After reaching the head node a second time it must terminate - as opposed to reaching null

What does a direct hash function do?

Direct hashing uses the item's key as the bucket index

(T/F) A priority queue is always implemented using a heap

False

(T/F) The edges from any minimum spanning tree can be used to create a path that goes through all vertices in the graph without ever encountering the same vertex twice

False

(T/F) A minimum spanning tree is a set of vertices

False A minimum spanning tree is a set of edges

(T/F) The search algorithm stops only when encountering a bucket containing the key being searched for.

False - Probing N buckets or encountering an empty-since-start bucket will also stop the search

(T/F) An AVL tree maintains the minimum possible height

False - an AVL tree doesn't always have the minimum possible height, but has a height no worse than 1.5x the minimum

T/F Calling ShellSort with gap array (7, 3, 1) vs (3, 7, 1) produces the same result with no difference in efficiency

False - both will produce sorted arrays, but one will be more efficient than the other.

(T/F) A hash table implementation must use only one criteria for resizing

False - multiple criteria can be used together

(T/F) If items in a priority queue with a lower numerical value have higher priority, then a max-heap should be used to implement the priority queue.

False - priority queues use min-heaps.

(T/F) For a directed, acyclic graph, only one possible topological sort output exists

False - there can be more than one valid topological sort

What are some sorting algorithms that are easy adapted to efficiently sort linked lists?

Insertion sort and merge sort

How does removal from a max heap work?

A remove from a max-heap is always a removal of the root, and is done by replacing the root with last level's last node, and swapping that node with its greatest child until no max-heap property violation occurs

What is a stack?

A stack is an ADT in which items are only inserted on or removed from the top of a stack. Push inserts to the top of the stack, pop removes the item from the top of the stack Often implemented using a linked list

How does MergeSort work?

It divides a list into two halves, recursively sorts each half, and merges the sorted halves to produce a sorted list. The recursive partitioning continues until a list of 1 element is reached as a list of 1 element is already sorted.

How does Shell Sort work?

It uses a gap value in order to create interleaved lists, and it sorts the elements that are in between the gap values with each other. Then they are shifted, and the process repeats. Once all elements are touched, the gap value is reduced by one and the process is repeated until the gap value becomes 1 and the array is sorted.

How does double-hashing work?

Double hashing uses 2 different functions to computer bucket indices: (h1(key) + i * h2(key)) % tablesize

Determine the index j and the left and right partitions. numbers = (1, 2, 3, 4, 5), i = 0, k = 4

j = (i + k)/2 = (0 + 4)/2 = 2 Elements from i to j, inclusive, are in the left partition. left partition (1,2,3) right partition (4,5)

What is binary search's efficiency in a sorted list?

log2N

What is the process for removing an internal node with two children?>

1) find the node-to-be-removed's succesor 2)Copy successor to the current node 3) remove successor from right subtree

What limitations does a direct access table have?

All keys must be non-negative integers The hash table's size equals the largest key value + 1, which may be very large

What is the ordering property of a binary search tree?

All of the node's left subtree keys are less than or equal to the node's key All of the node's right subtree is greater than or equal to the node's key

What is an AVL tree?

An AVL tree is a BST with a height balance property and specific operations to rebalance the tree when a node is inserted or removed. If an AVL tree violates a BST property, then it is NOT an AVL

What does the append operation for a singly-linked-list do? What does prepend do

Append inserts the new node after the list's tail node Prepend inserts it before the list's head node

How does binary search work?

Binary search first checks the middle element of the list. If the search key is not found, the algorithm focuses on the left sublist or the right sublist depending on if the element was greater or less than the search element. Only works on a sorted list.

For quicksort - how many partitioning levels are required for a list of 1024 elements? How many comparisons?

logbase2 1024 = 10 logbase2 1024 * 1024 = 10240 comparisons

How to find midpoint in Quicksort?

midpoint = lowIndex + ((highIndex - lowIndex)/2) If it's a fraction, you round down

If myList is a singly-linked list with a dummy node, which statement is true when the list is empty?

myList->head == myList->tail

(T/F) When implementing a priority queue with a heap, no operation will have a runtime complexity worse than O(logN).

True Enqueue and Dequeue are worst case O(logN) the rest of the operations run in constant time

(T/F) In a hash table using open addressing, the load factor cannot exceed 1.0

True - since in open addressing, one bucket holds at most one item.

What is a queue? How does it work?

A queue is an ADT in which items are inserted at the end of the queue and removed from the front of the queue. referred to as a FIFO ADT often implemented using a linked list

What are some requirements of a graph for topological sorting?

- The graph must be acyclic - The graph must be directed

How does a bredth-first-search work?

This is a traversal that visits a starting vertex, then all vertices of distance 1 from that vertex, then distance 2, and so on.

(T/F) Only 1 minimum spanning tree exists for a graph that has no duplicate edge weights

True

(T/F) The edge with the lowest weight will always be in the minimum spanning tree

True

What is the parent index for a node at index 12 in a heap?

(i - 1)/2 (12 - 1)/2 = 5 (always round down)

What are some common constant time operations?

- Mathematical operations - assignment to a variable - comparison of two fixed size data values - read or write an array element at particular index

Rank the common growth rates in big O from fastest to slowest

- O(1) - O(logN) - O(N) - O(NlogN) - O(N^2) - O(c^N)

What is the ranking of the sorting algorithms from slowest to fastest?

- Selection Sort (O(N^2)) - Insertion Sort (O(N^2)) - Shell Sort (O(N^1.5)) Everything above is consider a slow sorting algorithm, and everything below is considered a fast sorting algorithm - QuickSort (N log N) - Merge Sort (NlogN) - Heap sort (NlogN) - Radix Sort (O(N))

How does selection sort work?

- Selection sort treats the input as two parts - a sorted and unsorted part - the algorithm searches the unsorted part for the smallest element, and stores it's index - Elements at i and indexsmallest are swapped. - Sorted and unsorted parts are updated. - Process repeats until everything is sorted - elements to the LEFT of i are sorted - elements to the RIGHT of i are unsorted

Suppose a recursive function's runtime is T(N) = 7 + T(N - 1), how many levels will a recursion tree have? What is the runtime complexity of the function using O notation?

- The recursion tree will have N levels - Since the recursion tree has N levels and does a constant number of operations at each level, the time complexity is O(N)

What is a BST remove algorithms worst case runtime complexity?

- Worst case time complexity is O(logN) for a BSt with log2N levels and worst case O(N) for a tree with N levels

How does insertion sort work?

- it works left to right. Examines each item and compares it to items on its left. Then, it inserts it into the correct position in the array by moving it down the list and comparing the elements on the right and on the left

If ListTraverse is called to traverse a list with 10 nodes, how many calls to ListTraverseRecursive are made?

11 - one for the null node

How many times is InsertionSortInterleaved called if ShellSort is called with gap array (10, 2, 1)?

13 (10 + 2 +1)

When is a BST height balanced?

A BST is height balanced, if for any node, the heights of the node's left and right subtrees differ by only 0 or 1

What is a deque (pronounced "deck)?

A deque is an ADT in which items can be inserted and removed at both the front and the back

What is a dummy node? Why are they used?

A dummy/header node is a node with an unused data member that always residers at the head of the list and cannot be removed. Using a dummy node simplifies the algorithms for a linked list because the head and tail pointers are never null The head point always points to the dummy node, but the tail pointer will not point to the dummy node unless the list is empty

How does a hash table resize function work?

A hashtable resize operation increases the number of buckets, while preserving all existing items. A hash table with N buckets is commonly resized to the next prime number >= N*2 A new array is allocated, and all the items from the old array are re-inserted into the new array, making the resize operation's time complexity O(N)

What is a perfect hash function? What are the runtime complexities of it's operations?

A perfect hash function maps items to buckets with no collisions. Can be created if the number of items and all possible items keys are known beforehand. The runtime for insert, search, and remove is O(1) with a perfect hash function

What is the definition of a prime number?

A prime number is a number that can only be divided by itself and 1 without remainders - its best to use a prime number as the modulo number when dealing with quadratic probing and double hashing

How does a doubly-linked list work?

Each node has data, a pointer to the next node and a pointer to the previous node

What aspect of linked lists makes adapting array-based sorting algorithms to linked lists difficult?

Elements in a linked list cannot be accessed by index

What does enqueue do? What does dequeue do?

Enqueue = Inserts an item at the end of the queue Dequeue = removes item from the front of a queue

(T/F) Calling Heapsort on an array with 1 element will cause an out of bounds array access

False

(T/F) Heapsort uses recursion

False

(T/F) When traversing down a BSP tree, half the objects are eliminated each level.

False

T/F A linked list must have a list data structure

False

T/F A fast sorting algorithm's worst case runtime must be O(NlogN) or better

False - fast sorting algorithms are classified based on average case, not worst case runtime complexity.

(T/F) For collision resolution - the insertion algorithm can only insert into empty-since-start buckets

False - it can insert into both

(T/F) The Dequeue and Peek operations both return the value in the root, and therefore have the same worst-case runtime complexity.

False. Dequeue's worst case runtime is O(logN), peek's worst case runtime is O(1)

How does quadratic probing handle a collision?

It handles a collision by starting at the key's mapped bucket and quadratically searches subsequent buckets until an empty bucket is found. The formula used is (H + c1*i+c2*i^2) % (tablesize)

How does insertion work in a max heap?

It starts by inserting the node in the tree's last level, and then swapping the node with its parent until no max-heap property violation occurs. This is called percolating. Worst case runtime is O(logN)

How does QuickSort work?

It uses a pivot - which is an element that meets the following three conditions: - Correct position in final, sorted array - Items to the left are smaller - Items to the right are larger 1) Choose a pivot and move it to the end of the array to get it out of the way 2) Then look for itemFromLeft - which is the first item from the left that is larger than the pivot. Then look for itemFromRight - which is the first element that is smaller than the pivot 3) swap item from left with item from right. 4) repeat process until itemFromLeft has a greater index than itemFromRight 5) Swap itemFromLeft with the pivot. 6) Choose the next pivot.

What is the fastest average runtime complexity of a comparison sorting algorithm?

O(NlogN) This is HeapSort and QuickSort

What is a hash table's load factor?

THis is the number of items in the hash table divided by the number of buckets This is used to decide when to resize the hash table

What is the only node in a BST that has no successor?

The largest, right most node

What is the lower bound for an algorithm? The upper bound?

The lower bound of the algorithm is the best case runtime complexity, while the upper bound is the worst case runtime complexity

What is the runtime complexity of insertion sort? What about the runtime complexity of insertion sort for a nearly sorted list?

The runtime complexity of insertion sort is O(N^2) The runtime complexity of insertion sort for a nearly sorted list is O(N)

What is a node's balance factor?

This is the left subtree height minus the right subtree height - if it's greater than 1, then the AVL tree needs to be rebalanced

What is the chaining collision resolution technique?

This is where each bucket has a list of items when collisions happen

What is the linear probing collision resolution technique?

This technique handles a collision by starting at the key's mapped bucket and then linearly searches subsequent buckets until a empty bucket is found. When searching using this technique, it will only stop for an empty-since-start bucket, but not for an empty-after-removal bucket

(T/F) A BSP implementation could choose to split regions in arbitrary locations, instead of right down the middle.

True

(T/F) Double hashing would never resolve collisions if the second hash function always returned 0.

True

(T/F) When resizing to a larger size, the load factor is guaranteed to decrease

True

T/F Neither search nor remove-at-will will resize the list's array

True

(T/F) If the hash table was using open addressing, a load factor < 0.25 guarantees that no more than 25 collisions will occur during insertion.

True Also only a load factor of 1.0 in open addressing guarantees a collision

A binary tree is complete if

all levels, except possibly the last level, contain all possibl enodes and all nodes in the last level are as far left as possible

A binary tree is perfect

if all internal nodes have 2 children and all leaf nodes are at the same level


Related study sets

kin 245 the wrist and hand joints

View Set

Erik Erikson's of Psychosocial Development

View Set