1. Home
  2. Explore
  3. Computer Science
  4. JavaScript Data Structures

Study methods

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

JavaScript Data Structures

  • 86Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Stacks and Queues

Which principle describes how a stack processes elements?

86 questions

  1. 1

    Which principle describes how a stack processes elements?

    1. A

      Highest priority, first out

    2. B

      Last in, first out

    3. C

      Random access, first out

    4. D

      First in, first out

    Correct answer
    B

    Last in, first out

    Explanation

    A stack uses last-in, first-out behavior: the most recently added element is the first one removed.

  2. 2

    Which stack operation adds an element to the top of the stack?

    1. A

      shift

    2. B

      pop

    3. C

      push

    4. D

      peek

    Correct answer
    C

    push

    Explanation

    The push operation places a new element on top of a stack.

  3. 3

    What does the pop operation do to a stack?

    1. A

      Removes and returns the top element

    2. B

      Displays the top element without removing it

    3. C

      Counts the elements without changing them

    4. D

      Adds an element to the bottom

    Correct answer
    A

    Removes and returns the top element

    Explanation

    Pop removes the top element and returns its value.

  4. 4

    How does the peek operation differ from pop?

    1. A

      Peek returns the bottom element and removes it

    2. B

      Peek adds an element to the top of the stack

    3. C

      Peek removes the top element without returning it

    4. D

      Peek returns the top element without removing it

    Correct answer
    D

    Peek returns the top element without removing it

    Explanation

    Peek examines the top element while leaving it in the stack; pop removes it.

  5. 5

    Why can a JavaScript array be used directly as a stack?

    1. A

      Arrays automatically prevent duplicate values

    2. B

      Arrays provide operations such as push and pop

    3. C

      Arrays allow access only to the last element

    4. D

      Arrays always maintain sorted order

    Correct answer
    B

    Arrays provide operations such as push and pop

    Explanation

    JavaScript arrays already provide the push and pop operations needed for basic stack behavior.

  6. 6

    Why does popping letters after pushing them in forward order produce a reversed word?

    1. A

      The stack automatically alphabetizes the letters

    2. B

      The last pushed letter is removed first

    3. C

      The first pushed letter is removed first

    4. D

      The stack converts each letter to its opposite

    Correct answer
    B

    The last pushed letter is removed first

    Explanation

    Because a stack is last in, first out, letters pushed from left to right are popped from right to left.

  7. 7

    How can a stack-based palindrome check determine whether a word is a palindrome?

    1. A

      It sorts the letters and compares their frequencies

    2. B

      It compares only the first and last letters

    3. C

      It compares the original word with the reversed word

    4. D

      It checks whether every letter appears only once

    Correct answer
    C

    It compares the original word with the reversed word

    Explanation

    A palindrome reads the same forward and backward, so comparing the original word with its stack-generated reverse is sufficient.

  8. 8

    What does the count variable track in the custom stack implementation?

    1. A

      The value of the top element

    2. B

      The number of elements in the stack

    3. C

      The index of the bottom element

    4. D

      The number of duplicate elements

    Correct answer
    B

    The number of elements in the stack

    Explanation

    The custom stack uses count to record how many items it currently contains.

  9. 9

    What happens when pop is called on an empty custom stack?

    1. A

      It throws away the entire stack

    2. B

      It adds a null element

    3. C

      It returns the bottom element

    4. D

      It returns undefined

    Correct answer
    D

    It returns undefined

    Explanation

    The implementation checks whether the count is zero and returns undefined when no element exists.

  10. 10

    Which principle describes a standard queue?

    1. A

      Highest value, first out

    2. B

      Random element, first out

    3. C

      Last in, first out

    4. D

      First in, first out

    Correct answer
    D

    First in, first out

    Explanation

    A queue removes elements in the same order in which they were added.

  11. 11

    In the described array-based queue, where are elements added and removed?

    1. A

      Added and removed only at the beginning

    2. B

      Added at the end and removed from the beginning

    3. C

      Added at the beginning and removed from the end

    4. D

      Added and removed only at the end

    Correct answer
    B

    Added at the end and removed from the beginning

    Explanation

    The implementation uses push to add at the end and shift to remove from the beginning.

  12. 12

    What does the front operation of a queue do?

    1. A

      Returns the last element without removing it

    2. B

      Returns the first element without removing it

    3. C

      Adds a new element before the first element

    4. D

      Removes and returns the first element

    Correct answer
    B

    Returns the first element without removing it

    Explanation

    Front examines the element at the beginning of the queue while leaving it in place.

  13. 13

    How does a priority queue differ from a standard queue?

    1. A

      Elements are ordered partly by priority

    2. B

      Elements must always be strings

    3. C

      Elements cannot be removed from a priority queue

    4. D

      Elements are arranged alphabetically

    Correct answer
    A

    Elements are ordered partly by priority

    Explanation

    A priority queue stores both an element and a priority, placing higher-priority elements ahead of lower-priority ones.

  14. 14

    If two elements in a priority queue have the same priority, how are they ordered?

    1. A

      They are ordered alphabetically

    2. B

      They retain their insertion order

    3. C

      They are placed at random

    4. D

      They are ordered from largest to smallest

    Correct answer
    B

    They retain their insertion order

    Explanation

    Equal-priority elements behave like elements in a normal queue and remain in insertion order.

  15. 15

    What is the defining property of a set data structure?

    1. A

      It stores values only in first-in, first-out order

    2. B

      It stores unique values without requiring a particular order

    3. C

      It stores every value together with a numerical index

    4. D

      It stores values only in last-in, first-out order

    Correct answer
    B

    It stores unique values without requiring a particular order

    Explanation

    A set contains no duplicate elements, and its values are not required to have a particular order.

  16. 16

    What does the has method of a set return?

    1. A

      The number of duplicate elements

    2. B

      A sorted copy of the set

    3. C

      Whether a specified element is present

    4. D

      The position of the largest element

    Correct answer
    C

    Whether a specified element is present

    Explanation

    The has method checks for membership and returns true or false.

  17. 17

    What should add return when an element is already in the custom set?

    1. A

      The duplicate element

    2. B

      true

    3. C

      The set's size

    4. D

      false

    Correct answer
    D

    false

    Explanation

    The custom add method returns false when it does not add an element because that element already exists.

  18. 18

    What should remove return when it successfully deletes an element from the custom set?

    1. A

      The deleted element's index

    2. B

      true

    3. C

      false

    4. D

      The entire collection

    Correct answer
    B

    true

    Explanation

    The custom remove method returns true after finding and deleting the requested element.

  19. 19

    Which name does the ES6 Set use for the operation called remove in the custom implementation?

    1. A

      erase

    2. B

      discard

    3. C

      removeItem

    4. D

      delete

    Correct answer
    D

    delete

    Explanation

    ES6 Set uses delete to remove an element.

  20. 20

    What does the union of two sets contain?

    1. A

      Only elements found in the first set

    2. B

      All elements from both sets without duplicates

    3. C

      Only elements shared by both sets

    4. D

      Only elements found in neither set

    Correct answer
    B

    All elements from both sets without duplicates

    Explanation

    Union combines both sets and eliminates duplicate values.

  21. 21

    What does the intersection of two sets contain?

    1. A

      Elements present in both sets

    2. B

      Elements present in either set but not both

    3. C

      All elements from the second set

    4. D

      All elements from the first set

    Correct answer
    A

    Elements present in both sets

    Explanation

    The intersection contains only values that occur in both sets.

  22. 22

    What does the difference between two sets contain?

    1. A

      All elements from both sets with duplicates

    2. B

      Elements that occur in neither set

    3. C

      Elements in one set but not in the other

    4. D

      Elements occurring in both sets

    Correct answer
    C

    Elements in one set but not in the other

    Explanation

    The difference removes from one set the values that are also present in the other set.

  23. 23

    When is one set a subset of another set?

    1. A

      When the first set contains an element absent from the second

    2. B

      When both sets have exactly the same size

    3. C

      When every element of the first set is in the second set

    4. D

      When the sets contain no common elements

    Correct answer
    C

    When every element of the first set is in the second set

    Explanation

    A set is a subset when it is completely contained within another set.

  24. 24

    What is a tree node that has no children called?

    1. A

      A branch node

    2. B

      A root node

    3. C

      A parent node

    4. D

      A leaf node

    Correct answer
    D

    A leaf node

    Explanation

    Leaf nodes occur at the ends of a tree and have no children.

  25. 25

    What is the root node of a tree?

    1. A

      The deepest node of the tree

    2. B

      The node with the greatest value

    3. C

      The top node of the tree

    4. D

      The node with no parent but two children always

    Correct answer
    C

    The top node of the tree

    Explanation

    The root is the topmost node from which the tree branches.

  26. 26

    What distinguishes a binary tree from a general tree?

    1. A

      Each node must have exactly two children

    2. B

      Each node has at most two children

    3. C

      The tree cannot contain leaf nodes

    4. D

      The tree can contain only two total nodes

    Correct answer
    B

    Each node has at most two children

    Explanation

    A binary tree permits zero, one, or two children per node, but never more than two.

  27. 27

    What ordering rule defines a binary search tree?

    1. A

      Only leaf values are required to be ordered

    2. B

      All values are stored in insertion order

    3. C

      Left values are greater than the parent and right values are smaller

    4. D

      Left values are less than or equal to the parent and right values are greater than or equal

    Correct answer
    D

    Left values are less than or equal to the parent and right values are greater than or equal

    Explanation

    A binary search tree places smaller or equal values in the left subtree and larger or equal values in the right subtree.

  28. 28

    What happens when a value equal to an existing node is added to the described binary search tree?

    1. A

      The entire tree is rebuilt

    2. B

      The duplicate is always placed in the left subtree

    3. C

      The duplicate value is not added

    4. D

      The duplicate is always placed in the right subtree

    Correct answer
    C

    The duplicate value is not added

    Explanation

    The described insertion function returns without adding a node when the value already exists.

  29. 29

    Where is the minimum value found in a binary search tree?

    1. A

      At the root node

    2. B

      At the leftmost node

    3. C

      At the first inserted node

    4. D

      At the rightmost node

    Correct answer
    B

    At the leftmost node

    Explanation

    Following left children until no further left child exists reaches the minimum value.

  30. 30

    Where is the maximum value found in a binary search tree?

    1. A

      At the root node

    2. B

      At the shallowest leaf

    3. C

      At the leftmost node

    4. D

      At the rightmost node

    Correct answer
    D

    At the rightmost node

    Explanation

    Following right children until no further right child exists reaches the maximum value.

  31. 31

    What does the find operation return in the described binary search tree?

    1. A

      The height of the tree

    2. B

      A sorted array of all values

    3. C

      The parent node of the searched value

    4. D

      true if the value exists and false otherwise

    Correct answer
    D

    true if the value exists and false otherwise

    Explanation

    The find function searches the tree and returns a Boolean indicating whether the value is present.

  32. 32

    Which deletion case is simplest in a binary search tree?

    1. A

      Deleting a leaf node

    2. B

      Deleting a node with two children and many descendants

    3. C

      Deleting the root with two children

    4. D

      Deleting a node whose value is duplicated throughout the tree

    Correct answer
    A

    Deleting a leaf node

    Explanation

    A leaf has no children, so it can simply be replaced with null.

  33. 33

    How is a binary search tree node with one child removed?

    1. A

      The node is replaced by its child

    2. B

      Both the node and its child are deleted

    3. C

      The tree is converted into an array

    4. D

      The child is moved to the root automatically

    Correct answer
    A

    The node is replaced by its child

    Explanation

    When a node has one child, the child takes the node's place in the tree.

  34. 34

    What is the height of a tree node in the described convention?

    1. A

      The number of children it has

    2. B

      Its numerical value minus the root value

    3. C

      The number of values stored in the tree

    4. D

      Its distance in levels from the root

    Correct answer
    D

    Its distance in levels from the root

    Explanation

    The root has height zero, and each lower level increases the distance by one.

  35. 35

    When is a tree considered balanced according to the described criterion?

    1. A

      Every node has exactly two children

    2. B

      Its root is the smallest value

    3. C

      All leaves occur at exactly the same depth

    4. D

      Its minimum and maximum heights differ by at most one

    Correct answer
    D

    Its minimum and maximum heights differ by at most one

    Explanation

    The tree is considered balanced when the minimum and maximum heights differ by no more than one.

  36. 36

    What is the defining order of an in-order traversal?

    1. A

      Node, left subtree, right subtree

    2. B

      Right subtree, node, left subtree

    3. C

      Left subtree, node, right subtree

    4. D

      Left subtree, right subtree, node

    Correct answer
    C

    Left subtree, node, right subtree

    Explanation

    In-order traversal visits the left subtree, then the current node, then the right subtree.

  37. 37

    What is the defining order of a pre-order traversal?

    1. A

      Right subtree, left subtree, node

    2. B

      Left subtree, node, right subtree

    3. C

      Node, left subtree, right subtree

    4. D

      Left subtree, right subtree, node

    Correct answer
    C

    Node, left subtree, right subtree

    Explanation

    Pre-order traversal visits a node before visiting either of its subtrees.

  38. 38

    What is the defining order of a post-order traversal?

    1. A

      Node, left subtree, right subtree

    2. B

      Left subtree, right subtree, node

    3. C

      Right subtree, node, left subtree

    4. D

      Node, right subtree, left subtree

    Correct answer
    B

    Left subtree, right subtree, node

    Explanation

    Post-order traversal visits both subtrees before visiting the node itself.

  39. 39

    Which traversal explores all nodes at one level before moving to the next?

    1. A

      In-order traversal

    2. B

      Post-order traversal

    3. C

      Level-order traversal

    4. D

      Pre-order traversal

    Correct answer
    C

    Level-order traversal

    Explanation

    Level-order traversal is breadth-first: it processes one level completely before proceeding downward.

  40. 40

    What data structure is used in the described level-order traversal?

    1. A

      A queue

    2. B

      A hash table

    3. C

      A set

    4. D

      A stack

    Correct answer
    A

    A queue

    Explanation

    The traversal enqueues child nodes and dequeues them in level order.

  41. 41

    What is the average time complexity of search, insertion, and deletion in a hash table?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(1)O(1)O(1)

    3. C

      O(n)O(n)O(n)

    4. D

      O(log⁡n)O(\log n)O(logn)

    Correct answer
    B

    O(1)O(1)O(1)

    Explanation

    Hash tables provide average constant-time search, insertion, and deletion when hashing distributes keys effectively.

  42. 42

    What does a hash function do in a hash table?

    1. A

      Converts an array into a linked list

    2. B

      Removes duplicate values from the table

    3. C

      Sorts all keys alphabetically

    4. D

      Maps a key to an array index

    Correct answer
    D

    Maps a key to an array index

    Explanation

    A hash function transforms a key into a numerical value used to identify a storage bucket or array index.

  43. 43

    What property must a hash function have for reliable lookup?

    1. A

      The result must always equal zero

    2. B

      Every key must produce a different result

    3. C

      The result must depend on insertion order

    4. D

      The same key must produce the same result

    Correct answer
    D

    The same key must produce the same result

    Explanation

    A key must hash to the same index each time so that its associated value can be found later.

  44. 44

    What is a collision in a hash table?

    1. A

      A value is stored without a key

    2. B

      Two tables have different storage limits

    3. C

      Two keys hash to the same index

    4. D

      A key is removed before it is inserted

    Correct answer
    C

    Two keys hash to the same index

    Explanation

    A collision occurs when different keys produce the same hash index.

  45. 45

    How can collisions be handled using buckets?

    1. A

      Replace the entire hash table

    2. B

      Discard every key that collides

    3. C

      Store multiple key-value pairs at the same index

    4. D

      Change all keys to numerical indexes

    Correct answer
    C

    Store multiple key-value pairs at the same index

    Explanation

    A bucket can contain multiple key-value pairs, which are searched to locate the requested key.

  46. 46

    Why does a modulus operation constrain a hash index to the available buckets?

    1. A

      The modulus operation converts values into strings

    2. B

      The remainder is always within the bucket-index range

    3. C

      The modulus operation sorts all keys

    4. D

      The modulus operation prevents every collision

    Correct answer
    B

    The remainder is always within the bucket-index range

    Explanation

    Taking the hash value modulo the number of buckets produces a remainder from zero through one less than the bucket count.

  47. 47

    What two pieces of information does each linked-list node contain?

    1. A

      A parent reference and a child count

    2. B

      An index and a sorting priority

    3. C

      An element and a reference to the next node

    4. D

      A key and a hash value

    Correct answer
    C

    An element and a reference to the next node

    Explanation

    Each node stores its element and a link to the next node.

  48. 48

    What does the head of a linked list reference?

    1. A

      The node at the middle index

    2. B

      The first node

    3. C

      The last node

    4. D

      The largest node

    Correct answer
    B

    The first node

    Explanation

    The head pointer identifies the first node in the linked list.

  49. 49

    What does the next reference of the final linked-list node contain?

    1. A

      null

    2. B

      The list length

    3. C

      The previous node

    4. D

      The head node

    Correct answer
    A

    null

    Explanation

    The final node has no successor, so its next reference is null.

  50. 50

    What is a major advantage of linked lists over fixed-size arrays?

    1. A

      Linked lists always use less memory than arrays

    2. B

      Linked lists can grow dynamically

    3. C

      Linked lists provide instant random access

    4. D

      Linked lists automatically keep values sorted

    Correct answer
    B

    Linked lists can grow dynamically

    Explanation

    Linked lists can expand by connecting additional nodes rather than requiring a predetermined array capacity.

  51. 51

    What is a major advantage of arrays over linked lists?

    1. A

      Arrays provide direct random access by index

    2. B

      Arrays make insertion at the beginning constant-time

    3. C

      Arrays always have dynamic size

    4. D

      Arrays require no memory allocation

    Correct answer
    A

    Arrays provide direct random access by index

    Explanation

    An array can retrieve an element at a known index directly, whereas a linked list must be traversed node by node.

  52. 52

    Why can linked-list insertion and deletion be efficient after the relevant location is found?

    1. A

      All elements are automatically copied into a new array

    2. B

      The values are sorted before every operation

    3. C

      Only node references need to be changed

    4. D

      The list uses binary search to locate every node

    Correct answer
    C

    Only node references need to be changed

    Explanation

    Insertion and deletion can be performed by redirecting links rather than shifting many elements.

  53. 53

    What does a linked-list index lookup generally require?

    1. A

      Traversing from the head through preceding nodes

    2. B

      Hashing the requested index

    3. C

      Checking only the final node

    4. D

      Sorting the nodes by value

    Correct answer
    A

    Traversing from the head through preceding nodes

    Explanation

    Because linked lists do not support direct indexing, the list must be traversed from the head.

  54. 54

    What happens when the head node is removed from a linked list?

    1. A

      The head remains unchanged

    2. B

      The head is updated to the removed node's next node

    3. C

      The last node becomes null

    4. D

      Every node is deleted

    Correct answer
    B

    The head is updated to the removed node's next node

    Explanation

    The next node becomes the new first node when the current head is removed.

  55. 55

    What is a trie primarily designed to store?

    1. A

      Graph edges by their weights

    2. B

      Numerical values in heap order

    3. C

      Queue elements by priority

    4. D

      Strings or words by shared prefixes

    Correct answer
    D

    Strings or words by shared prefixes

    Explanation

    A trie stores words one character at a time, sharing nodes for common prefixes.

  56. 56

    What does each step or node in a trie represent?

    1. A

      A character in a word

    2. B

      A complete graph

    3. C

      A numerical hash bucket

    4. D

      A queue position

    Correct answer
    A

    A character in a word

    Explanation

    Each trie node corresponds to a character along a word path.

  57. 57

    Why must a trie distinguish between a node that ends a word and one that merely continues a prefix?

    1. A

      A prefix can exist without being a complete word

    2. B

      Words cannot share initial characters

    3. C

      Trie nodes cannot contain more than one character

    4. D

      Every prefix is automatically a complete word

    Correct answer
    A

    A prefix can exist without being a complete word

    Explanation

    A marker such as isEnd indicates whether the current character completes a stored word, even if longer words continue from it.

  58. 58

    What is the defining relationship between parent and child nodes in a min-heap?

    1. A

      Each parent must equal both children

    2. B

      Each parent is less than or equal to its children

    3. C

      Each parent is greater than or equal to its children

    4. D

      Each parent must have exactly one child

    Correct answer
    B

    Each parent is less than or equal to its children

    Explanation

    In a min-heap, the smallest value is at the root and every parent is no greater than its children.

  59. 59

    What is the defining relationship between parent and child nodes in a max-heap?

    1. A

      Each parent is greater than or equal to its children

    2. B

      Each parent must have exactly two children

    3. C

      Each parent must be smaller than both children

    4. D

      Each parent is less than or equal to its children

    Correct answer
    A

    Each parent is greater than or equal to its children

    Explanation

    A max-heap places the largest value at the root, with each parent at least as large as its children.

  60. 60

    What does it mean for a binary heap to be complete?

    1. A

      Every node has exactly two children

    2. B

      The values are completely sorted from left to right

    3. C

      Every level is full except possibly the last, which fills left to right

    4. D

      All leaves occur at different depths

    Correct answer
    C

    Every level is full except possibly the last, which fills left to right

    Explanation

    A complete binary tree fills every level before beginning the next and fills a partially complete final level from left to right.

  61. 61

    Why can a binary heap be efficiently represented as an array?

    1. A

      Its values are always stored in sorted array order

    2. B

      It contains no leaf nodes

    3. C

      Its complete structure allows child and parent indexes to be calculated

    4. D

      It never contains duplicate values

    Correct answer
    C

    Its complete structure allows child and parent indexes to be calculated

    Explanation

    The heap's structure makes parent-child relationships computable from indexes without storing explicit node references.

  62. 62

    Using one-based indexing, what is the index of the left child of a heap element at index iii?

    1. A

      2i2i2i

    2. B

      i−1i-1i−1

    3. C

      2i+12i+12i+1

    4. D

      ⌊i/2⌋\lfloor i/2 \rfloor⌊i/2⌋

    Correct answer
    A

    2i2i2i

    Explanation

    With one-based heap indexing, the left child is at index 2i2i2i.

  63. 63

    Using one-based indexing, what is the index of the right child of a heap element at index iii?

    1. A

      2i+12i+12i+1

    2. B

      2i2i2i

    3. C

      ⌊i/2⌋\lfloor i/2 \rfloor⌊i/2⌋

    4. D

      i+1i+1i+1

    Correct answer
    A

    2i+12i+12i+1

    Explanation

    With one-based heap indexing, the right child is at index 2i+12i+12i+1.

  64. 64

    Using one-based indexing, what is the index of the parent of an element at index iii?

    1. A

      2i+12i+12i+1

    2. B

      i−2i-2i−2

    3. C

      ⌊i/2⌋\lfloor i/2 \rfloor⌊i/2⌋

    4. D

      2i2i2i

    Correct answer
    C

    ⌊i/2⌋\lfloor i/2 \rfloor⌊i/2⌋

    Explanation

    The parent index is the floor of i/2i/2i/2, meaning the result is rounded down to the nearest integer.

  65. 65

    What happens when a new value is inserted into the described min-heap?

    1. A

      It is placed according to alphabetical order

    2. B

      It is inserted at the root without comparison

    3. C

      It is appended and moved upward while smaller than its parent

    4. D

      It replaces the root and moves downward immediately

    Correct answer
    C

    It is appended and moved upward while smaller than its parent

    Explanation

    Heap insertion first places the value at the end, then repeatedly swaps it with its parent when it violates the min-heap property.

  66. 66

    What happens when the minimum value is removed from the described min-heap?

    1. A

      The first leaf becomes the new root without further comparisons

    2. B

      All elements are shifted one position left

    3. C

      The heap is converted into a binary search tree

    4. D

      The last element moves to the root and moves downward as needed

    Correct answer
    D

    The last element moves to the root and moves downward as needed

    Explanation

    After removing the root, the final element is moved to the root and sifted downward to restore heap order.

  67. 67

    What ordering does the described heap sort produce when using a min-heap?

    1. A

      Insertion order

    2. B

      Least to greatest

    3. C

      Greatest to least

    4. D

      Random order

    Correct answer
    B

    Least to greatest

    Explanation

    Repeatedly removing the minimum from a min-heap produces the values in ascending order.

  68. 68

    What is the average and worst-case time complexity of the described heap sort?

    1. A

      O(n)O(n)O(n)

    2. B

      O(n2)O(n^2)O(n2)

    3. C

      O(1)O(1)O(1)

    4. D

      O(nlog⁡n)O(n\log n)O(nlogn)

    Correct answer
    D

    O(nlog⁡n)O(n\log n)O(nlogn)

    Explanation

    The content identifies heap sort as having average and worst-case performance of O(nlog⁡n)O(n\log n)O(nlogn).

  69. 69

    In graph terminology, what are the data items or points called?

    1. A

      Nodes or vertices

    2. B

      Edges or links

    3. C

      Buckets or slots

    4. D

      Roots or leaves

    Correct answer
    A

    Nodes or vertices

    Explanation

    The points in a graph are called nodes or vertices.

  70. 70

    What are the connections between graph nodes called?

    1. A

      Edges

    2. B

      Buckets

    3. C

      Roots

    4. D

      Indexes

    Correct answer
    A

    Edges

    Explanation

    Edges represent relationships or connections between vertices.

  71. 71

    What distinguishes an undirected graph from a directed graph?

    1. A

      Undirected graphs cannot contain cycles, whereas directed graphs can

    2. B

      Undirected graphs have weights, whereas directed graphs never do

    3. C

      Undirected graphs use numbers, whereas directed graphs use strings

    4. D

      Undirected edges have no direction, whereas directed edges do

    Correct answer
    D

    Undirected edges have no direction, whereas directed edges do

    Explanation

    An undirected edge represents a mutual connection, while a directed edge points from one node toward another.

  72. 72

    What does an adjacency list associate with each vertex?

    1. A

      A list of every possible path in the graph

    2. B

      A matrix containing only edge weights

    3. C

      A collection of neighboring vertices

    4. D

      A list of nodes in insertion order

    Correct answer
    C

    A collection of neighboring vertices

    Explanation

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

  73. 73

    What does an adjacency matrix use to represent an edge?

    1. A

      A 111 indicates a relationship and a 000 indicates none

    2. B

      A 000 indicates a relationship and a 111 indicates none

    3. C

      A negative number indicates every relationship

    4. D

      A string indicates a relationship and null indicates none

    Correct answer
    A

    A 111 indicates a relationship and a 000 indicates none

    Explanation

    In the described unweighted adjacency matrix, one represents an edge and zero represents no edge.

  74. 74

    What do the rows and columns represent in an adjacency matrix?

    1. A

      Rows represent nodes and columns represent path lengths

    2. B

      Both rows and columns represent graph nodes

    3. C

      Rows represent edges and columns represent nodes

    4. D

      Rows represent weights and columns represent buckets

    Correct answer
    B

    Both rows and columns represent graph nodes

    Explanation

    An adjacency matrix uses both dimensions to identify pairs of nodes.

  75. 75

    How does an incidence matrix differ from an adjacency matrix?

    1. A

      Rows represent edges and columns represent nodes only in undirected graphs

    2. B

      Rows represent nodes and columns represent edges

    3. C

      Both rows and columns represent edge weights

    4. D

      Both rows and columns represent nodes

    Correct answer
    B

    Rows represent nodes and columns represent edges

    Explanation

    An incidence matrix uses rows for vertices and columns for individual edges.

  76. 76

    How does an incidence matrix represent an undirected edge?

    1. A

      It places a 111 in the rows of the two connected nodes

    2. B

      It places a 111 only in the row of the source node

    3. C

      It places a 000 in both connected rows

    4. D

      It places a negative 111 in both connected rows

    Correct answer
    A

    It places a 111 in the rows of the two connected nodes

    Explanation

    Each undirected edge connects two nodes, so its column contains a one in both corresponding node rows.

  77. 77

    How are directed edges represented in the described incidence matrix?

    1. A

      Both endpoints receive a −1-1−1 regardless of direction

    2. B

      A 111 marks an entering edge and −1-1−1 marks a leaving edge

    3. C

      Both endpoints receive a 111 regardless of direction

    4. D

      A 111 marks an edge leaving a node and −1-1−1 marks an edge entering it

    Correct answer
    D

    A 111 marks an edge leaving a node and −1-1−1 marks an edge entering it

    Explanation

    For directed graphs, the source receives one and the destination receives negative one.

  78. 78

    What does a weighted graph attach to its edges?

    1. A

      A Boolean indicating whether nodes are sorted

    2. B

      Numerical values representing the cost or weight of connections

    3. C

      A unique root node

    4. D

      A stack position

    Correct answer
    B

    Numerical values representing the cost or weight of connections

    Explanation

    Weighted edges carry numerical values whose meaning depends on the application.

  79. 79

    What is the purpose of graph traversal algorithms?

    1. A

      To visit graph nodes and analyze their relationships

    2. B

      To ensure that all node labels are unique

    3. C

      To remove every edge from a graph

    4. D

      To convert every graph into a tree

    Correct answer
    A

    To visit graph nodes and analyze their relationships

    Explanation

    Traversal algorithms systematically visit nodes to explore a graph or determine relationships such as distances.

  80. 80

    What is the main strategy of breadth-first search?

    1. A

      Visit nodes in descending numerical order

    2. B

      Visit all nodes at the current distance before moving farther away

    3. C

      Visit only nodes with weighted edges

    4. D

      Follow one path as deeply as possible before backtracking

    Correct answer
    B

    Visit all nodes at the current distance before moving farther away

    Explanation

    Breadth-first search explores neighbors first, then neighbors of those nodes, proceeding outward by distance.

  81. 81

    What does the distance value of infinity represent in the described breadth-first search?

    1. A

      The node is exactly one edge away

    2. B

      The node is the root node

    3. C

      The node has the greatest numerical label

    4. D

      The node has not been reached from the start node

    Correct answer
    D

    The node has not been reached from the start node

    Explanation

    Distances begin at infinity to indicate that a node is currently considered unreachable or unvisited from the selected root.

  82. 82

    What distance is assigned to the starting node in breadth-first search?

    1. A

      −1-1−1

    2. B

      Infinity

    3. C

      111

    4. D

      000

    Correct answer
    D

    000

    Explanation

    The root node is zero edges away from itself.

  83. 83

    Why does breadth-first search use a queue?

    1. A

      It processes discovered nodes in order of their distance from the root

    2. B

      It prevents the graph from containing cycles

    3. C

      It stores only nodes that have no neighbors

    4. D

      It guarantees that the largest node is processed first

    Correct answer
    A

    It processes discovered nodes in order of their distance from the root

    Explanation

    A queue ensures that nodes discovered earlier are processed before nodes discovered later, producing breadth-first order.

  84. 84

    When does the described breadth-first search assign a distance to a neighbor?

    1. A

      Only when the neighbor is the root

    2. B

      Only when the neighbor has no outgoing edges

    3. C

      When the neighbor's distance is still infinity

    4. D

      Whenever the neighbor has already been visited

    Correct answer
    C

    When the neighbor's distance is still infinity

    Explanation

    A neighbor receives a distance only if it has not already been assigned one.

  85. 85

    How is the distance of a newly discovered neighbor calculated?

    1. A

      The total number of graph nodes

    2. B

      The neighbor's index plus one

    3. C

      The current node's distance plus one

    4. D

      The current node's distance minus one

    Correct answer
    C

    The current node's distance plus one

    Explanation

    Moving across one edge increases the current distance by one.

  86. 86

    When does the breadth-first search loop stop?

    1. A

      When the first neighbor is found

    2. B

      When every node has the same distance

    3. C

      When the queue contains no more nodes to process

    4. D

      When the root node is removed from the graph

    Correct answer
    C

    When the queue contains no more nodes to process

    Explanation

    The traversal continues while the queue is nonempty and stops after all reachable discovered nodes have been processed.

Question 1 of 86
Question 1 of 86

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent