CS 133 Practice Quiz 6 & &

Ace your homework & exams now with Quizwiz!

If a new node is inserted into the right subtree of a right subtree and causes an imbalance, an AVL tree requires:

a single left rotation

A depth-first search algorithm uses:

a stack

Which of the following is true?

Any bit "ANDed" with 0 yields 0

Which of the following is not a bitwise operator? & ~ ^ *

*

If vertex 1 in a graph is connected directly to vertex 2 by an edge, we say that:

1 and 2 are adjacent

In the tricolor algorithm, grey nodes are:

nodes that have been discovered but haven't been dealt with yet

If you have a 1000-element balanced binary search tree, what is the maximum number of comparisons that may be needed to find an element in the tree?

10

Evaluate (00001000 & 11000101) ^ (11110000)

11110000

Add the following nodes to a binary search tree in the order they appear. 6 35 17 19 16 10 23 3 What is the output of a post-order traversal of this tree? - 10 16 23 19 17 34 3 6 - 3 10 16 23 19 17 34 6 - 6 3 34 17 16 10 19 23 - 3 6 17 16 10 19 23

3 10 16 23 19 17 34 6

Let Bit1 = Bit2 = 1. Which of the following does not have the same result as the others?

Bit1 ^ Bit2

Which of the following statements about binary search trees is false?

In a tightly packed binary search tree, each level contains about half as many elements as the previous level. (The previous level is the level closer to the root node.)

A hash function has the complexity: - O(n) - O(logn) - O(1) - O(nlogn)

O(1)

A well-balanced binary search tree can be searched for a value in:

O(logn)

A seriously unbalanced binary search tree can be searched for a value in:

O(n)

An AVL is: (select the most accurate answer) - a binary tree that balanced its nodes so that the median value is always the root - a height-balanced BST that rebalances automatically after every insertion or deletion - any tree that retains its height balance after insertions and deletions - a BST that places all values less than the root to its left and all values greater than the root to its right

a height-balanced BST that rebalances automatically after every insertion or deletion

If a new node is inserted into the right subtree of a left subtree and causes an imbalance, an AVL tree requires:

a left-right rotation

Which statement is not true for binary trees: - the children of a node are called siblings - the root node is the first node in the tree - the left child in the root node is the first node in the left subtree - a node with no children is called an orphan

a node with no children is called an orphan

A breadth-first search algorithm uses:

a queue

If a new node is inserted into the left subtree of a right subtree and causes an imbalance, an AVL tree requires:

a right-left rotation

A navigation app would need to use:

a shortest-path algorithm

If a new node is inserted into the left subtree of a left subtree and causes an imbalance, an AVL tree requires:

a single right rotation

A topological sort is useful for finding: - vertices in a graph that are unconnected - the cost of reaching every vertex in a graph - the shortest path from one vertex to another - a traversal order for a directed, acyclic graph

a traversal order for a directed, acyclic graph

In C++, an adjacency list can easily be created using: - a vector of vectors of ints - a two-dimensional array - a priority queue of Edge objects - any of these will work

a vector of vectors of ints

Prim's algorithm: - always chooses the edge with the least cost - creates a spanning tree - finds the minimum cost to connect all vertices - all of these are true

all of these are true

Select the incorrect statement. Binary trees (regardless of the order in which the values are inserted into the tree) - can be sorted efficiently - are nonlinear data structures - always have multiple links per node - always have the same shape for a particular data set

always have the same shape for a particular data set

A graph is often represented using an adjacency list, which is designed with: - a stack - a linked list of arrays - an array of lists - an array

an array of lists

In bitwise manipulations, a mask is typically: - an integer value with specific bits set to 0 - a floating point value with specific bits set to 1 - a floating point value with specific bits set to 0 - an integer value with specific bits set to 1

an integer value with specific bits set to 1

To implement a weighted graph in C++, it makes sense to create

and Edge struct to hold the endpoints and the weight of each edge

AVL defines a balanced BST to be one where: - all leaf nodes reside in the same level (row) - the root node's children both have the same height - any two sibling subtrees do not differ in height by more than one level (row) - all of these are true

any two sibling subtrees do not differ in height by more than one level (row)

A node can only be inserted __________ in a binary search tree.

as a leaf node

Which operator sets the bits in the result to 1 if at least one of the corresponding bits in the two operands is 1?

bitwise inclusive OR

In a breadth-first search of a graph, vertices are examined:

based on their proximity to the current root

The most basic unit of data on a computer is the

bit

Which operator sets the bits in the result to 1 only when the corresponding bits in the two operands are both 1?

bitwise AND

In rewriting a BST to behave as an AVL, which functions would not need to be rewritten?

find

An unbalanced tree is one where: - a large majority of the values are greater than that of the root node - a large majority of the values are less than that of the root node - both must be true to cause an unbalanced tree - either of these cases will cause an unbalanced tree

either of these cases will cause an unbalanced tree

The balance factor for each node is normally stored: - in a balance_factor array in the BST struct - in the main source code - in a balance_factor struct - in the node struct

in the node struct

Which type of binary search tree traversal processes the node values in ascending order? - duplicate elimination order - post-order traversal - in-order traversal - pre-order traversal

in-order traversal

Which statement is true of the << operator? - it's called the right shift operator - it's called the bitwise right shift operator - it shifts the bits of the second operand left by the number of bits specified by the first operand (no) - it fills from the right with 0 bits

it fills from the right with 0 bits

The primary problem with an unbalanced tree is that: - it is harder to delete values from - it is more difficult to traverse - it is less time efficient - it is less space efficient (no)

it is less time efficient

Which statement is true of the >> operator?

it shifts the bits of the first operand right by the number of bits specified by the second operand

Which statement is false? - the result of shifting a value is undefined if the right operand has more bits than the number of bits in which the left operand is stored (no) - the result of shifting a value is undefined if the right operand is negative - left shifting is machine dependent - right shifting is machine dependent

left shifting is machine dependent

The bitwise operators can be used to manipulate the bits of variables of type

long

The steps for an in-order traversal of a binary search tree include each of the following except

skip over duplicate values

Suppose you have a list of names sorted in alphabetical order, already stored in one of the data types below. The easiest way to print the names in reverse alphabetical order would be to use a

stack

The balance factor of a node is defined as:

the height of the right subtree minus the height of the left subtree

Which statement about the level-order traversal of a binary tree is false?

the search begins at the row of the leftmost leaf node

Dijkstra's algorithm finds:

the shortest path from one vertex to another

Which of the following statements about binary search trees with no duplicate values is false? - the values in any right subtree are less than the values in its parent node - the shape of the tree that corresponds to a particular set of data can vary based on the order in which the values are inserted into the tree - the values in any left subtree are less than the values in its parent node (no) - it is possible that a binary tree could contain all its values along one straight path through the tree (no)

the values in any right subtree are less than the values in its parent node

Which is not true about simple undirected graphs: - they have no edges with defined heads and tails - they have no duplicate edges - they have no cycles - they have no loops

they have no cycles

Parts of a graph include:

vertices and edges

Which of the following statements is false? - pointers should not be left uninitialized - function malloc returns NULL if it's unable to allocate the requested memory - undefined behavior occurs when you attempt to use free to deallocate dynamic memory that was already deallocated - when you use free to deallocate dynamically allocated memory, the pointer passed to free is set to NULL

when you use free to deallocate dynamically allocated memory, the pointer passed to free is set to NULL

For any eight-bit non-zero x, which of the following does not result in zero? x ^= x x <<= 8 x |= x x &= (~x)

x |= x

Which statement is true? - | is the logical or operator - || and | are each binary operators - operators || and | are interchangeable - || is the bitwise or operator

|| and | are each binary operators


Related study sets

Chap 21: Allergy and Anaphylaxis

View Set

Unit 2 - Practice Test - ch 2,6,7,8

View Set

Chapter 8 Emergency Care, First Aid, and Disasters

View Set

Supply Chain Chapter 11 Questions

View Set

Week 1 Introduction to Psychology

View Set