1. Home
  2. Explore
  3. Computer Science
  4. Java Data Structures and Algorithms

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Java Data Structures and Algorithms

  • 98Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Foundations and Arrays

Which description correctly distinguishes data from a data structure?

98 questions

  1. 1

    Which description correctly distinguishes data from a data structure?

    1. A

      Data is information to store, and a structure is how that information is arranged.

    2. B

      Data is the arrangement of information, and a structure is the information itself.

    3. C

      Data is an algorithm’s output, and a structure is the time it takes to produce it.

    4. D

      Data is the computer’s memory, and a structure is the information stored in it.

    Correct answer
    A

    Data 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.

  2. 2

    Why can choosing a data structure affect an algorithm’s efficiency?

    1. A

      A data structure affects only how information is displayed to a user.

    2. B

      A data structure affects operation efficiency, time complexity, and memory use.

    3. C

      A data structure determines the programming language an algorithm must use.

    4. D

      A data structure guarantees that every operation takes constant time.

    Correct answer
    B

    A 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.

  3. 3

    What is the fundamental distinction between linear and nonlinear data structures?

    1. A

      Linear structures permit only one data type; nonlinear structures permit mixed data types.

    2. B

      Linear structures always use contiguous memory; nonlinear structures always use scattered memory.

    3. C

      Linear structures have fixed size; nonlinear structures must have dynamic size.

    4. D

      Linear structures arrange data sequentially; nonlinear structures allow arrangements such as hierarchies.

    Correct answer
    D

    Linear 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.

  4. 4

    Which description best characterizes a Java array?

    1. A

      A Java array has a declared size and type, and its elements can be accessed by index.

    2. B

      A Java array stores elements without indexes and allocates them wherever memory is available.

    3. C

      A Java array can grow whenever needed and stores unrelated types by default.

    4. D

      A Java array stores elements as linked nodes and requires sequential access.

    Correct answer
    A

    A 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.

  5. 5

    How does the content contrast array memory allocation with linked-list allocation?

    1. A

      An array requires contiguous memory, whereas linked-list nodes can occupy separate memory locations.

    2. B

      An array can use scattered memory, whereas a linked list requires one contiguous block.

    3. C

      Both arrays and linked lists require all elements to occupy one contiguous memory block.

    4. D

      Neither arrays nor linked lists depend on how memory is allocated.

    Correct answer
    A

    An 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.

  6. 6

    An integer array begins at address 100100100, and each integer occupies 444 bytes. Which address calculation locates element index 222?

    1. A

      The address is 100+4100+4100+4, because each index adds one element’s size.

    2. B

      The address is 100+2100+2100+2, because an index counts bytes from the base address.

    3. C

      The address is 100+2(4)100+2(4)100+2(4), because the index is multiplied by the element size.

    4. D

      The address is 100+42100+4^2100+42, because the index is raised to the element size.

    Correct answer
    C

    The address is 100+2(4)100+2(4)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 100100100, element index 222 is at 100+2(4)=108100+2(4)=108100+2(4)=108.

  7. 7

    Why does zero-based indexing make the first array element require no offset from the base address?

    1. A

      The index is a byte count, so index 000 identifies the second element.

    2. B

      The index is an offset from the first element, so index 000 adds no bytes to the base address.

    3. C

      The index is a memory address, so it does not depend on the base address.

    4. D

      The index is the element’s ordinal number, so index 111 identifies the first element.

    Correct answer
    B

    The index is an offset from the first element, so index 000 adds no bytes to the base address.

    Explanation

    In a zero-based array, the first element has index 000, so the address of index iii is the base address plus iii times the element size.

  8. 8

    What does it mean that an array is homogeneous?

    1. A

      An array can mix primitive types whenever all values are numeric.

    2. B

      An array can mix types only if its size is specified explicitly.

    3. C

      An array’s type changes automatically to match each inserted element.

    4. D

      An array stores elements of its declared type rather than arbitrary mixed types.

    Correct answer
    D

    An 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.

  9. 9

    How is an individual value selected from a two-dimensional array?

    1. A

      A two-dimensional array uses one index for the row and stores columns in separate linked lists.

    2. B

      A two-dimensional array is a collection of unrelated one-dimensional arrays with no index relationship.

    3. C

      A two-dimensional array uses a row index and a column index to select an element.

    4. D

      A two-dimensional array can be accessed only by traversing every element in sequence.

    Correct answer
    C

    A 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.

  10. 10

    Which statement describes the two array-creation approaches discussed in the content?

    1. A

      An array’s size is always inferred, even when no values are supplied.

    2. B

      An array can be initialized directly only after its elements have been sorted.

    3. C

      An array can be created with an explicit size or initialized directly with values.

    4. D

      An array must always be initialized with a loop before it can be declared.

    Correct answer
    C

    An 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.

  11. 11

    Why is the usual array-loop condition index < array.length rather than index <= array.length?

    1. A

      The loop should stop before the length, because the last valid index is length minus one.

    2. B

      The loop should start at index one, because index zero stores the array’s name.

    3. C

      The loop should stop before length minus one, because the final element is reserved.

    4. D

      The loop should stop at the length, because the length is also the last valid index.

    Correct answer
    A

    The loop should stop before the length, because the last valid index is length minus one.

    Explanation

    With an array of size nnn, valid indexes range from 000 through n−1n-1n−1; a loop condition of index less than the array length avoids accessing index nnn.

  12. 12

    What determines how many indexes are used to access an element in an array?

    1. A

      The number of indexes used to access an array element corresponds to its dimensions.

    2. B

      Every array uses exactly one index, even when it represents a matrix.

    3. C

      The number of dimensions is determined by the element type, not by indexing.

    4. D

      A two-dimensional array uses one index for each element and one for its type.

    Correct answer
    A

    The 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.

  13. 13

    Which limitation follows from an array having a fixed size?

    1. A

      An array automatically expands, but doing so prevents indexed access.

    2. B

      An array has dynamic capacity, but its unused positions cannot be read.

    3. C

      An array has fixed capacity, which can waste space when underused and constrain growth.

    4. D

      An array allocates memory only for occupied positions, so unused capacity is impossible.

    Correct answer
    C

    An 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.

  14. 14

    Why can inserting or deleting an element in the middle of an array be costly?

    1. A

      Insertion and deletion are difficult because arrays cannot be accessed by index.

    2. B

      Insertion and deletion are difficult because arrays cannot store repeated values.

    3. C

      Insertion and deletion may require shifting subsequent elements to make or fill a position.

    4. D

      Insertion and deletion are difficult because an array stores only one element at a time.

    Correct answer
    C

    Insertion 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.

  15. 15

    A stack receives elements AAA, then BBB, then CCC. Which element is removed first?

    1. A

      A stack is last in, first out, so the newest element is removed first.

    2. B

      A stack is first in, first out, so the oldest element is removed first.

    3. C

      A stack removes the smallest element before all other elements.

    4. D

      A stack removes elements in the order in which they are stored in memory.

    Correct answer
    A

    A 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.

  16. 16

    Where do the push and pop operations act on a stack?

    1. A

      Insertion occurs at the front, while removal occurs at the rear.

    2. B

      Both insertion and removal occur at the top of the stack.

    3. C

      Insertion occurs at the bottom, while removal can occur at any position.

    4. D

      Insertion occurs at any position, while removal occurs only at the bottom.

    Correct answer
    B

    Both 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.

  17. 17

    What is the purpose of a stack’s top marker?

    1. A

      A top marker points to the middle element so insertion can occur on either side.

    2. B

      A top marker records the total number of different data types in the stack.

    3. C

      A top marker stores the bottom element so all stack operations scan upward.

    4. D

      A top marker identifies the accessible end used for stack operations.

    Correct answer
    D

    A 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.

  18. 18

    What time complexity does the content associate with the main stack operations when the top is tracked?

    1. A

      Push and pop are constant time, but checking emptiness and peeking require a full traversal.

    2. B

      Each operation takes time proportional to the number of elements because the stack must be sorted.

    3. C

      Push, pop, checking emptiness, and peeking can each take constant time.

    4. D

      Only peeking is constant time; all other stack operations require sorting.

    Correct answer
    C

    Push, 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.

  19. 19

    How does peek differ from pop?

    1. A

      Peek removes the top element, while pop returns it without changing the stack.

    2. B

      Peek sorts the stack, while pop checks whether it is empty.

    3. C

      Peek inspects the top without removing it, while pop removes the top.

    4. D

      Peek and pop both remove the top element, but only pop returns its value.

    Correct answer
    C

    Peek 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.

  20. 20

    How does a stack support recursive function calls?

    1. A

      Recursive calls are managed by a queue that processes the oldest call first.

    2. B

      Recursive calls are managed by a stack of activation records that are removed as calls return.

    3. C

      Recursive calls avoid auxiliary memory because each call replaces the previous one.

    4. D

      Recursive calls are stored in an array that is sorted after every call.

    Correct answer
    B

    Recursive 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.

  21. 21

    Why is browser navigation often used as an example of stack behavior?

    1. A

      Browser history can behave like a stack because Back removes the most recent history entry.

    2. B

      Browser history behaves like a tree because Back always opens the page with the most links.

    3. C

      Browser history behaves like an array because Back shifts every page one position.

    4. D

      Browser history behaves like a queue because Back opens the oldest page first.

    Correct answer
    A

    Browser 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.

  22. 22

    Which arrangement describes a standard queue?

    1. A

      A queue inserts at the front and removes at the rear, preserving last in, first out.

    2. B

      A queue follows last in, first out, with insertion and removal both at the front.

    3. C

      A queue follows first in, first out, with insertion at the rear and removal at the front.

    4. D

      A queue removes the highest-priority item regardless of insertion order.

    Correct answer
    C

    A 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.

  23. 23

    What do enqueue and dequeue do in a queue?

    1. A

      Enqueue sorts the queue, and dequeue returns its largest element.

    2. B

      Enqueue adds at the front, and dequeue removes from the rear.

    3. C

      Enqueue removes the front element, and dequeue adds at the rear.

    4. D

      Enqueue adds at the rear, and dequeue removes from the front.

    Correct answer
    D

    Enqueue 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.

  24. 24

    What roles do the front and rear markers play in a queue?

    1. A

      Front tracks the queue’s capacity, and rear tracks its data type.

    2. B

      Front and rear both point to the oldest item so the queue can be sorted.

    3. C

      Front marks the newest item, and rear marks the next item to be removed.

    4. D

      Front identifies the removal end, and rear identifies the insertion end.

    Correct answer
    D

    Front 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.

  25. 25

    How does the described array-based queue implementation determine whether the queue is empty?

    1. A

      The queue is empty only when front points to the largest stored value.

    2. B

      The implementation checks the front/rear state to determine whether any elements remain.

    3. C

      The queue is empty whenever the rear points to the final array position.

    4. D

      The queue is empty only when its elements are arranged in descending order.

    Correct answer
    B

    The 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.

  26. 26

    Which set of applications is consistent with the queue examples in the content?

    1. A

      Queues are used mainly to provide random access to arbitrary elements.

    2. B

      Queues are used mainly to keep the smallest value at the front automatically.

    3. C

      Queues are used mainly to evaluate recursive expressions in reverse order.

    4. D

      Queues can support scheduling, playlists, and interrupt handling in arrival order.

    Correct answer
    D

    Queues 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.

  27. 27

    How do the insertion and removal restrictions of stacks and queues differ?

    1. A

      A stack removes the oldest element first; a queue removes the newest element first.

    2. B

      A stack adds at the front and removes at the rear; a queue uses only its front.

    3. C

      A stack adds and removes at one end; a queue adds at one end and removes at the other.

    4. D

      A stack and a queue both allow insertion and removal at arbitrary positions.

    Correct answer
    C

    A 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.

  28. 28

    Why can a linked list use memory chunks that are not contiguous?

    1. A

      A linked list can connect nodes in separate memory locations using references.

    2. B

      A linked list needs a contiguous block, while an array can use separated chunks.

    3. C

      A linked list and an array both require elements to occupy contiguous memory.

    4. D

      A linked list uses scattered memory only when its elements have different data types.

    Correct answer
    A

    A 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.

  29. 29

    What does it mean to say that a linked list has dynamic size?

    1. A

      A linked list can change size only if its nodes are moved into an array.

    2. B

      A linked list has dynamic size only when its elements are sorted.

    3. C

      A linked list can grow or shrink as nodes are inserted or deleted.

    4. D

      A linked list has a fixed size determined when its first node is created.

    Correct answer
    C

    A 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.

  30. 30

    Why is direct random access generally unavailable in a linked list?

    1. A

      A linked list can access any node directly by calculating its memory address from the head.

    2. B

      A linked list generally requires sequential traversal because nodes are reached through links.

    3. C

      A linked list supports direct random access because every node has an array index.

    4. D

      A linked list can access only its final node because earlier nodes have no references.

    Correct answer
    B

    A 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.

  31. 31

    Why must a linked list’s head reference be preserved?

    1. A

      The head points to the last node, so losing it prevents insertion at the rear only.

    2. B

      The head points to the first node, so losing it can make the list inaccessible.

    3. C

      The head stores every node’s value, so losing it deletes the values from memory.

    4. D

      The head stores the list’s capacity, so losing it prevents the list from growing.

    Correct answer
    B

    The 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.

  32. 32

    What information does a node in a singly linked list hold?

    1. A

      A singly linked-list node contains a data value and a link to the first node.

    2. B

      A singly linked-list node contains data and links to both its previous and next nodes.

    3. C

      A singly linked-list node contains only data, and the nodes are located by array indexes.

    4. D

      A singly linked-list node contains data and a link to the next node.

    Correct answer
    D

    A 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.

  33. 33

    What additional capability does a doubly linked list gain from storing previous links?

    1. A

      A doubly linked list stores previous and next references, enabling backward and forward traversal.

    2. B

      A doubly linked list stores two head pointers but no links between nodes.

    3. C

      A doubly linked list stores two data values and can be traversed only forward.

    4. D

      A doubly linked list connects its final node to its first node in every case.

    Correct answer
    A

    A 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.

  34. 34

    What makes a linked list circular?

    1. A

      Every node links directly to every other node in the list.

    2. B

      The list has no head because every node is treated as the first.

    3. C

      The first node links to null, and the last node has no next reference.

    4. D

      The last node links back to the first node, forming a cycle.

    Correct answer
    D

    The 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.

  35. 35

    Why can insertion and deletion be efficient in a linked list once the relevant location is reached?

    1. A

      Insertion or deletion is fast because the list automatically sorts its nodes.

    2. B

      Insertion or deletion needs no memory allocation or reference updates.

    3. C

      Insertion or deletion is fast because every node has a fixed array index.

    4. D

      Insertion or deletion can often be done by changing links instead of shifting later elements.

    Correct answer
    D

    Insertion 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.

  36. 36

    Which situation particularly favors using a linked list over an array?

    1. A

      A linked list is useful with fragmented memory or frequent insertions and deletions.

    2. B

      A linked list is most useful when fixed capacity and direct indexing are essential.

    3. C

      A linked list is most useful when all elements must occupy one contiguous block.

    4. D

      A linked list is most useful when frequent random access is required and insertions are rare.

    Correct answer
    A

    A 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.

  37. 37

    What type consistency does the content describe for the elements of a linked list?

    1. A

      A linked list stores only references and cannot store element data.

    2. B

      A linked list can be designed to store nodes containing values of the same declared type.

    3. C

      A linked list automatically converts every value to the type of its head node.

    4. D

      A linked list must alternate data types between adjacent nodes.

    Correct answer
    B

    A 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.

  38. 38

    How does a binary tree differ from a general tree in the number of children per node?

    1. A

      A general tree is linear, while a binary tree must be stored contiguously.

    2. B

      A general tree and a binary tree both require exactly two children per node.

    3. C

      A general tree can have any number of children; a binary tree allows at most two.

    4. D

      A general tree has at most two children per node, while a binary tree has no such limit.

    Correct answer
    C

    A 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.

  39. 39

    What property makes a tree a hierarchical data structure?

    1. A

      A tree organizes nodes as a single sequential chain with no branches.

    2. B

      A tree organizes nodes hierarchically through a root and parent-child relationships.

    3. C

      A tree requires every node to connect to every other node.

    4. D

      A tree stores nodes only in a fixed-size, contiguous array.

    Correct answer
    B

    A 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.

  40. 40

    What is a leaf node?

    1. A

      A leaf node is any node shared by two different parents.

    2. B

      A leaf node is a node with no children.

    3. C

      A leaf node is any node that has exactly one child.

    4. D

      A leaf node is the root node with the greatest number of children.

    Correct answer
    B

    A 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.

  41. 41

    Which ordering rule defines the binary search tree described in the content?

    1. A

      A binary search tree places values randomly and sorts only during traversal.

    2. B

      A binary search tree stores smaller values on the right and larger values on the left.

    3. C

      A binary search tree places smaller values left and larger values right of a node.

    4. D

      A binary search tree stores all values in sorted order in a single chain.

    Correct answer
    C

    A 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.

  42. 42

    Which child counts are allowed for an individual node in a binary tree?

    1. A

      A node may have zero, one, or two children, but no more than two.

    2. B

      Every node must have at least one child and may have more than two.

    3. C

      Every node must have exactly two children.

    4. D

      Only the root node is limited to two children.

    Correct answer
    A

    A 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.

  43. 43

    Which sequence defines inorder traversal?

    1. A

      Inorder visits left subtree, right subtree, then node.

    2. B

      Inorder visits right subtree, node, then left subtree.

    3. C

      Inorder visits left subtree, node, then right subtree.

    4. D

      Inorder visits node, left subtree, then right subtree.

    Correct answer
    C

    Inorder visits left subtree, node, then right subtree.

    Explanation

    In inorder traversal, the left subtree is visited first, then the node, then the right subtree.

  44. 44

    Which sequence defines preorder traversal?

    1. A

      Preorder visits node, left subtree, then right subtree.

    2. B

      Preorder visits left subtree, right subtree, then node.

    3. C

      Preorder visits right subtree, node, then left subtree.

    4. D

      Preorder visits left subtree, node, then right subtree.

    Correct answer
    A

    Preorder visits node, left subtree, then right subtree.

    Explanation

    Preorder visits the node first, then its left subtree, and then its right subtree.

  45. 45

    Which sequence defines postorder traversal?

    1. A

      Postorder visits right subtree, node, then left subtree.

    2. B

      Postorder visits node, right subtree, then left subtree.

    3. C

      Postorder visits node, left subtree, then right subtree.

    4. D

      Postorder visits left subtree, right subtree, then node.

    Correct answer
    D

    Postorder visits left subtree, right subtree, then node.

    Explanation

    Postorder visits the left subtree and right subtree before visiting the node itself.

  46. 46

    What ordering results from performing inorder traversal on a correctly ordered binary search tree?

    1. A

      Postorder traversal sorts the tree by visiting the root first.

    2. B

      Inorder traversal of a correctly ordered binary search tree yields ascending values.

    3. C

      Inorder traversal always visits a general tree in descending order.

    4. D

      Preorder traversal always returns a binary search tree’s values in ascending order.

    Correct answer
    B

    Inorder 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.

  47. 47

    Which uses for preorder traversal are specifically discussed in the content?

    1. A

      Preorder is used only to traverse a tree from leaves toward its root.

    2. B

      Preorder guarantees ascending output for every binary tree.

    3. C

      Preorder can support copying a tree and counting its nodes or leaves.

    4. D

      Preorder is required to find the minimum value in every general tree.

    Correct answer
    C

    Preorder 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.

  48. 48

    How do tree traversals correspond to expression notations in the examples?

    1. A

      Preorder produces infix, inorder produces postfix, and postorder produces prefix.

    2. B

      Preorder produces prefix, inorder produces infix, and postorder produces postfix.

    3. C

      Preorder produces postfix, inorder produces prefix, and postorder produces infix.

    4. D

      Preorder, inorder, and postorder all produce the same expression notation.

    Correct answer
    B

    Preorder 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.

  49. 49

    Why can a tree be preferable to a linear data structure for some search tasks?

    1. A

      Trees are useful because they guarantee that no comparisons are needed.

    2. B

      Trees are useful only when data must remain in contiguous memory.

    3. C

      Trees can organize data hierarchically and support efficient searches compared with linear structures.

    4. D

      Trees are useful because every tree operation always takes constant time.

    Correct answer
    C

    Trees 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.

  50. 50

    Why does deleting a node from a binary search tree require considering how many children it has?

    1. A

      A node with two children is always deleted by deleting both of its children first.

    2. B

      Deletion is equally simple for all nodes because tree links never need adjustment.

    3. C

      Deletion requires different handling depending on whether a node has zero, one, or two children.

    4. D

      A node with no children cannot be deleted without rebuilding the whole tree.

    Correct answer
    C

    Deletion 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.

  51. 51

    Which description best defines an algorithm in the content?

    1. A

      An algorithm is a sequence of machine instructions that must use one specific language.

    2. B

      An algorithm is a step-by-step solution approach that is independent of a particular programming language.

    3. C

      An algorithm is a Java class that stores values in a fixed-size array.

    4. D

      An algorithm is a measure of the amount of memory a program occupies.

    Correct answer
    B

    An 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.

  52. 52

    What do time complexity and space complexity measure, respectively?

    1. A

      Time complexity measures the programming language, while space complexity measures the data type.

    2. B

      Time complexity counts only loops, while space complexity counts only recursive calls.

    3. C

      Time complexity describes operation growth, while space complexity describes memory requirements.

    4. D

      Time complexity measures memory use, while space complexity counts comparisons.

    Correct answer
    C

    Time 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.

  53. 53

    Why is worst-case complexity commonly used when estimating an algorithm’s resource needs?

    1. A

      Worst-case analysis estimates the maximum resources an algorithm may require.

    2. B

      Worst-case analysis measures only how quickly an algorithm succeeds.

    3. C

      Best-case analysis is used because it always represents the most likely execution.

    4. D

      Average-case analysis is used because it is always larger than worst-case analysis.

    Correct answer
    A

    Worst-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.

  54. 54

    What is the time complexity of one loop that processes each of nnn elements once?

    1. A

      A single loop over nnn inputs has time complexity O(1)O(1)O(1).

    2. B

      A single loop over nnn inputs has time complexity O(n)O(n)O(n).

    3. C

      A single loop over nnn inputs has time complexity O(n2)O(n^2)O(n2).

    4. D

      A single loop over nnn inputs has time complexity O(\log n).

    Correct answer
    B

    A single loop over nnn inputs has time complexity O(n)O(n)O(n).

    Explanation

    A single loop that performs a constant amount of work per iteration over nnn inputs takes time proportional to nnn.

  55. 55

    What is the time complexity of two nested loops that each run nnn times?

    1. A

      Two fully nested loops over nnn iterations each have time complexity O(1)O(1)O(1).

    2. B

      Two fully nested loops over nnn iterations each have time complexity O(log⁡n)O(\log n)O(logn).

    3. C

      Two fully nested loops over nnn iterations each have time complexity O(n2)O(n^2)O(n2).

    4. D

      Two fully nested loops over nnn iterations each have time complexity O(n)O(n)O(n).

    Correct answer
    C

    Two fully nested loops over nnn iterations each have time complexity O(n2)O(n^2)O(n2).

    Explanation

    If an outer loop runs nnn times and an inner loop also runs nnn times for each outer iteration, the total work is proportional to n2n^2n2.

  56. 56

    How is asymptotic time complexity generally determined for sequential code sections?

    1. A

      Sequential sections always have the complexity of the first statement only.

    2. B

      Sequential sections always have complexities multiplied together.

    3. C

      Sequential sections are combined, and the dominant growth term determines the asymptotic complexity.

    4. D

      Sequential sections always have the sum of all terms retained exactly.

    Correct answer
    C

    Sequential 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.

  57. 57

    What is the worst-case time complexity of linear search on an unsorted array of nnn elements?

    1. A

      Linear search checks every pair of elements, giving O(n2)O(n^2)O(n2) worst-case time.

    2. B

      Linear search halves the remaining search range, giving O(log⁡n)O(\log n)O(logn) worst-case time.

    3. C

      Linear search checks elements one by one, giving O(n)O(n)O(n) worst-case time.

    4. D

      Linear search finds any element in constant time by using its index.

    Correct answer
    C

    Linear search checks elements one by one, giving O(n)O(n)O(n) worst-case time.

    Explanation

    Linear search checks elements one by one; in the worst case it examines all nnn elements, giving O(n)O(n)O(n) time.

  58. 58

    Which best describes the best- and worst-case time complexities of linear search?

    1. A

      Its best and worst cases are both O(log⁡n)O(\log n)O(logn).

    2. B

      Its best case is O(n)O(n)O(n) and its worst case is O(1)O(1)O(1).

    3. C

      Its best and worst cases are both O(n2)O(n^2)O(n2).

    4. D

      Its best case is O(1)O(1)O(1) and its worst case is O(n)O(n)O(n).

    Correct answer
    D

    Its best case is O(1)O(1)O(1) and its worst case is O(n)O(n)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 nnn elements.

  59. 59

    Why does binary search have logarithmic time complexity?

    1. A

      Binary search repeatedly halves the search range, giving O(log⁡n)O(\log n)O(logn) time.

    2. B

      Binary search compares every pair of elements, giving O(n2)O(n^2)O(n2) time.

    3. C

      Binary search sorts the array after each comparison, giving O(nlog⁡n)O(n\log n)O(nlogn) time.

    4. D

      Binary search checks each element in sequence, giving O(n)O(n)O(n) time.

    Correct answer
    A

    Binary search repeatedly halves the search range, giving O(log⁡n)O(\log n)O(logn) time.

    Explanation

    Binary search uses comparisons to eliminate half of the remaining sorted search range at each step, leading to logarithmic time.

  60. 60

    Why must the data be sorted before applying the binary search method described in the content?

    1. A

      Binary search requires sorted data so that one half can be safely discarded.

    2. B

      Binary search requires mixed data types so comparisons can distinguish both halves.

    3. C

      Binary search works only when the target is guaranteed to be the middle element.

    4. D

      Binary search requires a linked list because arrays do not support midpoint comparisons.

    Correct answer
    A

    Binary 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.

  61. 61

    How should binary search choose a half after comparing the midpoint with the target?

    1. A

      Regardless of the comparison, search both halves to ensure the target is found.

    2. B

      If the midpoint is less than the target, search the right half; if greater, search the left.

    3. C

      If the midpoint is less than the target, search the left half; if greater, search the right.

    4. D

      If the midpoint differs from the target, restart the search at index zero.

    Correct answer
    B

    If 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.

  62. 62

    What is a key space-related distinction between recursive and iterative binary search?

    1. A

      Recursive binary search requires a queue to remember each midpoint.

    2. B

      Recursive binary search searches both halves and therefore always uses O(n)O(n)O(n) time.

    3. C

      Recursive binary search eliminates all memory use because each call replaces the previous call.

    4. D

      Recursive binary search searches one half per call but uses call-stack space for its calls.

    Correct answer
    D

    Recursive 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.

  63. 63

    What auxiliary-space complexity does the content associate with linear search?

    1. A

      Linear search uses O(n2)O(n^2)O(n2) auxiliary space because it checks every pair.

    2. B

      Linear search uses O(log⁡n)O(\log n)O(logn) auxiliary space because it divides the array.

    3. C

      Linear search uses O(1)O(1)O(1) auxiliary space because it needs only a fixed amount of extra storage.

    4. D

      Linear search uses O(n)O(n)O(n) auxiliary space because it copies the entire array.

    Correct answer
    C

    Linear search uses O(1)O(1)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.

  64. 64

    Which process describes merge sort?

    1. A

      Merge sort divides the data into subproblems, sorts them, and merges the results.

    2. B

      Merge sort partitions around a pivot and places smaller values on one side.

    3. C

      Merge sort scans once and swaps every adjacent out-of-order pair.

    4. D

      Merge sort repeatedly selects the smallest element and moves it to the front.

    Correct answer
    A

    Merge 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.

  65. 65

    Why does merge sort have O(nlog⁡n)O(n\log n)O(nlogn) time complexity?

    1. A

      Merge sort has O(n2)O(n^2)O(n2) time because it compares every pair of elements.

    2. B

      Merge sort has O(nlog⁡n)O(n\log n)O(nlogn) time because it has logarithmic division levels and linear merging work per level.

    3. C

      Merge sort has O(n)O(n)O(n) time because each element is processed only once overall.

    4. D

      Merge sort has O(log⁡n)O(\log n)O(logn) time because each level uses one comparison.

    Correct answer
    B

    Merge sort has O(nlog⁡n)O(n\log n)O(nlogn) time because it has logarithmic division levels and linear merging work per level.

    Explanation

    Merge sort repeatedly divides an nnn-element problem into halves, producing about log⁡n\log nlogn levels, and does O(n)O(n)O(n) work per level when merging.

  66. 66

    What auxiliary-space complexity is associated with the merge-sort implementation described?

    1. A

      Merge sort uses O(log⁡n)O(\log n)O(logn) auxiliary space because it stores only recursion calls.

    2. B

      Merge sort uses O(n)O(n)O(n) auxiliary space because it stores data in temporary arrays.

    3. C

      Merge sort uses O(n2)O(n^2)O(n2) auxiliary space because it stores every pair of elements.

    4. D

      Merge sort uses O(1)O(1)O(1) auxiliary space because it sorts only by swapping in place.

    Correct answer
    B

    Merge sort uses O(n)O(n)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.

  67. 67

    What does it mean for a sorting algorithm to be stable?

    1. A

      A stable sort uses no auxiliary memory under any implementation.

    2. B

      A stable sort preserves the relative order of equal-valued elements.

    3. C

      A stable sort guarantees that every element remains at its original index.

    4. D

      A stable sort always produces descending order.

    Correct answer
    B

    A 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.

  68. 68

    Which comparison between merge sort and quicksort matches the content?

    1. A

      Merge sort is in-place and unstable, while quicksort is stable and uses auxiliary arrays.

    2. B

      Merge sort and quicksort both require O(n)O(n)O(n) auxiliary space and preserve all equal-item order.

    3. C

      Both merge sort and quicksort are necessarily stable and in-place.

    4. D

      Merge sort is stable but uses auxiliary space; quicksort is in-place but can be unstable.

    Correct answer
    D

    Merge 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.

  69. 69

    What is the central operation in quicksort?

    1. A

      Quicksort repeatedly merges two already sorted arrays into a new array.

    2. B

      Quicksort finds the minimum repeatedly and moves it to the beginning.

    3. C

      Quicksort selects a pivot, partitions values around it, and recursively sorts the partitions.

    4. D

      Quicksort inserts each element into its final position by shifting all earlier values.

    Correct answer
    C

    Quicksort 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.

  70. 70

    Which worst-case time complexities distinguish quicksort and merge sort in the content?

    1. A

      Quicksort’s worst case is O(log⁡n)O(\log n)O(logn), while merge sort’s worst case is O(n)O(n)O(n).

    2. B

      Quicksort’s worst case is O(1)O(1)O(1), while merge sort’s worst case is O(n2)O(n^2)O(n2).

    3. C

      Quicksort’s worst case is O(nlog⁡n)O(n\log n)O(nlogn), while merge sort’s worst case is O(n2)O(n^2)O(n2).

    4. D

      Quicksort’s worst case is O(n2)O(n^2)O(n2), while merge sort’s worst case is O(nlog⁡n)O(n\log n)O(nlogn).

    Correct answer
    D

    Quicksort’s worst case is O(n2)O(n^2)O(n2), while merge sort’s worst case is O(nlog⁡n)O(n\log n)O(nlogn).

    Explanation

    The content describes quicksort’s worst case as O(n2)O(n^2)O(n2), which can occur when partitioning is very unbalanced; merge sort remains O(nlog⁡n)O(n\log n)O(nlogn).

  71. 71

    Why is quicksort described as an in-place algorithm in the content?

    1. A

      Quicksort is in-place because it stores all values in a separate queue.

    2. B

      Quicksort is in-place because it always creates a complete copy of the input.

    3. C

      Quicksort is described as in-place because it rearranges the original array without merge sort’s auxiliary arrays.

    4. D

      Quicksort is in-place because it never changes the input array.

    Correct answer
    C

    Quicksort 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.

  72. 72

    What defines recursion, and what prevents recursive calls from continuing indefinitely?

    1. A

      Recursion occurs when a function calls itself, with a base case stopping the calls.

    2. B

      Recursion occurs when a function stores its result in an array.

    3. C

      Recursion occurs when a function calls a different function once.

    4. D

      Recursion occurs when a loop repeats without changing its counter.

    Correct answer
    A

    Recursion 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.

  73. 73

    What happens to activation records during recursive calls?

    1. A

      A recursive call avoids memory use because its execution is always iterative.

    2. B

      A recursive call creates a stack activation record that remains until the call returns.

    3. C

      A recursive call overwrites the previous activation record, so no extra space is used.

    4. D

      A recursive call stores its activation record in the queue’s rear position.

    Correct answer
    B

    A 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.

  74. 74

    What is the main idea behind backtracking?

    1. A

      Backtracking permanently commits to the first choice and never revisits it.

    2. B

      Backtracking explores a path and returns to an earlier choice point to try alternatives.

    3. C

      Backtracking follows only the shortest path and discards all other paths immediately.

    4. D

      Backtracking sorts all possible choices before exploring any of them.

    Correct answer
    B

    Backtracking 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.

  75. 75

    What limitation can arise from making locally optimal choices in a greedy algorithm?

    1. A

      A greedy algorithm always evaluates every complete solution before choosing one.

    2. B

      A greedy algorithm randomly chooses among all possible solutions.

    3. C

      A greedy algorithm uses previous subproblem solutions to guarantee a global optimum.

    4. D

      A greedy algorithm makes locally best choices, which may not produce the globally best solution.

    Correct answer
    D

    A 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.

  76. 76

    What does the Bangalore-to-Delhi example demonstrate about greedy decisions?

    1. A

      The greedy route compares all complete paths before selecting the shortest one.

    2. B

      A locally shorter leg can lead to a longer total route than another path.

    3. C

      The greedy route is globally optimal because every locally shortest leg guarantees the shortest total route.

    4. D

      The greedy route uses previously computed subproblem solutions to revise every earlier choice.

    Correct answer
    B

    A 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.

  77. 77

    Which collection contains problems or algorithms that the content associates with greedy methods?

    1. A

      Examples include stack push, queue dequeue, linked-list traversal, and tree inorder only.

    2. B

      Examples include linear search, bubble sort, memory allocation, and function calls only.

    3. C

      Examples include the traveling salesperson problem, spanning-tree methods, Dijkstra’s algorithm, vertex cover, and knapsack.

    4. D

      Examples include merge sort, binary search, recursion, and array indexing only.

    Correct answer
    C

    Examples 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.

  78. 78

    What is a key difference between greedy methods and dynamic programming as presented?

    1. A

      Greedy methods always guarantee the global optimum; dynamic programming guarantees only feasibility.

    2. B

      Greedy methods make local choices; dynamic programming considers stored solutions to subproblems.

    3. C

      Greedy and dynamic programming both ignore previous results and always have the same running time.

    4. D

      Greedy methods store every subproblem result; dynamic programming makes one local choice only.

    Correct answer
    B

    Greedy 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.

  79. 79

    How does dynamic programming use earlier subproblem results?

    1. A

      Dynamic programming reuses previous subproblem results when solving later stages.

    2. B

      Dynamic programming avoids storing any earlier solution.

    3. C

      Dynamic programming is necessarily faster because it ignores prior choices.

    4. D

      Dynamic programming chooses only the currently most attractive option.

    Correct answer
    A

    Dynamic 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.

  80. 80

    What distinguishes fractional knapsack from zero-one knapsack?

    1. A

      Fractional knapsack requires whole items, while zero-one knapsack permits any fraction.

    2. B

      Zero-one knapsack permits splitting items, while fractional knapsack does not.

    3. C

      Both versions require every item to be selected completely.

    4. D

      Fractional knapsack permits fractions of items; zero-one knapsack selects or rejects whole items.

    Correct answer
    D

    Fractional 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.

  81. 81

    What ratio guides the greedy selection in the fractional knapsack algorithm?

    1. A

      It ranks items only by total weight and selects the heaviest items first.

    2. B

      It ranks items by weight divided by profit and selects the largest ratio last.

    3. C

      It ranks items only by total profit and ignores their weights.

    4. D

      It ranks items by profit per unit weight and considers larger ratios first.

    Correct answer
    D

    It 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.

  82. 82

    What should the fractional-knapsack algorithm do when only part of the next item fits?

    1. A

      The algorithm takes the fraction of the item that fits in the remaining capacity.

    2. B

      The algorithm exceeds the capacity if the item’s profit is sufficiently high.

    3. C

      The algorithm discards every previously selected item and restarts with the next one.

    4. D

      The algorithm rounds the item’s weight down and treats it as fully selected.

    Correct answer
    A

    The 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.

  83. 83

    What is the central objective in the knapsack problem described?

    1. A

      It selects the most profitable items even if their total weight exceeds capacity.

    2. B

      It selects the lightest items regardless of their profits or total capacity.

    3. C

      It selects items to maximize profit without exceeding the knapsack’s capacity.

    4. D

      It minimizes the number of items without regard to their weights or profits.

    Correct answer
    C

    It 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.

  84. 84

    What graph task does the content associate with Dijkstra’s algorithm?

    1. A

      Dijkstra’s algorithm sorts graph vertices into ascending order.

    2. B

      Dijkstra’s algorithm constructs a binary search tree from sorted input.

    3. C

      Dijkstra’s algorithm finds a minimum spanning tree by selecting every edge.

    4. D

      Dijkstra’s algorithm finds shortest paths from one source to other vertices.

    Correct answer
    D

    Dijkstra’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.

  85. 85

    What are the basic components of a graph?

    1. A

      A graph consists of arrays and indexes, with edges representing array positions.

    2. B

      A graph consists of roots and leaves, with edges representing memory addresses.

    3. C

      A graph consists of queues and stacks, with edges representing operation order.

    4. D

      A graph consists of vertices and edges, with edges connecting vertices.

    Correct answer
    D

    A 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.

  86. 86

    What distinguishes a directed graph from an undirected graph?

    1. A

      A directed graph requires every edge to connect both ways.

    2. B

      A directed graph assigns a direction to edges, so reverse connections need not exist.

    3. C

      A directed graph permits edges only between vertices at the same level.

    4. D

      A directed graph has no edges between its vertices.

    Correct answer
    B

    A 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.

  87. 87

    How is an edge interpreted in an undirected graph?

    1. A

      An undirected graph contains no connections between vertices.

    2. B

      An undirected edge connects a vertex only to itself.

    3. C

      An undirected edge has no specified direction and represents a two-way connection.

    4. D

      An undirected edge points from exactly one vertex to another.

    Correct answer
    C

    An 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.

  88. 88

    When is a graph disconnected?

    1. A

      A graph is disconnected whenever any vertex has more than two neighbors.

    2. B

      A graph is disconnected when some vertices or components have no connecting path.

    3. C

      A graph is disconnected whenever it has more edges than vertices.

    4. D

      A graph is disconnected whenever it contains a cycle.

    Correct answer
    B

    A 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.

  89. 89

    What information does an adjacency matrix represent?

    1. A

      An adjacency matrix represents a graph using one Boolean value for the entire graph.

    2. B

      An adjacency matrix uses rows and columns to represent connections between vertex pairs.

    3. C

      An adjacency matrix stores only the names of vertices, not their connections.

    4. D

      An adjacency matrix stores a separate linked list for every possible path.

    Correct answer
    B

    An 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.

  90. 90

    What does an adjacency list contain for each graph vertex?

    1. A

      An adjacency list stores only each vertex’s number of outgoing edges.

    2. B

      An adjacency list records the neighbors directly connected to each vertex.

    3. C

      An adjacency list stores each graph vertex as a separate matrix row.

    4. D

      An adjacency list stores all possible vertex pairs in a sorted sequence.

    Correct answer
    B

    An 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.

  91. 91

    Which approach and supporting data structure characterize breadth-first search?

    1. A

      Breadth-first search explores level by level, typically using a queue.

    2. B

      Breadth-first search follows one path to its deepest point, typically using a stack.

    3. C

      Breadth-first search visits vertices in sorted numerical order.

    4. D

      Breadth-first search repeatedly chooses the lowest-weight edge, without a queue.

    Correct answer
    A

    Breadth-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.

  92. 92

    Why does a breadth-first search implementation keep track of visited vertices?

    1. A

      A vertex is marked visited only if it has no adjacent vertices.

    2. B

      A vertex is marked visited when it is first placed in the adjacency matrix.

    3. C

      A vertex is marked visited only after every graph edge has been removed.

    4. D

      A visited marker prevents the search from repeatedly processing a vertex.

    Correct answer
    D

    A 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.

  93. 93

    Which description matches depth-first search?

    1. A

      Depth-first search repeatedly finds the smallest value and uses a priority queue.

    2. B

      Depth-first search visits all immediate neighbors before going deeper and uses a queue.

    3. C

      Depth-first search explores deeply before backtracking and can use a stack.

    4. D

      Depth-first search visits vertices by sorted label and uses an array only.

    Correct answer
    C

    Depth-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.

  94. 94

    Which comparison between BFS and DFS is correct?

    1. A

      BFS and DFS both require sorted vertices and do not use visited tracking.

    2. B

      BFS uses a stack and depth-first order, while DFS uses a queue and breadth-first order.

    3. C

      BFS and DFS differ only in whether the graph has directed edges.

    4. D

      BFS uses a queue for level order, while DFS uses a stack for depth-first exploration.

    Correct answer
    D

    BFS 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.

  95. 95

    Which property defines a spanning tree of a connected graph with VVV vertices?

    1. A

      A spanning tree contains every edge of the graph and may include cycles.

    2. B

      A spanning tree connects all vertices without cycles and has V−1V-1V−1 edges.

    3. C

      A spanning tree contains one vertex and no edges, regardless of the graph.

    4. D

      A spanning tree connects only leaf vertices and has V+1V+1V+1 edges.

    Correct answer
    B

    A spanning tree connects all vertices without cycles and has V−1V-1V−1 edges.

    Explanation

    A spanning tree connects every vertex of a connected graph without cycles and has one fewer edge than vertices.

  96. 96

    What is the goal of a minimum spanning tree?

    1. A

      A minimum spanning tree connects only the lowest-degree vertices.

    2. B

      A minimum spanning tree is the tree with the greatest number of edges.

    3. C

      A minimum spanning tree is a shortest path from one chosen source.

    4. D

      A minimum spanning tree connects all vertices with minimum total edge weight.

    Correct answer
    D

    A 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.

  97. 97

    How does Prim’s algorithm build a minimum spanning tree?

    1. A

      Prim’s algorithm grows from a starting vertex by adding a light edge to a new vertex.

    2. B

      Prim’s algorithm repeatedly selects the globally heaviest remaining edge.

    3. C

      Prim’s algorithm sorts all vertices and connects them in label order.

    4. D

      Prim’s algorithm chooses a shortest path independently from every vertex.

    Correct answer
    A

    Prim’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.

  98. 98

    What is the key edge-selection rule in Kruskal’s algorithm?

    1. A

      Kruskal’s algorithm begins at one vertex and always selects its lightest outgoing edge.

    2. B

      Kruskal’s algorithm adds edges in decreasing weight order until every cycle is closed.

    3. C

      Kruskal’s algorithm selects edges randomly and removes cycles afterward.

    4. D

      Kruskal’s algorithm adds edges from low to high weight while avoiding cycles.

    Correct answer
    D

    Kruskal’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.

Question 1 of 98
Question 1 of 98

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent