1. Home
  2. Explore
  3. Computer Science
  4. CS50 Debugging Tools

Study methods

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

CS50 Debugging Tools

  • 58Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Programming Tools

Which CS50 IDE feature allows a programmer to pause execution, step through code, and inspect variables?

58 questions

  1. 1

    Which CS50 IDE feature allows a programmer to pause execution, step through code, and inspect variables?

    1. A

      The check50 tester

    2. B

      The style50 formatter

    3. C

      The help50 interpreter

    4. D

      The debug50 debugger

    Correct answer
    D

    The debug50 debugger

    Explanation

    debug50 opens a debugging panel that supports breakpoints, step-by-step execution, and variable inspection.

  2. 2

    What is the primary purpose of check50?

    1. A

      To display variable values during program execution

    2. B

      To run automated tests that check code correctness

    3. C

      To explain unfamiliar compiler error messages

    4. D

      To identify inconsistent spacing in source code

    Correct answer
    B

    To run automated tests that check code correctness

    Explanation

    check50 automates tests designed to evaluate whether a program produces the expected results.

  3. 3

    When is printf especially useful during debugging?

    1. A

      When a programmer wants to allocate a dynamically sized memory block

    2. B

      When a programmer wants to automatically correct a syntax error

    3. C

      When a programmer wants to observe values or confirm that execution reached a point

    4. D

      When a programmer wants to replace every breakpoint in a program

    Correct answer
    C

    When a programmer wants to observe values or confirm that execution reached a point

    Explanation

    printf can reveal variable values, trace loop execution, or confirm that a particular point in the program was reached.

  4. 4

    What does style50 primarily evaluate?

    1. A

      The correctness of the program's algorithm

    2. B

      The formatting and readability of source code

    3. C

      The memory leaks produced during program execution

    4. D

      The validity of command-line arguments

    Correct answer
    B

    The formatting and readability of source code

    Explanation

    style50 checks code style, including spacing and formatting that affect readability.

  5. 5

    When should a programmer instinctively use help50?

    1. A

      When source code contains inconsistent indentation

    2. B

      When a command or compiler error message is difficult to understand

    3. C

      When an array needs to be enlarged during execution

    4. D

      When a program needs to be stepped through one statement at a time

    Correct answer
    B

    When a command or compiler error message is difficult to understand

    Explanation

    help50 interprets cryptic error messages and provides more understandable, teaching-fellow-like guidance.

  6. 6

    What is the main purpose of rubber duck debugging?

    1. A

      To convert a text-based program into Scratch blocks

    2. B

      To test whether a program handles invalid input

    3. C

      To uncover mistakes by explaining code aloud step by step

    4. D

      To detect memory leaks by monitoring heap usage

    Correct answer
    C

    To uncover mistakes by explaining code aloud step by step

    Explanation

    Rubber duck debugging requires verbalizing the logic of the program, which can expose an incorrect assumption or unexpected step.

  7. 7

    How can Valgrind be used with a program that requires command-line arguments?

    1. A

      The arguments must be supplied only after the program terminates

    2. B

      The usual arguments can follow the program name in the Valgrind command

    3. C

      The arguments cannot be used because Valgrind accepts only interactive input

    4. D

      The arguments must be placed inside the source code before compilation

    Correct answer
    B

    The usual arguments can follow the program name in the Valgrind command

    Explanation

    Valgrind prefixes the normal execution command, so command-line arguments can be supplied in the usual way.

  8. 8

    What does Valgrind primarily help detect?

    1. A

      Invalid memory accesses and memory leaks

    2. B

      Incorrect user-interface prompts

    3. C

      Poor variable names and inconsistent indentation

    4. D

      Unoptimized arithmetic expressions

    Correct answer
    A

    Invalid memory accesses and memory leaks

    Explanation

    Valgrind reports errors such as invalid reads or writes and memory that was allocated but never freed.

  9. 9

    What can happen when memory allocated with malloc is never freed?

    1. A

      The allocated memory immediately becomes read-only

    2. B

      The compiler automatically copies the memory into a smaller block

    3. C

      The operating system automatically converts the memory into stack space

    4. D

      The program can leak memory and eventually slow down, freeze, or crash

    Correct answer
    D

    The program can leak memory and eventually slow down, freeze, or crash

    Explanation

    Failing to call free leaves allocated memory unavailable for reuse, potentially causing a memory leak and resource exhaustion.

  10. 10

    If a program allocates space for 10 integers, which expression requests the required number of bytes without hard-coding the size of an integer?

    1. A

      10÷sizeof⁡(int)10 \div \operatorname{sizeof}(\text{int})10÷sizeof(int)

    2. B

      sizeof⁡(10×int)\operatorname{sizeof}(10 \times \text{int})sizeof(10×int)

    3. C

      10+sizeof⁡(int)10 + \operatorname{sizeof}(\text{int})10+sizeof(int)

    4. D

      10×sizeof⁡(int)10 \times \operatorname{sizeof}(\text{int})10×sizeof(int)

    Correct answer
    D

    10×sizeof⁡(int)10 \times \operatorname{sizeof}(\text{int})10×sizeof(int)

    Explanation

    Multiplying the number of integers by sizeof(int) accounts for the platform-specific size of each integer.

  11. 11

    What does malloc return when it successfully allocates a block of memory?

    1. A

      A copy of the first value stored in the block

    2. B

      A pointer to the beginning of the allocated block

    3. C

      The number of bytes remaining on the heap

    4. D

      The index of the final byte in the block

    Correct answer
    B

    A pointer to the beginning of the allocated block

    Explanation

    malloc returns an address, represented in C by a pointer, to the newly allocated memory.

  12. 12

    Why is accessing element 10 of an array containing 10 elements invalid?

    1. A

      The valid indices range from 0 through 9

    2. B

      Index 10 always refers to the first element

    3. C

      Arrays can contain only even-numbered indices

    4. D

      The valid indices range from 1 through 10

    Correct answer
    A

    The valid indices range from 0 through 9

    Explanation

    An array of 10 elements has indices 0, 1, through 9, so index 10 is outside its bounds.

  13. 13

    Why might an out-of-bounds memory access appear to work in C?

    1. A

      Valgrind silently repairs the access before execution

    2. B

      The program may accidentally access memory that is available but not part of the array

    3. C

      The compiler changes the invalid index into the final valid index

    4. D

      C automatically expands every array when an invalid index is used

    Correct answer
    B

    The program may accidentally access memory that is available but not part of the array

    Explanation

    C may not immediately detect an out-of-bounds access, and the neighboring memory may happen to be accessible, producing seemingly correct behavior.

  14. 14

    What does an 'invalid read of size 4' commonly indicate when an integer is being accessed?

    1. A

      The program has used a four-character string instead of an integer

    2. B

      The program is reading four bytes from an invalid memory location

    3. C

      The program has printed four integers in the wrong order

    4. D

      The program has allocated four arrays instead of one

    Correct answer
    B

    The program is reading four bytes from an invalid memory location

    Explanation

    An integer commonly occupies four bytes on the discussed systems, so the message indicates an invalid four-byte read.

  15. 15

    When should dynamically allocated memory generally be freed?

    1. A

      Whenever a pointer is passed to another function

    2. B

      After the program has finished using the memory

    3. C

      Immediately after malloc returns, before any use

    4. D

      Before the memory is initialized with a value

    Correct answer
    B

    After the program has finished using the memory

    Explanation

    Memory should be freed only after its final use; freeing it earlier and then accessing it creates a use-after-free error.

  16. 16

    What does freeing memory conceptually tell the operating system?

    1. A

      The physical memory has been erased from the computer

    2. B

      The pointer has been converted into an integer

    3. C

      The memory has been moved permanently to the stack

    4. D

      The memory is available for reuse by other allocations

    Correct answer
    D

    The memory is available for reuse by other allocations

    Explanation

    free marks the allocated region as available again; it does not necessarily erase the physical bytes immediately.

  17. 17

    Which memory region is used by malloc?

    1. A

      The text segment

    2. B

      The register segment

    3. C

      The stack

    4. D

      The heap

    Correct answer
    D

    The heap

    Explanation

    Dynamic memory requested with malloc comes from the heap.

  18. 18

    What is stored in the text segment when a program runs?

    1. A

      The machine-code instructions of the program

    2. B

      The dynamically allocated variables created by malloc

    3. C

      The local variables belonging to active functions

    4. D

      The unused bytes returned by free

    Correct answer
    A

    The machine-code instructions of the program

    Explanation

    The text segment contains the program's machine code after it is loaded from long-term storage into RAM.

  19. 19

    What is typically stored on the stack?

    1. A

      Only memory allocated with malloc

    2. B

      The executable machine code

    3. C

      Files stored permanently on disk

    4. D

      Function call frames and local variables

    Correct answer
    D

    Function call frames and local variables

    Explanation

    The stack contains regions associated with active function calls and their local variables.

  20. 20

    What can occur if the stack and heap grow into one another?

    1. A

      All local variables are copied into the text segment

    2. B

      A memory exhaustion or overflow problem can occur

    3. C

      The operating system converts pointers into strings

    4. D

      The program automatically becomes a linked list

    Correct answer
    B

    A memory exhaustion or overflow problem can occur

    Explanation

    Because memory is finite, excessive growth of either region can cause the stack and heap to collide or exhaust available memory.

  21. 21

    Why does passing ordinary variables to a swap function fail to change the originals in main?

    1. A

      The function cannot contain a temporary variable

    2. B

      The function receives copies of the values rather than the original variables

    3. C

      The compiler automatically reverses the requested assignments

    4. D

      The stack prevents functions from changing integers

    Correct answer
    B

    The function receives copies of the values rather than the original variables

    Explanation

    Function arguments are passed by value in this situation, so the function modifies local copies named a and b.

  22. 22

    How can a swap function modify the original variables in its caller?

    1. A

      By receiving pointers to the variables and dereferencing them

    2. B

      By storing the variables in the text segment

    3. C

      By declaring the function with return type void

    4. D

      By copying the variables into a second array

    Correct answer
    A

    By receiving pointers to the variables and dereferencing them

    Explanation

    Passing addresses lets the function access and modify the original memory locations through dereferencing.

  23. 23

    What does the dereference operator do to a pointer?

    1. A

      It calculates the pointer's position in the source file

    2. B

      It accesses the value stored at the pointer's address

    3. C

      It allocates a new memory block automatically

    4. D

      It converts the pointed-to value into a function

    Correct answer
    B

    It accesses the value stored at the pointer's address

    Explanation

    Dereferencing follows the address stored in a pointer and accesses the data located there.

  24. 24

    Why is dereferencing an uninitialized pointer unsafe?

    1. A

      It may contain an unpredictable address that does not refer to valid memory

    2. B

      It automatically frees the pointer's target

    3. C

      It changes the pointer into a null pointer

    4. D

      It always contains the address of the first array element

    Correct answer
    A

    It may contain an unpredictable address that does not refer to valid memory

    Explanation

    An uninitialized pointer contains an indeterminate garbage value, so dereferencing it can access an invalid location.

  25. 25

    What does a null pointer represent?

    1. A

      A special value indicating that the pointer refers to no valid object

    2. B

      A pointer that always refers to the most recent variable

    3. C

      A pointer to the first byte of every allocated block

    4. D

      A pointer containing an arbitrary leftover memory address

    Correct answer
    A

    A special value indicating that the pointer refers to no valid object

    Explanation

    NULL represents the absence of a valid target address and is commonly used to mark the end of a structure.

  26. 26

    What is the purpose of a struct in C?

    1. A

      To make every variable dynamically allocated

    2. B

      To group related values into a custom data type

    3. C

      To automatically sort all variables in memory

    4. D

      To replace all pointer operations with arithmetic

    Correct answer
    B

    To group related values into a custom data type

    Explanation

    A struct lets programmers define a custom type containing related fields, such as a student's name and dorm.

  27. 27

    What does encapsulation mean in the context of a student struct?

    1. A

      Keeping related student data together in one data structure

    2. B

      Hiding all variables by placing them on the stack

    3. C

      Converting every student field into a function

    4. D

      Storing every student's data in a separate program

    Correct answer
    A

    Keeping related student data together in one data structure

    Explanation

    Encapsulation groups related information, such as name and dorm, into one abstraction representing a student.

  28. 28

    Which operator accesses a field of a structure value?

    1. A

      The scope-resolution operator

    2. B

      The dot operator

    3. C

      The square-bracket operator

    4. D

      The percent operator

    Correct answer
    B

    The dot operator

    Explanation

    For a structure value, the dot operator accesses fields such as student.name or student.dorm.

  29. 29

    Why does a pointer to a struct commonly use the arrow operator?

    1. A

      It converts a structure into an array of integers

    2. B

      It follows two pointers simultaneously

    3. C

      It allocates a new structure and initializes every field

    4. D

      It combines dereferencing the pointer with accessing a structure field

    Correct answer
    D

    It combines dereferencing the pointer with accessing a structure field

    Explanation

    n->field is shorthand for (*n).field: follow the pointer and then access the specified field.

  30. 30

    What is a major limitation of a C array?

    1. A

      Its size cannot be changed directly after it is created

    2. B

      Its elements cannot contain integers

    3. C

      Its elements cannot be accessed using indices

    4. D

      Its elements must always be stored on the heap

    Correct answer
    A

    Its size cannot be changed directly after it is created

    Explanation

    A fixed-size C array cannot grow in place; enlarging it requires another allocation and copying.

  31. 31

    What is the time complexity of resizing an array by creating a new array and copying all existing elements?

    1. A

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

    2. B

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

    3. C

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

    4. D

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

    Correct answer
    D

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

    Explanation

    Copying all nnn existing elements requires a number of operations proportional to nnn.

  32. 32

    What does realloc do when enlarging an allocated block?

    1. A

      It always adds exactly one byte without moving anything

    2. B

      It converts the block into a stack allocation

    3. C

      It frees the block and returns a random address

    4. D

      It may extend the block in place or allocate a new block and copy the contents

    Correct answer
    D

    It may extend the block in place or allocate a new block and copy the contents

    Explanation

    realloc can enlarge the block at its current location if possible, or move the contents to a larger block and return its new address.

  33. 33

    Why should the return value of realloc often be stored in a temporary pointer first?

    1. A

      realloc returns a value that cannot be assigned directly to a pointer

    2. B

      A failed realloc can return NULL, and the original pointer may still be needed

    3. C

      The temporary pointer automatically doubles the allocation

    4. D

      The original pointer is always invalid after any realloc call

    Correct answer
    B

    A failed realloc can return NULL, and the original pointer may still be needed

    Explanation

    Using a temporary pointer allows the program to check for NULL before replacing the original pointer and potentially losing access to the allocation.

  34. 34

    What is the distinction between an array's size and its capacity in the dynamic-array example?

    1. A

      Size is the number of bytes allocated, while capacity is the number of loops

    2. B

      Size is the number of elements used, while capacity is the space available

    3. C

      Size is the maximum possible value, while capacity is the current index

    4. D

      Size refers to the heap, while capacity refers to the stack

    Correct answer
    B

    Size is the number of elements used, while capacity is the space available

    Explanation

    Size records how many elements are currently stored, whereas capacity records how many elements can fit.

  35. 35

    What keystroke was described as signaling end-of-file input in the terminal?

    1. A

      Control-Z

    2. B

      Control-Q

    3. C

      Control-D

    4. D

      Control-C

    Correct answer
    C

    Control-D

    Explanation

    Control-D sends an end-of-file signal, indicating that the user is finished providing input.

  36. 36

    Why cannot getInt directly support a user typing q to quit?

    1. A

      getInt automatically converts q into zero

    2. B

      getInt accepts only commands beginning with Control-D

    3. C

      getInt expects integer input rather than an arbitrary string

    4. D

      getInt terminates the operating system when q is entered

    Correct answer
    C

    getInt expects integer input rather than an arbitrary string

    Explanation

    Because getInt is designed to obtain an integer, a letter such as q is not a valid value for that input function.

  37. 37

    What is the defining representation of a node in a singly linked list?

    1. A

      A value together with pointers to every previous node

    2. B

      A value together with a pointer to the next node

    3. C

      A single pointer with no stored data

    4. D

      A fixed array containing every list value

    Correct answer
    B

    A value together with a pointer to the next node

    Explanation

    Each node stores its own value and an address pointing to the next node in the list.

  38. 38

    Why is the first pointer in a linked list especially important?

    1. A

      It provides access to the first node and therefore to the rest of the list

    2. B

      It stores the number of nodes without pointing to any node

    3. C

      It always points to the final node in the list

    4. D

      It contains a copy of every value in the list

    Correct answer
    A

    It provides access to the first node and therefore to the rest of the list

    Explanation

    Following the first pointer allows traversal from the beginning through every subsequent node.

  39. 39

    What value normally marks the end of a singly linked list?

    1. A

      The largest integer in the list

    2. B

      The address of the first node

    3. C

      NULL

    4. D

      The number of nodes in the list

    Correct answer
    C

    NULL

    Explanation

    The final node's next pointer is set to NULL to indicate that no further node exists.

  40. 40

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

    1. A

      They require no pointers or dynamic memory

    2. B

      They guarantee that all values occupy adjacent memory

    3. C

      They can grow by allocating additional nodes without moving existing nodes

    4. D

      They provide faster random access to every element

    Correct answer
    C

    They can grow by allocating additional nodes without moving existing nodes

    Explanation

    New linked-list nodes can be allocated separately and connected with pointers, avoiding the need to resize and copy the entire structure.

  41. 41

    What is the major access-time disadvantage of a singly linked list?

    1. A

      Finding a later element requires following the links from the beginning

    2. B

      The first element cannot be accessed without sorting the list

    3. C

      The list can contain only one data type

    4. D

      Each node must be copied before it can be read

    Correct answer
    A

    Finding a later element requires following the links from the beginning

    Explanation

    Because nodes may be scattered in memory, the program must traverse the chain sequentially to reach a later node.

  42. 42

    What is the worst-case time complexity of inserting into a sorted singly linked list when the insertion point must be found?

    1. A

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

    2. B

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

    3. C

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

    4. D

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

    Correct answer
    D

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

    Explanation

    The new value may belong at the end, requiring traversal through all nnn existing nodes.

  43. 43

    What is the time complexity of inserting a new node at the beginning of an unsorted linked list?

    1. A

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

    2. B

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

    3. C

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

    4. D

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

    Correct answer
    C

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

    Explanation

    Insertion at the front requires only updating the new node's next pointer and the list's first pointer.

  44. 44

    Why must a new node point to the old successor before the predecessor points to the new node?

    1. A

      Otherwise the list would automatically become sorted

    2. B

      Otherwise NULL would be converted into an integer

    3. C

      Otherwise the only pointer to the old successor could be lost

    4. D

      Otherwise the new node would be allocated on the stack

    Correct answer
    C

    Otherwise the only pointer to the old successor could be lost

    Explanation

    The new node must first preserve the old link; changing the predecessor's pointer too early can disconnect the remainder of the list.

  45. 45

    What additional capability does a doubly linked list provide compared with a singly linked list?

    1. A

      Each node can store values of multiple unrelated data types

    2. B

      The list no longer requires a pointer to its first node

    3. C

      The list automatically provides constant-time search

    4. D

      Each node can point both to the next node and to the previous node

    Correct answer
    D

    Each node can point both to the next node and to the previous node

    Explanation

    A doubly linked list stores forward and backward links, allowing traversal in both directions.

  46. 46

    What is a hash function in the discussed hash-table design?

    1. A

      A function that maps an input, such as a name, to a bucket index

    2. B

      A function that copies an array into a larger array

    3. C

      A function that converts every pointer into NULL

    4. D

      A function that sorts every linked list in descending order

    Correct answer
    A

    A function that maps an input, such as a name, to a bucket index

    Explanation

    The hash function uses an input property, such as the first letter of a name, to select one of several array buckets.

  47. 47

    How is the described hash table commonly structured?

    1. A

      An array whose entries point to linked lists

    2. B

      A single array containing every item in sorted order

    3. C

      A linked list whose entries each contain a complete array

    4. D

      A tree whose nodes contain no pointers

    Correct answer
    A

    An array whose entries point to linked lists

    Explanation

    The array provides bucket access, while each bucket's linked list stores items that hash to that bucket.

  48. 48

    Why can hashing names by their first letter improve lookup performance?

    1. A

      It removes the need to store names in memory

    2. B

      It divides the names among shorter lists instead of one long list

    3. C

      It guarantees that every lookup takes exactly one operation

    4. D

      It sorts all names without comparing any characters

    Correct answer
    B

    It divides the names among shorter lists instead of one long list

    Explanation

    The first letter distributes names across buckets, so each linked list is typically much shorter than one list containing everyone.

  49. 49

    What is the worst-case lookup time for a hash table if every item hashes to the same bucket?

    1. A

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

    2. B

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

    3. C

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

    4. D

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

    Correct answer
    C

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

    Explanation

    If all items occupy one linked list, lookup may require examining all nnn items.

  50. 50

    What is the goal of a well-designed hash function?

    1. A

      To place every item in the first bucket

    2. B

      To distribute items as evenly as possible among buckets

    3. C

      To eliminate the need for an array of buckets

    4. D

      To ensure that all linked lists have different lengths

    Correct answer
    B

    To distribute items as evenly as possible among buckets

    Explanation

    A good hash function reduces collisions by distributing inputs relatively uniformly across the available buckets.

  51. 51

    What ordering property defines a binary search tree in the lecture's example?

    1. A

      Values in the left subtree are smaller and values in the right subtree are larger

    2. B

      Every node has exactly two children with equal values

    3. C

      Values are stored in the tree in the order they were inserted

    4. D

      Values increase only from the root toward the left subtree

    Correct answer
    A

    Values in the left subtree are smaller and values in the right subtree are larger

    Explanation

    For each node, smaller values are placed to the left and larger values to the right, enabling guided searches.

  52. 52

    How many pointer fields are needed in a binary-tree node to represent left and right children?

    1. A

      One pointer field

    2. B

      Three pointer fields

    3. C

      Two pointer fields

    4. D

      No pointer fields

    Correct answer
    C

    Two pointer fields

    Explanation

    A binary-tree node needs one pointer for its left child and one pointer for its right child.

  53. 53

    What is the worst-case search time in a balanced binary search tree with nnn nodes?

    1. A

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

    2. B

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

    3. C

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

    4. D

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

    Correct answer
    A

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

    Explanation

    Each comparison chooses the left or right subtree, approximately halving the remaining search space in a balanced tree.

  54. 54

    Why can a tree provide faster searching than an unsorted linked list?

    1. A

      The ordering allows each comparison to eliminate an entire subtree

    2. B

      Tree nodes are always stored contiguously in memory

    3. C

      A tree stores every value in a single array index

    4. D

      Trees never require dynamic memory allocation

    Correct answer
    A

    The ordering allows each comparison to eliminate an entire subtree

    Explanation

    The binary-search-tree ordering lets the search choose a direction and discard many candidates at each step.

  55. 55

    What is a trie?

    1. A

      A hash table that uses only the last character of each word

    2. B

      A tree in which each node contains an array used to select the next character

    3. C

      A linked list whose nodes each store three integers

    4. D

      A fixed-size array containing all dictionary words directly

    Correct answer
    B

    A tree in which each node contains an array used to select the next character

    Explanation

    A trie represents strings character by character, with each node providing array-based links to possible next characters.

  56. 56

    Why can a trie support lookup in time related to word length rather than dictionary size?

    1. A

      Lookup compares the word against every stored word simultaneously

    2. B

      Lookup stores only the first letter of each word

    3. C

      Lookup always uses binary search over one contiguous array

    4. D

      Lookup follows one character link per letter in the word

    Correct answer
    D

    Lookup follows one character link per letter in the word

    Explanation

    A trie follows the sequence of characters directly, so the number of steps depends primarily on the word's length.

  57. 57

    What is the primary cost of using a trie for fast word lookup?

    1. A

      It can consume a large amount of memory

    2. B

      It makes insertion impossible after initialization

    3. C

      It requires every word to have the same length

    4. D

      It cannot store words with repeated letters

    Correct answer
    A

    It can consume a large amount of memory

    Explanation

    Each node may contain an array of possible character links, so a trie can use substantially more memory than simpler structures.

  58. 58

    How can a trie distinguish between a complete word and a prefix of a longer word?

    1. A

      The trie compares only the first and last letters

    2. B

      The trie must delete every node after a word is found

    3. C

      Every prefix is automatically treated as a complete word

    4. D

      Each node can record whether a word ends at that point

    Correct answer
    D

    Each node can record whether a word ends at that point

    Explanation

    A separate end-of-word marker allows the structure to distinguish a complete word such as Bob from a longer word such as Bobby.

Question 1 of 58
Question 1 of 58

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent