Java Data Structures and Algorithms
- 98Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Which description correctly distinguishes data from a data structure?
Which description correctly distinguishes data from a data structure?
98 questions
- 1
Which description correctly distinguishes data from a data structure?
- A
Data is information to store, and a structure is how that information is arranged.
- B
Data is the arrangement of information, and a structure is the information itself.
- C
Data is an algorithm’s output, and a structure is the time it takes to produce it.
- D
Data is the computer’s memory, and a structure is the information stored in it.
Correct answer
AData is information to store, and a structure is how that information is arranged.
Explanation
Data is the information to be stored; a data structure is the way that information is arranged in the computer.
- A
- 2
Why can choosing a data structure affect an algorithm’s efficiency?
- A
A data structure affects only how information is displayed to a user.
- B
A data structure affects operation efficiency, time complexity, and memory use.
- C
A data structure determines the programming language an algorithm must use.
- D
A data structure guarantees that every operation takes constant time.
Correct answer
BA data structure affects operation efficiency, time complexity, and memory use.
Explanation
The way data is organized affects the operations that can be performed efficiently, the time complexity of algorithms, and their memory use.
- A
- 3
What is the fundamental distinction between linear and nonlinear data structures?
- A
Linear structures permit only one data type; nonlinear structures permit mixed data types.
- B
Linear structures always use contiguous memory; nonlinear structures always use scattered memory.
- C
Linear structures have fixed size; nonlinear structures must have dynamic size.
- D
Linear structures arrange data sequentially; nonlinear structures allow arrangements such as hierarchies.
Correct answer
DLinear structures arrange data sequentially; nonlinear structures allow arrangements such as hierarchies.
Explanation
Linear structures arrange elements sequentially, whereas nonlinear structures can arrange elements hierarchically or in more complex relationships.
- A
- 4
Which description best characterizes a Java array?
- A
A Java array has a declared size and type, and its elements can be accessed by index.
- B
A Java array stores elements without indexes and allocates them wherever memory is available.
- C
A Java array can grow whenever needed and stores unrelated types by default.
- D
A Java array stores elements as linked nodes and requires sequential access.
Correct answer
AA Java array has a declared size and type, and its elements can be accessed by index.
Explanation
A Java array stores a fixed number of elements of one declared type, and the elements are accessed through indexes.
- A
- 5
How does the content contrast array memory allocation with linked-list allocation?
- A
An array requires contiguous memory, whereas linked-list nodes can occupy separate memory locations.
- B
An array can use scattered memory, whereas a linked list requires one contiguous block.
- C
Both arrays and linked lists require all elements to occupy one contiguous memory block.
- D
Neither arrays nor linked lists depend on how memory is allocated.
Correct answer
AAn array requires contiguous memory, whereas linked-list nodes can occupy separate memory locations.
Explanation
The source contrasts arrays, which require contiguous memory allocation, with linked lists, whose nodes can use separate available memory chunks.
- A
- 6
An integer array begins at address 100, and each integer occupies 4 bytes. Which address calculation locates element index 2?
- A
The address is 100+4, because each index adds one element’s size.
- B
The address is 100+2, because an index counts bytes from the base address.
- C
The address is 100+2(4), because the index is multiplied by the element size.
- D
The address is 100+42, because the index is raised to the element size.
Correct answer
CThe address is 100+2(4), because the index is multiplied by the element size.
Explanation
For a zero-based array of four-byte integers beginning at address 100, element index 2 is at 100+2(4)=108.
- A
- 7
Why does zero-based indexing make the first array element require no offset from the base address?
- A
The index is a byte count, so index 0 identifies the second element.
- B
The index is an offset from the first element, so index 0 adds no bytes to the base address.
- C
The index is a memory address, so it does not depend on the base address.
- D
The index is the element’s ordinal number, so index 1 identifies the first element.
Correct answer
BThe index is an offset from the first element, so index 0 adds no bytes to the base address.
Explanation
In a zero-based array, the first element has index 0, so the address of index i is the base address plus i times the element size.
- A
- 8
What does it mean that an array is homogeneous?
- A
An array can mix primitive types whenever all values are numeric.
- B
An array can mix types only if its size is specified explicitly.
- C
An array’s type changes automatically to match each inserted element.
- D
An array stores elements of its declared type rather than arbitrary mixed types.
Correct answer
DAn array stores elements of its declared type rather than arbitrary mixed types.
Explanation
The content describes arrays as homogeneous: an array declared for one data type stores elements of that type rather than mixing unrelated types.
- A
- 9
How is an individual value selected from a two-dimensional array?
- A
A two-dimensional array uses one index for the row and stores columns in separate linked lists.
- B
A two-dimensional array is a collection of unrelated one-dimensional arrays with no index relationship.
- C
A two-dimensional array uses a row index and a column index to select an element.
- D
A two-dimensional array can be accessed only by traversing every element in sequence.
Correct answer
CA two-dimensional array uses a row index and a column index to select an element.
Explanation
A two-dimensional array can represent rows and columns, and accessing an element requires two indexes, one for each dimension.
- A
- 10
Which statement describes the two array-creation approaches discussed in the content?
- A
An array’s size is always inferred, even when no values are supplied.
- B
An array can be initialized directly only after its elements have been sorted.
- C
An array can be created with an explicit size or initialized directly with values.
- D
An array must always be initialized with a loop before it can be declared.
Correct answer
CAn array can be created with an explicit size or initialized directly with values.
Explanation
The source demonstrates creating an array with an explicit size or initializing it with values directly, in which case Java can infer the size.
- A
- 11
Why is the usual array-loop condition
index < array.lengthrather thanindex <= array.length?- A
The loop should stop before the length, because the last valid index is length minus one.
- B
The loop should start at index one, because index zero stores the array’s name.
- C
The loop should stop before length minus one, because the final element is reserved.
- D
The loop should stop at the length, because the length is also the last valid index.
Correct answer
AThe loop should stop before the length, because the last valid index is length minus one.
Explanation
With an array of size n, valid indexes range from 0 through n−1; a loop condition of index less than the array length avoids accessing index n.
- A
- 12
What determines how many indexes are used to access an element in an array?
- A
The number of indexes used to access an array element corresponds to its dimensions.
- B
Every array uses exactly one index, even when it represents a matrix.
- C
The number of dimensions is determined by the element type, not by indexing.
- D
A two-dimensional array uses one index for each element and one for its type.
Correct answer
AThe number of indexes used to access an array element corresponds to its dimensions.
Explanation
A one-dimensional array uses one index, a two-dimensional array uses two, and adding dimensions requires additional indexes.
- A
- 13
Which limitation follows from an array having a fixed size?
- A
An array automatically expands, but doing so prevents indexed access.
- B
An array has dynamic capacity, but its unused positions cannot be read.
- C
An array has fixed capacity, which can waste space when underused and constrain growth.
- D
An array allocates memory only for occupied positions, so unused capacity is impossible.
Correct answer
CAn array has fixed capacity, which can waste space when underused and constrain growth.
Explanation
An array’s fixed capacity can waste allocated space when few elements are used, and exceeding that capacity requires a different strategy.
- A
- 14
Why can inserting or deleting an element in the middle of an array be costly?
- A
Insertion and deletion are difficult because arrays cannot be accessed by index.
- B
Insertion and deletion are difficult because arrays cannot store repeated values.
- C
Insertion and deletion may require shifting subsequent elements to make or fill a position.
- D
Insertion and deletion are difficult because an array stores only one element at a time.
Correct answer
CInsertion and deletion may require shifting subsequent elements to make or fill a position.
Explanation
Insertion or deletion within an array can require shifting later elements to preserve their positions, making these operations comparatively cumbersome.
- A
- 15
A stack receives elements A, then B, then C. Which element is removed first?
- A
A stack is last in, first out, so the newest element is removed first.
- B
A stack is first in, first out, so the oldest element is removed first.
- C
A stack removes the smallest element before all other elements.
- D
A stack removes elements in the order in which they are stored in memory.
Correct answer
AA stack is last in, first out, so the newest element is removed first.
Explanation
A stack is last in, first out: the most recently pushed element is the first one removed.
- A
- 16
Where do the push and pop operations act on a stack?
- A
Insertion occurs at the front, while removal occurs at the rear.
- B
Both insertion and removal occur at the top of the stack.
- C
Insertion occurs at the bottom, while removal can occur at any position.
- D
Insertion occurs at any position, while removal occurs only at the bottom.
Correct answer
BBoth insertion and removal occur at the top of the stack.
Explanation
Stack insertion and removal are restricted to the top; pushing adds at the top, and popping removes from the top.
- A
- 17
What is the purpose of a stack’s top marker?
- A
A top marker points to the middle element so insertion can occur on either side.
- B
A top marker records the total number of different data types in the stack.
- C
A top marker stores the bottom element so all stack operations scan upward.
- D
A top marker identifies the accessible end used for stack operations.
Correct answer
DA top marker identifies the accessible end used for stack operations.
Explanation
A top marker tracks the current top element, allowing the implementation to add, remove, or inspect the top without traversing the entire stack.
- A
- 18
What time complexity does the content associate with the main stack operations when the top is tracked?
- A
Push and pop are constant time, but checking emptiness and peeking require a full traversal.
- B
Each operation takes time proportional to the number of elements because the stack must be sorted.
- C
Push, pop, checking emptiness, and peeking can each take constant time.
- D
Only peeking is constant time; all other stack operations require sorting.
Correct answer
CPush, pop, checking emptiness, and peeking can each take constant time.
Explanation
Push, pop, checking emptiness, and peeking can each be performed with a constant number of steps when the top is tracked.
- A
- 19
How does
peekdiffer frompop?- A
Peek removes the top element, while pop returns it without changing the stack.
- B
Peek sorts the stack, while pop checks whether it is empty.
- C
Peek inspects the top without removing it, while pop removes the top.
- D
Peek and pop both remove the top element, but only pop returns its value.
Correct answer
CPeek inspects the top without removing it, while pop removes the top.
Explanation
A peek returns or inspects the top element without removing it; pop removes the top element.
- A
- 20
How does a stack support recursive function calls?
- A
Recursive calls are managed by a queue that processes the oldest call first.
- B
Recursive calls are managed by a stack of activation records that are removed as calls return.
- C
Recursive calls avoid auxiliary memory because each call replaces the previous one.
- D
Recursive calls are stored in an array that is sorted after every call.
Correct answer
BRecursive calls are managed by a stack of activation records that are removed as calls return.
Explanation
Recursive calls are commonly managed through a call stack: calls are pushed as execution proceeds and completed calls are popped as they return.
- A
- 21
Why is browser navigation often used as an example of stack behavior?
- A
Browser history can behave like a stack because Back removes the most recent history entry.
- B
Browser history behaves like a tree because Back always opens the page with the most links.
- C
Browser history behaves like an array because Back shifts every page one position.
- D
Browser history behaves like a queue because Back opens the oldest page first.
Correct answer
ABrowser history can behave like a stack because Back removes the most recent history entry.
Explanation
Browser history can behave like a stack: visiting pages adds history entries, and pressing Back returns to the most recently visited prior page.
- A
- 22
Which arrangement describes a standard queue?
- A
A queue inserts at the front and removes at the rear, preserving last in, first out.
- B
A queue follows last in, first out, with insertion and removal both at the front.
- C
A queue follows first in, first out, with insertion at the rear and removal at the front.
- D
A queue removes the highest-priority item regardless of insertion order.
Correct answer
CA queue follows first in, first out, with insertion at the rear and removal at the front.
Explanation
Queues follow first in, first out: insertion takes place at the rear, and removal takes place at the front.
- A
- 23
What do enqueue and dequeue do in a queue?
- A
Enqueue sorts the queue, and dequeue returns its largest element.
- B
Enqueue adds at the front, and dequeue removes from the rear.
- C
Enqueue removes the front element, and dequeue adds at the rear.
- D
Enqueue adds at the rear, and dequeue removes from the front.
Correct answer
DEnqueue adds at the rear, and dequeue removes from the front.
Explanation
Enqueue adds an element to the rear of the queue; dequeue removes the front element.
- A
- 24
What roles do the front and rear markers play in a queue?
- A
Front tracks the queue’s capacity, and rear tracks its data type.
- B
Front and rear both point to the oldest item so the queue can be sorted.
- C
Front marks the newest item, and rear marks the next item to be removed.
- D
Front identifies the removal end, and rear identifies the insertion end.
Correct answer
DFront identifies the removal end, and rear identifies the insertion end.
Explanation
Front and rear markers identify the two ends of a queue: items are removed at the front and added at the rear.
- A
- 25
How does the described array-based queue implementation determine whether the queue is empty?
- A
The queue is empty only when front points to the largest stored value.
- B
The implementation checks the front/rear state to determine whether any elements remain.
- C
The queue is empty whenever the rear points to the final array position.
- D
The queue is empty only when its elements are arranged in descending order.
Correct answer
BThe implementation checks the front/rear state to determine whether any elements remain.
Explanation
With a simple array-based queue, the described implementation treats the queue as empty when its front and rear positions indicate there are no stored elements.
- A
- 26
Which set of applications is consistent with the queue examples in the content?
- A
Queues are used mainly to provide random access to arbitrary elements.
- B
Queues are used mainly to keep the smallest value at the front automatically.
- C
Queues are used mainly to evaluate recursive expressions in reverse order.
- D
Queues can support scheduling, playlists, and interrupt handling in arrival order.
Correct answer
DQueues can support scheduling, playlists, and interrupt handling in arrival order.
Explanation
The content identifies operating-system scheduling, playlists, and interrupt handling as applications of queues, where work can be processed in arrival order.
- A
- 27
How do the insertion and removal restrictions of stacks and queues differ?
- A
A stack removes the oldest element first; a queue removes the newest element first.
- B
A stack adds at the front and removes at the rear; a queue uses only its front.
- C
A stack adds and removes at one end; a queue adds at one end and removes at the other.
- D
A stack and a queue both allow insertion and removal at arbitrary positions.
Correct answer
CA stack adds and removes at one end; a queue adds at one end and removes at the other.
Explanation
Both a stack and a queue restrict where elements are added or removed, but a stack uses one end while a queue uses opposite ends.
- A
- 28
Why can a linked list use memory chunks that are not contiguous?
- A
A linked list can connect nodes in separate memory locations using references.
- B
A linked list needs a contiguous block, while an array can use separated chunks.
- C
A linked list and an array both require elements to occupy contiguous memory.
- D
A linked list uses scattered memory only when its elements have different data types.
Correct answer
AA linked list can connect nodes in separate memory locations using references.
Explanation
A linked list can use separated available memory chunks because its nodes are connected by references rather than requiring one contiguous array block.
- A
- 29
What does it mean to say that a linked list has dynamic size?
- A
A linked list can change size only if its nodes are moved into an array.
- B
A linked list has dynamic size only when its elements are sorted.
- C
A linked list can grow or shrink as nodes are inserted or deleted.
- D
A linked list has a fixed size determined when its first node is created.
Correct answer
CA linked list can grow or shrink as nodes are inserted or deleted.
Explanation
A linked list’s size can grow or shrink as nodes are added or removed, unlike the fixed capacity of a standard array.
- A
- 30
Why is direct random access generally unavailable in a linked list?
- A
A linked list can access any node directly by calculating its memory address from the head.
- B
A linked list generally requires sequential traversal because nodes are reached through links.
- C
A linked list supports direct random access because every node has an array index.
- D
A linked list can access only its final node because earlier nodes have no references.
Correct answer
BA linked list generally requires sequential traversal because nodes are reached through links.
Explanation
A linked list’s nodes contain references to other nodes, so reaching a later node ordinarily requires following links from the head.
- A
- 31
Why must a linked list’s head reference be preserved?
- A
The head points to the last node, so losing it prevents insertion at the rear only.
- B
The head points to the first node, so losing it can make the list inaccessible.
- C
The head stores every node’s value, so losing it deletes the values from memory.
- D
The head stores the list’s capacity, so losing it prevents the list from growing.
Correct answer
BThe head points to the first node, so losing it can make the list inaccessible.
Explanation
The head points to the first node and is needed to begin traversal; losing it can make the remaining list inaccessible.
- A
- 32
What information does a node in a singly linked list hold?
- A
A singly linked-list node contains a data value and a link to the first node.
- B
A singly linked-list node contains data and links to both its previous and next nodes.
- C
A singly linked-list node contains only data, and the nodes are located by array indexes.
- D
A singly linked-list node contains data and a link to the next node.
Correct answer
DA singly linked-list node contains data and a link to the next node.
Explanation
A singly linked-list node contains data and a link to the next node; the final node’s next link is null in a noncircular list.
- A
- 33
What additional capability does a doubly linked list gain from storing previous links?
- A
A doubly linked list stores previous and next references, enabling backward and forward traversal.
- B
A doubly linked list stores two head pointers but no links between nodes.
- C
A doubly linked list stores two data values and can be traversed only forward.
- D
A doubly linked list connects its final node to its first node in every case.
Correct answer
AA doubly linked list stores previous and next references, enabling backward and forward traversal.
Explanation
A doubly linked list stores both previous and next references, which enables traversal in either direction.
- A
- 34
What makes a linked list circular?
- A
Every node links directly to every other node in the list.
- B
The list has no head because every node is treated as the first.
- C
The first node links to null, and the last node has no next reference.
- D
The last node links back to the first node, forming a cycle.
Correct answer
DThe last node links back to the first node, forming a cycle.
Explanation
In a circular linked list, the last node links back to the first node rather than ending with a null next reference.
- A
- 35
Why can insertion and deletion be efficient in a linked list once the relevant location is reached?
- A
Insertion or deletion is fast because the list automatically sorts its nodes.
- B
Insertion or deletion needs no memory allocation or reference updates.
- C
Insertion or deletion is fast because every node has a fixed array index.
- D
Insertion or deletion can often be done by changing links instead of shifting later elements.
Correct answer
DInsertion or deletion can often be done by changing links instead of shifting later elements.
Explanation
Inserting or deleting a linked-list node can often be done by changing a small number of links rather than shifting all subsequent elements.
- A
- 36
Which situation particularly favors using a linked list over an array?
- A
A linked list is useful with fragmented memory or frequent insertions and deletions.
- B
A linked list is most useful when fixed capacity and direct indexing are essential.
- C
A linked list is most useful when all elements must occupy one contiguous block.
- D
A linked list is most useful when frequent random access is required and insertions are rare.
Correct answer
AA linked list is useful with fragmented memory or frequent insertions and deletions.
Explanation
A linked list is useful when memory is fragmented or when frequent insertions and deletions are needed; it does not provide array-style direct indexing.
- A
- 37
What type consistency does the content describe for the elements of a linked list?
- A
A linked list stores only references and cannot store element data.
- B
A linked list can be designed to store nodes containing values of the same declared type.
- C
A linked list automatically converts every value to the type of its head node.
- D
A linked list must alternate data types between adjacent nodes.
Correct answer
BA linked list can be designed to store nodes containing values of the same declared type.
Explanation
The content describes linked-list elements as homogeneous in its examples: nodes in a list store values of the same declared type.
- A
- 38
How does a binary tree differ from a general tree in the number of children per node?
- A
A general tree is linear, while a binary tree must be stored contiguously.
- B
A general tree and a binary tree both require exactly two children per node.
- C
A general tree can have any number of children; a binary tree allows at most two.
- D
A general tree has at most two children per node, while a binary tree has no such limit.
Correct answer
CA general tree can have any number of children; a binary tree allows at most two.
Explanation
A general tree can have any number of children per node, while a binary tree restricts each node to at most two children.
- A
- 39
What property makes a tree a hierarchical data structure?
- A
A tree organizes nodes as a single sequential chain with no branches.
- B
A tree organizes nodes hierarchically through a root and parent-child relationships.
- C
A tree requires every node to connect to every other node.
- D
A tree stores nodes only in a fixed-size, contiguous array.
Correct answer
BA tree organizes nodes hierarchically through a root and parent-child relationships.
Explanation
A tree is hierarchical: it has a root, parent-child relationships, and possibly subtrees at different levels.
- A
- 40
What is a leaf node?
- A
A leaf node is any node shared by two different parents.
- B
A leaf node is a node with no children.
- C
A leaf node is any node that has exactly one child.
- D
A leaf node is the root node with the greatest number of children.
Correct answer
BA leaf node is a node with no children.
Explanation
A leaf node has no children; the content gives examples of leaves as terminal nodes in a tree.
- A
- 41
Which ordering rule defines the binary search tree described in the content?
- A
A binary search tree places values randomly and sorts only during traversal.
- B
A binary search tree stores smaller values on the right and larger values on the left.
- C
A binary search tree places smaller values left and larger values right of a node.
- D
A binary search tree stores all values in sorted order in a single chain.
Correct answer
CA binary search tree places smaller values left and larger values right of a node.
Explanation
A binary search tree places values smaller than a node in its left subtree and greater values in its right subtree, supporting directed searches.
- A
- 42
Which child counts are allowed for an individual node in a binary tree?
- A
A node may have zero, one, or two children, but no more than two.
- B
Every node must have at least one child and may have more than two.
- C
Every node must have exactly two children.
- D
Only the root node is limited to two children.
Correct answer
AA node may have zero, one, or two children, but no more than two.
Explanation
In a binary tree, each node can have zero, one, or two children, but never more than two.
- A
- 43
Which sequence defines inorder traversal?
- A
Inorder visits left subtree, right subtree, then node.
- B
Inorder visits right subtree, node, then left subtree.
- C
Inorder visits left subtree, node, then right subtree.
- D
Inorder visits node, left subtree, then right subtree.
Correct answer
CInorder visits left subtree, node, then right subtree.
Explanation
In inorder traversal, the left subtree is visited first, then the node, then the right subtree.
- A
- 44
Which sequence defines preorder traversal?
- A
Preorder visits node, left subtree, then right subtree.
- B
Preorder visits left subtree, right subtree, then node.
- C
Preorder visits right subtree, node, then left subtree.
- D
Preorder visits left subtree, node, then right subtree.
Correct answer
APreorder visits node, left subtree, then right subtree.
Explanation
Preorder visits the node first, then its left subtree, and then its right subtree.
- A
- 45
Which sequence defines postorder traversal?
- A
Postorder visits right subtree, node, then left subtree.
- B
Postorder visits node, right subtree, then left subtree.
- C
Postorder visits node, left subtree, then right subtree.
- D
Postorder visits left subtree, right subtree, then node.
Correct answer
DPostorder visits left subtree, right subtree, then node.
Explanation
Postorder visits the left subtree and right subtree before visiting the node itself.
- A
- 46
What ordering results from performing inorder traversal on a correctly ordered binary search tree?
- A
Postorder traversal sorts the tree by visiting the root first.
- B
Inorder traversal of a correctly ordered binary search tree yields ascending values.
- C
Inorder traversal always visits a general tree in descending order.
- D
Preorder traversal always returns a binary search tree’s values in ascending order.
Correct answer
BInorder traversal of a correctly ordered binary search tree yields ascending values.
Explanation
For a binary search tree, inorder traversal visits values in ascending order when the tree follows the stated left-smaller/right-greater ordering.
- A
- 47
Which uses for preorder traversal are specifically discussed in the content?
- A
Preorder is used only to traverse a tree from leaves toward its root.
- B
Preorder guarantees ascending output for every binary tree.
- C
Preorder can support copying a tree and counting its nodes or leaves.
- D
Preorder is required to find the minimum value in every general tree.
Correct answer
CPreorder can support copying a tree and counting its nodes or leaves.
Explanation
The content identifies preorder traversal as useful for copying a tree and counting its nodes or leaves; preorder also visits the root before its subtrees.
- A
- 48
How do tree traversals correspond to expression notations in the examples?
- A
Preorder produces infix, inorder produces postfix, and postorder produces prefix.
- B
Preorder produces prefix, inorder produces infix, and postorder produces postfix.
- C
Preorder produces postfix, inorder produces prefix, and postorder produces infix.
- D
Preorder, inorder, and postorder all produce the same expression notation.
Correct answer
BPreorder produces prefix, inorder produces infix, and postorder produces postfix.
Explanation
The content connects preorder to prefix notation, inorder to infix notation, and postorder to postfix notation for expression trees.
- A
- 49
Why can a tree be preferable to a linear data structure for some search tasks?
- A
Trees are useful because they guarantee that no comparisons are needed.
- B
Trees are useful only when data must remain in contiguous memory.
- C
Trees can organize data hierarchically and support efficient searches compared with linear structures.
- D
Trees are useful because every tree operation always takes constant time.
Correct answer
CTrees can organize data hierarchically and support efficient searches compared with linear structures.
Explanation
Trees can support search and other operations efficiently compared with sequential structures, and a binary search tree can eliminate a subtree from consideration based on comparisons.
- A
- 50
Why does deleting a node from a binary search tree require considering how many children it has?
- A
A node with two children is always deleted by deleting both of its children first.
- B
Deletion is equally simple for all nodes because tree links never need adjustment.
- C
Deletion requires different handling depending on whether a node has zero, one, or two children.
- D
A node with no children cannot be deleted without rebuilding the whole tree.
Correct answer
CDeletion requires different handling depending on whether a node has zero, one, or two children.
Explanation
Deleting a node with no children is straightforward; deleting a node with one or two children requires preserving the tree’s structure and ordering.
- A
- 51
Which description best defines an algorithm in the content?
- A
An algorithm is a sequence of machine instructions that must use one specific language.
- B
An algorithm is a step-by-step solution approach that is independent of a particular programming language.
- C
An algorithm is a Java class that stores values in a fixed-size array.
- D
An algorithm is a measure of the amount of memory a program occupies.
Correct answer
BAn algorithm is a step-by-step solution approach that is independent of a particular programming language.
Explanation
An algorithm is a step-by-step, language-independent approach to solving a problem; different algorithms can solve the same problem with different efficiency.
- A
- 52
What do time complexity and space complexity measure, respectively?
- A
Time complexity measures the programming language, while space complexity measures the data type.
- B
Time complexity counts only loops, while space complexity counts only recursive calls.
- C
Time complexity describes operation growth, while space complexity describes memory requirements.
- D
Time complexity measures memory use, while space complexity counts comparisons.
Correct answer
CTime complexity describes operation growth, while space complexity describes memory requirements.
Explanation
Time complexity characterizes how the number of operations grows with input size, while space complexity characterizes the memory required.
- A
- 53
Why is worst-case complexity commonly used when estimating an algorithm’s resource needs?
- A
Worst-case analysis estimates the maximum resources an algorithm may require.
- B
Worst-case analysis measures only how quickly an algorithm succeeds.
- C
Best-case analysis is used because it always represents the most likely execution.
- D
Average-case analysis is used because it is always larger than worst-case analysis.
Correct answer
AWorst-case analysis estimates the maximum resources an algorithm may require.
Explanation
The content emphasizes worst-case analysis because it represents the maximum resources an algorithm may require for an input of the given size.
- A
- 54
What is the time complexity of one loop that processes each of n elements once?
- A
A single loop over n inputs has time complexity O(1).
- B
A single loop over n inputs has time complexity O(n).
- C
A single loop over n inputs has time complexity O(n2).
- D
A single loop over n inputs has time complexity O([n\log n).
Correct answer
BA single loop over n inputs has time complexity O(n).
Explanation
A single loop that performs a constant amount of work per iteration over n inputs takes time proportional to n.
- A
- 55
What is the time complexity of two nested loops that each run n times?
- A
Two fully nested loops over n iterations each have time complexity O(1).
- B
Two fully nested loops over n iterations each have time complexity O(logn).
- C
Two fully nested loops over n iterations each have time complexity O(n2).
- D
Two fully nested loops over n iterations each have time complexity O(n).
Correct answer
CTwo fully nested loops over n iterations each have time complexity O(n2).
Explanation
If an outer loop runs n times and an inner loop also runs n times for each outer iteration, the total work is proportional to n2.
- A
- 56
How is asymptotic time complexity generally determined for sequential code sections?
- A
Sequential sections always have the complexity of the first statement only.
- B
Sequential sections always have complexities multiplied together.
- C
Sequential sections are combined, and the dominant growth term determines the asymptotic complexity.
- D
Sequential sections always have the sum of all terms retained exactly.
Correct answer
CSequential sections are combined, and the dominant growth term determines the asymptotic complexity.
Explanation
For sequential sections, the dominant growth rate determines the overall asymptotic complexity; lower-order terms and constant factors are omitted.
- A
- 57
What is the worst-case time complexity of linear search on an unsorted array of n elements?
- A
Linear search checks every pair of elements, giving O(n2) worst-case time.
- B
Linear search halves the remaining search range, giving O(logn) worst-case time.
- C
Linear search checks elements one by one, giving O(n) worst-case time.
- D
Linear search finds any element in constant time by using its index.
Correct answer
CLinear search checks elements one by one, giving O(n) worst-case time.
Explanation
Linear search checks elements one by one; in the worst case it examines all n elements, giving O(n) time.
- A
- 58
Which best describes the best- and worst-case time complexities of linear search?
- A
Its best and worst cases are both O(logn).
- B
Its best case is O(n) and its worst case is O(1).
- C
Its best and worst cases are both O(n2).
- D
Its best case is O(1) and its worst case is O(n).
Correct answer
DIts best case is O(1) and its worst case is O(n).
Explanation
Linear search may find the target at the first element, which takes constant time; if it is absent or last, it may inspect all n elements.
- A
- 59
Why does binary search have logarithmic time complexity?
- A
Binary search repeatedly halves the search range, giving O(logn) time.
- B
Binary search compares every pair of elements, giving O(n2) time.
- C
Binary search sorts the array after each comparison, giving O(nlogn) time.
- D
Binary search checks each element in sequence, giving O(n) time.
Correct answer
ABinary search repeatedly halves the search range, giving O(logn) time.
Explanation
Binary search uses comparisons to eliminate half of the remaining sorted search range at each step, leading to logarithmic time.
- A
- 60
Why must the data be sorted before applying the binary search method described in the content?
- A
Binary search requires sorted data so that one half can be safely discarded.
- B
Binary search requires mixed data types so comparisons can distinguish both halves.
- C
Binary search works only when the target is guaranteed to be the middle element.
- D
Binary search requires a linked list because arrays do not support midpoint comparisons.
Correct answer
ABinary search requires sorted data so that one half can be safely discarded.
Explanation
Binary search depends on ordering: comparing the target with the midpoint determines which half can be discarded only when the data is sorted.
- A
- 61
How should binary search choose a half after comparing the midpoint with the target?
- A
Regardless of the comparison, search both halves to ensure the target is found.
- B
If the midpoint is less than the target, search the right half; if greater, search the left.
- C
If the midpoint is less than the target, search the left half; if greater, search the right.
- D
If the midpoint differs from the target, restart the search at index zero.
Correct answer
BIf the midpoint is less than the target, search the right half; if greater, search the left.
Explanation
When a binary-search midpoint value is less than the target, the search continues in the right half; when greater, it continues in the left half.
- A
- 62
What is a key space-related distinction between recursive and iterative binary search?
- A
Recursive binary search requires a queue to remember each midpoint.
- B
Recursive binary search searches both halves and therefore always uses O(n) time.
- C
Recursive binary search eliminates all memory use because each call replaces the previous call.
- D
Recursive binary search searches one half per call but uses call-stack space for its calls.
Correct answer
DRecursive binary search searches one half per call but uses call-stack space for its calls.
Explanation
A recursive binary search updates the range and calls itself on one half; recursive calls use call-stack space, unlike an iterative version that can use constant auxiliary space.
- A
- 63
What auxiliary-space complexity does the content associate with linear search?
- A
Linear search uses O(n2) auxiliary space because it checks every pair.
- B
Linear search uses O(logn) auxiliary space because it divides the array.
- C
Linear search uses O(1) auxiliary space because it needs only a fixed amount of extra storage.
- D
Linear search uses O(n) auxiliary space because it copies the entire array.
Correct answer
CLinear search uses O(1) auxiliary space because it needs only a fixed amount of extra storage.
Explanation
The content states that linear search uses no additional structure proportional to the input and has constant auxiliary space.
- A
- 64
Which process describes merge sort?
- A
Merge sort divides the data into subproblems, sorts them, and merges the results.
- B
Merge sort partitions around a pivot and places smaller values on one side.
- C
Merge sort scans once and swaps every adjacent out-of-order pair.
- D
Merge sort repeatedly selects the smallest element and moves it to the front.
Correct answer
AMerge sort divides the data into subproblems, sorts them, and merges the results.
Explanation
Merge sort recursively divides the array into subproblems, sorts them, and merges the sorted parts.
- A
- 65
Why does merge sort have O(nlogn) time complexity?
- A
Merge sort has O(n2) time because it compares every pair of elements.
- B
Merge sort has O(nlogn) time because it has logarithmic division levels and linear merging work per level.
- C
Merge sort has O(n) time because each element is processed only once overall.
- D
Merge sort has O(logn) time because each level uses one comparison.
Correct answer
BMerge sort has O(nlogn) time because it has logarithmic division levels and linear merging work per level.
Explanation
Merge sort repeatedly divides an n-element problem into halves, producing about logn levels, and does O(n) work per level when merging.
- A
- 66
What auxiliary-space complexity is associated with the merge-sort implementation described?
- A
Merge sort uses O(logn) auxiliary space because it stores only recursion calls.
- B
Merge sort uses O(n) auxiliary space because it stores data in temporary arrays.
- C
Merge sort uses O(n2) auxiliary space because it stores every pair of elements.
- D
Merge sort uses O(1) auxiliary space because it sorts only by swapping in place.
Correct answer
BMerge sort uses O(n) auxiliary space because it stores data in temporary arrays.
Explanation
Merge sort uses auxiliary arrays to hold portions being merged, so its auxiliary space grows proportionally to the number of elements.
- A
- 67
What does it mean for a sorting algorithm to be stable?
- A
A stable sort uses no auxiliary memory under any implementation.
- B
A stable sort preserves the relative order of equal-valued elements.
- C
A stable sort guarantees that every element remains at its original index.
- D
A stable sort always produces descending order.
Correct answer
BA stable sort preserves the relative order of equal-valued elements.
Explanation
A stable sort preserves the relative order of equal-valued elements; the content describes merge sort as stable.
- A
- 68
Which comparison between merge sort and quicksort matches the content?
- A
Merge sort is in-place and unstable, while quicksort is stable and uses auxiliary arrays.
- B
Merge sort and quicksort both require O(n) auxiliary space and preserve all equal-item order.
- C
Both merge sort and quicksort are necessarily stable and in-place.
- D
Merge sort is stable but uses auxiliary space; quicksort is in-place but can be unstable.
Correct answer
DMerge sort is stable but uses auxiliary space; quicksort is in-place but can be unstable.
Explanation
The content contrasts merge sort’s stable behavior and auxiliary storage with quicksort’s in-place behavior and possible instability.
- A
- 69
What is the central operation in quicksort?
- A
Quicksort repeatedly merges two already sorted arrays into a new array.
- B
Quicksort finds the minimum repeatedly and moves it to the beginning.
- C
Quicksort selects a pivot, partitions values around it, and recursively sorts the partitions.
- D
Quicksort inserts each element into its final position by shifting all earlier values.
Correct answer
CQuicksort selects a pivot, partitions values around it, and recursively sorts the partitions.
Explanation
Quicksort chooses a pivot and partitions the array so values on one side are smaller and values on the other side are larger, then sorts the partitions recursively.
- A
- 70
Which worst-case time complexities distinguish quicksort and merge sort in the content?
- A
Quicksort’s worst case is O(logn), while merge sort’s worst case is O(n).
- B
Quicksort’s worst case is O(1), while merge sort’s worst case is O(n2).
- C
Quicksort’s worst case is O(nlogn), while merge sort’s worst case is O(n2).
- D
Quicksort’s worst case is O(n2), while merge sort’s worst case is O(nlogn).
Correct answer
DQuicksort’s worst case is O(n2), while merge sort’s worst case is O(nlogn).
Explanation
The content describes quicksort’s worst case as O(n2), which can occur when partitioning is very unbalanced; merge sort remains O(nlogn).
- A
- 71
Why is quicksort described as an in-place algorithm in the content?
- A
Quicksort is in-place because it stores all values in a separate queue.
- B
Quicksort is in-place because it always creates a complete copy of the input.
- C
Quicksort is described as in-place because it rearranges the original array without merge sort’s auxiliary arrays.
- D
Quicksort is in-place because it never changes the input array.
Correct answer
CQuicksort is described as in-place because it rearranges the original array without merge sort’s auxiliary arrays.
Explanation
Quicksort is generally in-place in the described implementation: it rearranges elements within the original array rather than requiring merge sort’s auxiliary arrays.
- A
- 72
What defines recursion, and what prevents recursive calls from continuing indefinitely?
- A
Recursion occurs when a function calls itself, with a base case stopping the calls.
- B
Recursion occurs when a function stores its result in an array.
- C
Recursion occurs when a function calls a different function once.
- D
Recursion occurs when a loop repeats without changing its counter.
Correct answer
ARecursion occurs when a function calls itself, with a base case stopping the calls.
Explanation
Recursion occurs when a function calls itself; a base case is needed to stop further recursive calls.
- A
- 73
What happens to activation records during recursive calls?
- A
A recursive call avoids memory use because its execution is always iterative.
- B
A recursive call creates a stack activation record that remains until the call returns.
- C
A recursive call overwrites the previous activation record, so no extra space is used.
- D
A recursive call stores its activation record in the queue’s rear position.
Correct answer
BA recursive call creates a stack activation record that remains until the call returns.
Explanation
A recursive call creates an activation record on the call stack; records are removed as functions return, which uses auxiliary memory.
- A
- 74
What is the main idea behind backtracking?
- A
Backtracking permanently commits to the first choice and never revisits it.
- B
Backtracking explores a path and returns to an earlier choice point to try alternatives.
- C
Backtracking follows only the shortest path and discards all other paths immediately.
- D
Backtracking sorts all possible choices before exploring any of them.
Correct answer
BBacktracking explores a path and returns to an earlier choice point to try alternatives.
Explanation
Backtracking explores choices, returns to a previous decision point when a path fails or is exhausted, and tries another path.
- A
- 75
What limitation can arise from making locally optimal choices in a greedy algorithm?
- A
A greedy algorithm always evaluates every complete solution before choosing one.
- B
A greedy algorithm randomly chooses among all possible solutions.
- C
A greedy algorithm uses previous subproblem solutions to guarantee a global optimum.
- D
A greedy algorithm makes locally best choices, which may not produce the globally best solution.
Correct answer
DA greedy algorithm makes locally best choices, which may not produce the globally best solution.
Explanation
A greedy algorithm chooses what appears best at each local step; these local choices may produce a feasible solution without guaranteeing the global optimum.
- A
- 76
What does the Bangalore-to-Delhi example demonstrate about greedy decisions?
- A
The greedy route compares all complete paths before selecting the shortest one.
- B
A locally shorter leg can lead to a longer total route than another path.
- C
The greedy route is globally optimal because every locally shortest leg guarantees the shortest total route.
- D
The greedy route uses previously computed subproblem solutions to revise every earlier choice.
Correct answer
BA locally shorter leg can lead to a longer total route than another path.
Explanation
The route example chooses the locally shorter next leg from Bangalore to Mumbai, even though the complete route through Hyderabad is shorter overall.
- A
- 77
Which collection contains problems or algorithms that the content associates with greedy methods?
- A
Examples include stack push, queue dequeue, linked-list traversal, and tree inorder only.
- B
Examples include linear search, bubble sort, memory allocation, and function calls only.
- C
Examples include the traveling salesperson problem, spanning-tree methods, Dijkstra’s algorithm, vertex cover, and knapsack.
- D
Examples include merge sort, binary search, recursion, and array indexing only.
Correct answer
CExamples include the traveling salesperson problem, spanning-tree methods, Dijkstra’s algorithm, vertex cover, and knapsack.
Explanation
The content lists the traveling salesperson problem, Prim’s and Kruskal’s spanning-tree methods, Dijkstra’s algorithm, vertex cover, and knapsack as examples connected with greedy approaches.
- A
- 78
What is a key difference between greedy methods and dynamic programming as presented?
- A
Greedy methods always guarantee the global optimum; dynamic programming guarantees only feasibility.
- B
Greedy methods make local choices; dynamic programming considers stored solutions to subproblems.
- C
Greedy and dynamic programming both ignore previous results and always have the same running time.
- D
Greedy methods store every subproblem result; dynamic programming makes one local choice only.
Correct answer
BGreedy methods make local choices; dynamic programming considers stored solutions to subproblems.
Explanation
The content contrasts greedy methods, which make local choices without relying on earlier subproblem results, with dynamic programming, which reuses prior subproblem solutions.
- A
- 79
How does dynamic programming use earlier subproblem results?
- A
Dynamic programming reuses previous subproblem results when solving later stages.
- B
Dynamic programming avoids storing any earlier solution.
- C
Dynamic programming is necessarily faster because it ignores prior choices.
- D
Dynamic programming chooses only the currently most attractive option.
Correct answer
ADynamic programming reuses previous subproblem results when solving later stages.
Explanation
Dynamic programming considers previously solved subproblems when constructing later solutions, whereas the described greedy approach focuses on the current local choice.
- A
- 80
What distinguishes fractional knapsack from zero-one knapsack?
- A
Fractional knapsack requires whole items, while zero-one knapsack permits any fraction.
- B
Zero-one knapsack permits splitting items, while fractional knapsack does not.
- C
Both versions require every item to be selected completely.
- D
Fractional knapsack permits fractions of items; zero-one knapsack selects or rejects whole items.
Correct answer
DFractional knapsack permits fractions of items; zero-one knapsack selects or rejects whole items.
Explanation
The fractional knapsack problem permits selecting a fraction of an item, while the zero-one version requires choosing an item entirely or not at all.
- A
- 81
What ratio guides the greedy selection in the fractional knapsack algorithm?
- A
It ranks items only by total weight and selects the heaviest items first.
- B
It ranks items by weight divided by profit and selects the largest ratio last.
- C
It ranks items only by total profit and ignores their weights.
- D
It ranks items by profit per unit weight and considers larger ratios first.
Correct answer
DIt ranks items by profit per unit weight and considers larger ratios first.
Explanation
The fractional-knapsack greedy method ranks items by profit divided by weight and considers higher ratios first, subject to the capacity limit.
- A
- 82
What should the fractional-knapsack algorithm do when only part of the next item fits?
- A
The algorithm takes the fraction of the item that fits in the remaining capacity.
- B
The algorithm exceeds the capacity if the item’s profit is sufficiently high.
- C
The algorithm discards every previously selected item and restarts with the next one.
- D
The algorithm rounds the item’s weight down and treats it as fully selected.
Correct answer
AThe algorithm takes the fraction of the item that fits in the remaining capacity.
Explanation
When the next whole item would exceed the remaining capacity in fractional knapsack, the algorithm can take only the fraction that fits.
- A
- 83
What is the central objective in the knapsack problem described?
- A
It selects the most profitable items even if their total weight exceeds capacity.
- B
It selects the lightest items regardless of their profits or total capacity.
- C
It selects items to maximize profit without exceeding the knapsack’s capacity.
- D
It minimizes the number of items without regard to their weights or profits.
Correct answer
CIt selects items to maximize profit without exceeding the knapsack’s capacity.
Explanation
The knapsack objective balances the limited capacity against the goal of maximizing profit; choosing by weight or profit alone may miss the best feasible selection.
- A
- 84
What graph task does the content associate with Dijkstra’s algorithm?
- A
Dijkstra’s algorithm sorts graph vertices into ascending order.
- B
Dijkstra’s algorithm constructs a binary search tree from sorted input.
- C
Dijkstra’s algorithm finds a minimum spanning tree by selecting every edge.
- D
Dijkstra’s algorithm finds shortest paths from one source to other vertices.
Correct answer
DDijkstra’s algorithm finds shortest paths from one source to other vertices.
Explanation
The content lists Dijkstra’s algorithm as a method for finding shortest paths from a single source to other vertices and connects it with greedy reasoning.
- A
- 85
What are the basic components of a graph?
- A
A graph consists of arrays and indexes, with edges representing array positions.
- B
A graph consists of roots and leaves, with edges representing memory addresses.
- C
A graph consists of queues and stacks, with edges representing operation order.
- D
A graph consists of vertices and edges, with edges connecting vertices.
Correct answer
DA graph consists of vertices and edges, with edges connecting vertices.
Explanation
A graph consists of vertices and edges; edges represent relationships or connections between vertices.
- A
- 86
What distinguishes a directed graph from an undirected graph?
- A
A directed graph requires every edge to connect both ways.
- B
A directed graph assigns a direction to edges, so reverse connections need not exist.
- C
A directed graph permits edges only between vertices at the same level.
- D
A directed graph has no edges between its vertices.
Correct answer
BA directed graph assigns a direction to edges, so reverse connections need not exist.
Explanation
In a directed graph, an edge has a direction, so a connection from one vertex to another does not automatically imply a connection in the reverse direction.
- A
- 87
How is an edge interpreted in an undirected graph?
- A
An undirected graph contains no connections between vertices.
- B
An undirected edge connects a vertex only to itself.
- C
An undirected edge has no specified direction and represents a two-way connection.
- D
An undirected edge points from exactly one vertex to another.
Correct answer
CAn undirected edge has no specified direction and represents a two-way connection.
Explanation
An undirected edge has no direction, so it represents a connection that can be followed either way.
- A
- 88
When is a graph disconnected?
- A
A graph is disconnected whenever any vertex has more than two neighbors.
- B
A graph is disconnected when some vertices or components have no connecting path.
- C
A graph is disconnected whenever it has more edges than vertices.
- D
A graph is disconnected whenever it contains a cycle.
Correct answer
BA graph is disconnected when some vertices or components have no connecting path.
Explanation
A graph is disconnected if some vertices are isolated from the others or if its vertices split into groups with no connecting path between them.
- A
- 89
What information does an adjacency matrix represent?
- A
An adjacency matrix represents a graph using one Boolean value for the entire graph.
- B
An adjacency matrix uses rows and columns to represent connections between vertex pairs.
- C
An adjacency matrix stores only the names of vertices, not their connections.
- D
An adjacency matrix stores a separate linked list for every possible path.
Correct answer
BAn adjacency matrix uses rows and columns to represent connections between vertex pairs.
Explanation
An adjacency matrix records whether each pair of vertices is connected; an entry can represent an edge between the corresponding row and column vertices.
- A
- 90
What does an adjacency list contain for each graph vertex?
- A
An adjacency list stores only each vertex’s number of outgoing edges.
- B
An adjacency list records the neighbors directly connected to each vertex.
- C
An adjacency list stores each graph vertex as a separate matrix row.
- D
An adjacency list stores all possible vertex pairs in a sorted sequence.
Correct answer
BAn adjacency list records the neighbors directly connected to each vertex.
Explanation
An adjacency list stores, for each vertex, a list of the vertices directly connected to it.
- A
- 91
Which approach and supporting data structure characterize breadth-first search?
- A
Breadth-first search explores level by level, typically using a queue.
- B
Breadth-first search follows one path to its deepest point, typically using a stack.
- C
Breadth-first search visits vertices in sorted numerical order.
- D
Breadth-first search repeatedly chooses the lowest-weight edge, without a queue.
Correct answer
ABreadth-first search explores level by level, typically using a queue.
Explanation
Breadth-first search visits vertices level by level and uses a queue to process vertices in first-in, first-out order.
- A
- 92
Why does a breadth-first search implementation keep track of visited vertices?
- A
A vertex is marked visited only if it has no adjacent vertices.
- B
A vertex is marked visited when it is first placed in the adjacency matrix.
- C
A vertex is marked visited only after every graph edge has been removed.
- D
A visited marker prevents the search from repeatedly processing a vertex.
Correct answer
DA visited marker prevents the search from repeatedly processing a vertex.
Explanation
In breadth-first search, a vertex is marked visited when it is processed or discovered so it is not repeatedly enqueued and traversed.
- A
- 93
Which description matches depth-first search?
- A
Depth-first search repeatedly finds the smallest value and uses a priority queue.
- B
Depth-first search visits all immediate neighbors before going deeper and uses a queue.
- C
Depth-first search explores deeply before backtracking and can use a stack.
- D
Depth-first search visits vertices by sorted label and uses an array only.
Correct answer
CDepth-first search explores deeply before backtracking and can use a stack.
Explanation
Depth-first search follows a path as deeply as possible before backtracking; a stack supports this last-in, first-out exploration.
- A
- 94
Which comparison between BFS and DFS is correct?
- A
BFS and DFS both require sorted vertices and do not use visited tracking.
- B
BFS uses a stack and depth-first order, while DFS uses a queue and breadth-first order.
- C
BFS and DFS differ only in whether the graph has directed edges.
- D
BFS uses a queue for level order, while DFS uses a stack for depth-first exploration.
Correct answer
DBFS uses a queue for level order, while DFS uses a stack for depth-first exploration.
Explanation
BFS and DFS need visited tracking to avoid repeatedly visiting vertices in cyclic or connected graphs; they differ in traversal order and commonly use a queue and stack, respectively.
- A
- 95
Which property defines a spanning tree of a connected graph with V vertices?
- A
A spanning tree contains every edge of the graph and may include cycles.
- B
A spanning tree connects all vertices without cycles and has V−1 edges.
- C
A spanning tree contains one vertex and no edges, regardless of the graph.
- D
A spanning tree connects only leaf vertices and has V+1 edges.
Correct answer
BA spanning tree connects all vertices without cycles and has V−1 edges.
Explanation
A spanning tree connects every vertex of a connected graph without cycles and has one fewer edge than vertices.
- A
- 96
What is the goal of a minimum spanning tree?
- A
A minimum spanning tree connects only the lowest-degree vertices.
- B
A minimum spanning tree is the tree with the greatest number of edges.
- C
A minimum spanning tree is a shortest path from one chosen source.
- D
A minimum spanning tree connects all vertices with minimum total edge weight.
Correct answer
DA minimum spanning tree connects all vertices with minimum total edge weight.
Explanation
A minimum spanning tree is a spanning tree whose total edge weight is as small as possible; Prim’s and Kruskal’s algorithms are methods for finding one.
- A
- 97
How does Prim’s algorithm build a minimum spanning tree?
- A
Prim’s algorithm grows from a starting vertex by adding a light edge to a new vertex.
- B
Prim’s algorithm repeatedly selects the globally heaviest remaining edge.
- C
Prim’s algorithm sorts all vertices and connects them in label order.
- D
Prim’s algorithm chooses a shortest path independently from every vertex.
Correct answer
APrim’s algorithm grows from a starting vertex by adding a light edge to a new vertex.
Explanation
Prim’s algorithm grows a tree from a starting vertex by repeatedly selecting a minimum-weight edge that extends the included vertices without creating a cycle.
- A
- 98
What is the key edge-selection rule in Kruskal’s algorithm?
- A
Kruskal’s algorithm begins at one vertex and always selects its lightest outgoing edge.
- B
Kruskal’s algorithm adds edges in decreasing weight order until every cycle is closed.
- C
Kruskal’s algorithm selects edges randomly and removes cycles afterward.
- D
Kruskal’s algorithm adds edges from low to high weight while avoiding cycles.
Correct answer
DKruskal’s algorithm adds edges from low to high weight while avoiding cycles.
Explanation
Kruskal’s algorithm considers edges in increasing weight order and adds an edge only when doing so does not create a cycle.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.