CSIT Test 2
Which sorts have a time complexity of (On^2)? (Quadratic sorts)
Selection, insertion, and bubble
The node to remove is a leaf; it can simply be deleted
Situation 1
The node to remove has one child; the deleted node is replace by the child
Situation 2
The node to remove has two children; an appropraite node is found lower in the tree and used to replace the node
Situation 3
Which of the following traversals never visits the root? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
none of the above
*BST operations:* Returns a reference to the maximum element in the tree.
findMax
*BST operations:* Returns a reference to the minimum element in the tree.
findMin
What order do elements go in and out in a queue?
FIFO
A full binary tree of height n has _________________ leaves. a) 2^n b) 3n c) 2n d) 2(n+1) e) 3(n+1)
2^n
One method of implementing a tree using an array involves storing the child of the element at the index n in the array at indexes ______________________________ . a) n+1 and n+2 b) 2^n and 2^2n c) 2n+1 and 2n+2 d) n-1 and n-2 e) none of the above will work
2n+1 and 2n+2
A tree whose nodes represent decision points, and whose children represent the options available; the leaves represent the conclusions that might be draw. Ex Diagnosis
Decision tree
Lists whose elements can be referenced using a numeric index.
Indexed list
Which of the following traversals traverse the left subtree, then visit the root, then traverse the right subtree? (LVR) a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Inorder
Sort that orders a value by repetitively inserting a particular value into a sorted subset of the list. - consider the first item to be a sorted sublist of length 1 - insert the second item into the sorted sublist, shifting the first item if needed - insert the third item into the sorted sublist, shifting the other items as needed - repeat until all values have been inserted into their proper positions
Insertion sort
Used to define a collection from which an iterator can be extracted.
Iterable
An object that provides a way to access each element in a collection in turn.
Iterator
Pseudocode for Postorder traversal:
LRV - Left, Right, Visit
Pseudocode for Inorder traversal:
LVR - Left, Visit, Right
Which of the following is always true when adding an element to a heap? a) The new element will always be a leaf. b) The new element will always be the root. c) The new element will always be an internal node. d) The new element will always have 2 children. e) None of the above is always true
None of the above is always true
Finding an element in a balanced binary search tree that contains n elements requires _____________________ comparisons. a) O(1) b) O(n) c) O(2n) d) O(log2 n) e) none of the above
O(log2 n)
In the worst case, a general binary search tree could require __________________ comparisons to find an element. a) O(1) b) O(n) c) O(2n) d) O(log2 n) e) none of the above
O(n)
Lists whose elements are ordered by some inherent characteristic of the elements.
Ordered list
*Ordered List ADT:* Adds an element to the list.
add
*Queues ADT:* Ensures that the queue contains the given element; throws an exception if the element can't be added.
add
*BST operations:* Add an element to the tree.
addElement
Search that eliminates large parts of the search pool with each comparison; compare target number to the middle value.
binary search
A tree that, for each node: - the left subtree of n contains elements less than the element stored in n - the right subtree of n contains elements greater than or equal to the element stored in n
binary search tree
A regular array that is treated as if it loops back around on itself.
circular array
*Binary Tree ADT:* Determines whether the specified target is in the tree.
contains
*Binary Tree ADT:* Returns a reference to the specified target element if it is found
find
*Binary Tree ADT:* Returns a reference to the specified target element if it is found.
find
*Queues ADT:* Removes an element from the front of the queue.
dequeue
*Binary Tree ADT:* Determines whether the tree is empty.
isEmpty
*Binary Tree ADT:* Returns an iterator for an inorder traversal of the tree.
iteratorInOrder
*Binary Tree ADT:* Returns an iterator for an level-order traversal of the tree.
iteratorLevelOrder
*Binary Tree ADT:* Returns an iterator for an postorder traversal of the tree.
iteratorPostOrder
*Binary Tree ADT:* Returns an iterator for an preorder traversal of the tree.
iteratorPreOrder
Rotation that corrects an imbalance caused by a long path in the right subtree of the left child of the root - make the right child element of the root the new root element - make the former root element the left child element of the root - make
left rotation
*Queues ADT:* Returns a boolean (true/false) indicating success or failure.
offer
*BST operations:* Remove all occurences of element from the tree.
removeAllOccurences
*BST operations:* Remove an element from the tree.
removeElement
*BST operations:* Remove the maximum element in the tree.
removeMax
*BST operations:* Remove the minimum element in the tree.
removeMin
Rotation that corrects an imbalance caused by a long path in the left subtree of the left child of the root - make the left child element of the root the new root element - make the former root element the right child element of the new root - make the right child of what was the left child of the former root the new left child of the former root
right rotation
Operations on binary search trees to assist in the process of keeping a tree balanced
rotations
A tree whose elements are organized to facilitate finding a particular element when needed.
search tree
The process of finding a target element among a group of items, or determing that it doesn't exist
searching
*Binary Tree ADT:* Returns the number of elements in the tree.
size
In a maxheap, the largest element in the structure is always ______________________ . a) a leaf b) an internal node c) the root d) the left child of the root e) the right child of the root
the root
*Binary Tree ADT:* Returns a string representation of the tree.
toString
List composed of objects that each point to the next object in the list.
Linked list
Which of the following traversals is implemented using a queue as a supporting data structure? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Level-order
Which of the following traversals is not easily implemented recursively? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Level-order
Which of the following traversals visits the nodes that are closer to the top of the tree before visiting those that are closer to the bottom? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Level-order
Structure that uses object references to create links between objects; can be used to form non-linear structures.
Linked structure
What sort has a time complexity of O(n log n)? (Logarithmic sort)
Merge
Sort that orders values by recursively diving the list in hald until each sub-list has one element, then recombing - divide the list into two roughly equal parts - recursively divide each part in half, continuing until a part contains only one element - merge the two parts into one sorted list - continue to merge parts as the recursion unfolds
Merge sort
What are the 3 major types of list collections?
Ordered lists, Unordered lists, Indexed lists
Which of the following traversals visits the root *after* visiting the left and right subtrees? (LRV) a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Postorder
Which of the following tree traversals traverses the subtrees from left to right and then visits the root? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Postorder
Which of the following traversals visits the root *before* visiting the left and right subtrees? (VLR) a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above
Preorder
Sort that orders values by partitioning the list around one element, the sorting each partition. - choose one element in the list to be the partition element - organize the elements so that all elements less than the partition element are to the left and all greater are to the right - apply the quick sort algorithm (recursively) to both partitions
Quick sort
Sort that makes 3 passes through the data, for each position of 3-digit numbers - A value is put on the queue corresponding to that position's digit - Once all three passes are finished, the data is sorted in each queue
Radix sort
Sort that orders a list of values by repetitively putting a particular value into its final position. - find the smallest value in the list - switch it with the value in the first position - find the next smallest value in the list - switch it with the value in the second position - repeat until all values are in their proper places
Selection sort
What are some types of sorting algorithms?
Selection, Insertion, Bubble, Quick, Merge, Radix
The process of arranging a group of items into a defined order based on particular criteria
Sorting
A ________ is a collection whose elements are added on one end and removed from theother; FIFO - elements are removed in the same order they arrive. Ex. Checkout line
queue
Sort which orders a list of values by repetitively comparing neighboring elements and swapping their positions if necessary - scan the list, exchanging adjacent elements if they are not in relative order; this bubbles the highest value to the top - scan the list again, bubbling up the second highest value - repeat until all elements have been placed in their proper order
Bubble sort
Tree that shows the relationships among operators and operands in an expression; evaluated from the bottom up.
Expression tree
Nodes that can be reached by following a parth from a particular node are the _______________ of that node.
descendants
*Queues ADT:* Adds an element to the rear of the queue.
enqueue
*List ADT:* Examines the element at the front of the list.
first
*Queues ADT:* Examines the element at the front of the queue.
first
*Binary Tree ADT:* Returns a reference to the root of the binary tree
getRoot
*Binary Tree ADT:* Returns a reference to the root of the binary tree.
getRoot
Which of the following best describes a balanced tree? a) A balanced tree has all nodes at exactly the same level. b) A balanced tree has no nodes at exactly the same level. c) A balanced tree has half of the nodes at one level and half the nodes at another level. d) A balanced tree has all of the nodes within one level of each other. e) None of the above correctly describe a balanced tree.
A balanced tree has all of the nodes within one level of each other.
Lists whose elements have no inherent order but are ordered by their placement in the list.
Unordered list
Pseudocode for Preorder traversal:
VLR - Visit, Left, Right
*Unordered List ADT:* Adds an element after a particular element already in the list.
addAfter
*Unordered List ADT:* Adds an element to the front of the list.
addToFront
*Unordered List ADT:* Adds an element to the rear of the list.
addToRear
A binary search tree that is highly unbalanced is called a ________________ tree. a) full b) complete c) degenerate d) unsearchable e) none of the above
degenerate
*Binary Tree ADT:* Determines whether the specified target is in the tree
contains
*List ADT:* Determines if the list contains a particular element.
contains
A _________________ can be used as the basis for an expert system. a) queue b) stack c) ternary tree d) 4-ary tree e) decision tree
decision tree
In a binary search tree, the elements in the right subtree of the root are __________________ the root element. a) greater than b) less than c) greater than or equal to d) less than or equal to e) equal to
greater than or equal to
A ____________________ is a complete binary tree in which each element is greater than or equal to both of its children. a) binary search tree b) stack c) full tree d) heap e) none of the above
heap
The __________ of a tree is the length of the longest path fro the root to a leaf
height
A node that is not the root and has at least one child
internal node
*Binary Tree ADT:* Determines whether the tree is empty
isEmpty
*List ADT:* Determines if the list is empty.
isEmpty
*Queues ADT:* Determines if the queue is empty.
isEmpty
*Binary Tree ADT:* Returns an iterator for an inorder traversal of the tree
iteratorInOrder
*Binary Tree ADT:* Returns an interator for a level-order traversal of the tree
iteratorLevelOrder
*Binary Tree ADT:* Returns an interator for a postorder traversak of the tree
iteratorPostOrder
*Binary Tree ADT:* Returns an iterator for a preorder traversal of the tree
iteratorPreOrder
*List ADT:* Examines the element at the rear of the list.
last
When adding a new element to a binary search tree, the element is added as a(n) ______________. a) internal node b) subtree c) leaf d) root e) none of the above
leaf
A node that has no children.
leaf node
In a binary search tree, the elements in the left subtree of the root are __________________ the root element. a) greater than b) less than c) greater than or equal to d) less than or equal to e) equal to
less than or equal to
The __________ of a node is the length of the path from the root to the node.
level
A balanced binary tree with m elements will have height ______________ . a) 2m b) 2m c) logm 2 d) log2 m e) none of the above
log2 m
When removing an element from a binary search tree, we must always ______________________. a) make sure that the new tree is a binary search tree b) build a new tree c) find its inorder successor d) remove all of its children e) An element should never be removed from a binary search tree
make sure that the new tree is a binary search tree
What property of the tree does its order specify? a) maximum height b) maximum number of leaves c) maximum number of internal nodes d) maximum number of edges e) maximum number of children per node
maximum number of children per node
A _________________ is a nonlinear structure in which elements are organized into a hierarchy. a) binary b) ternary c) n-ary d) general e) graph
n-ary
A __________ can only have one parent, but may have multiple children. Those that have the same parents are siblings.
node
The _________ ___________ is the number of edges followed to get from the root to the node.
path length
*Queues ADT:* When empty, this method returns null.
poll
*List ADT:* Removes a particular element from the list.
remove
*Queues ADT:* When empty, this method throws an exception
remove
*List ADT:* Removes the first element from the list.
removeFirst
*List ADT:* Removes the last element from the list.
removeLast
A series of integers that determine how much each character is shifted
repeating key
When removing an element from a binary search tree that has two children, _______________________ will ensure that the resulting tree is still a binary search tree. a) replacing it with its only child b) replacing it with its inorder successor c) simply deleting it d) all of the above e) neither a, b, nor c
replacing it with its inorder successor
When removing an element from a binary search tree that is a leaf, ______________ will ensure that the resulting tree is still a binary search tree. a) replacing it with its only child b) replacing it with its inorder successor c) simply deleting it d) all of the above e) neither a, b, nor c
replacing it with its only child
A _____________________ is a tree whose elements are organized to facilitate finding a particular element when needed. a) full tree b) complete tree c) binary tree d) search tree e) none of the above
search tree
*Binary Tree ADT:* Returns the number of elements in the tree
size
*List ADT:* Determines the number of elements on the list.
size
*Queues ADT:* Determines the number of elements on the queue.
size
A tree structure that makes up part of another tree
subtree
*Binary Tree ADT:* Returns a string representation of the tree
toString
*Queues ADT:* Returns a string representation of the queue.
toString
A _________________ is a non-linear structure in which elements are organized into a hierarchy. a) graph b) tree c) queue d) stack e) linked-list
tree
If a binary search tree becomes unbalanced after an element is added, it is sometimes possible to efficiently rebalance the tree by ___________________ . a) using left and right rotations b) selecting a leaf node to use as a new root c) reconstructing the tree from scratch d) all of the above e) it is impossible to rebalance a tree efficiently
using left and right rotations