1. Home
  2. Explore
  3. Computer Science
  4. CS50 Week 7: Data Tools

Study methods

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

CS50 Week 7: Data Tools

  • 125Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Data Files
The database-centric language introduced for working with relational data is
.

125 questions

  1. 1
    The database-centric language introduced for working with relational data is
    _____
    .
    Hint

    Its name stands for Structured Query Language.

    Answer

    SQL

  2. 2
    A text file containing rows of data separated by delimiters is called a
    _____
    database.
    Hint

    It is a simple alternative to a full database program.

    Answer

    flat file

  3. 3
    The file format whose name means comma-separated values is abbreviated
    _____
    .
    Hint

    It is commonly used to exchange spreadsheet data in a portable format.

    Answer

    CSV

  4. 4
    In a CSV file, newline characters such as \n are used to represent separate
    _____
    .
    Hint

    They move the cursor to the next line.

    Answer

    rows

  5. 5
    In a CSV file, commas are used to separate values that represent different
    _____
    .
    Hint

    They separate fields within a row.

    Answer

    columns

  6. 6
    A CSV file's first row often describes the names or meanings of the columns and is called the
    _____
    row.
    Hint

    It contains metadata rather than an ordinary data record.

    Answer

    header

  7. 7
    When a CSV field contains a comma, the conventional way to prevent confusion is to
    _____
    the string.
    Hint

    The field is enclosed using quotation marks.

    Answer

    quote

  8. 8
    A globally portable format that can be exported from spreadsheet software is
    _____
    .
    Hint

    It is not a proprietary Apple, Microsoft, or Google format.

    Answer

    .csv

  9. 9
    A tab-separated version of a delimited text file is abbreviated
    _____
    .
    Hint

    The separator is a tab rather than a comma.

    Answer

    TSV

  10. 10
    In the survey data, the three columns were timestamp, language, and
    _____
    .
    Hint

    This column recorded a favorite CS50 assignment.

    Answer

    problem

  11. 11
    The Python module that provides functionality for reading CSV files is imported with
    _____
    .
    Hint

    The module name is the same as the file format abbreviation.

    Answer

    import csv

  12. 12
    The Python function that opens a file is
    _____
    .
    Hint

    It corresponds conceptually to fopen in C.

    Answer

    open

  13. 13
    The optional mode argument r passed to Python's open function means to open a file for
    _____
    .
    Hint

    This mode is implied if the second argument is omitted.

    Answer

    reading

  14. 14
    The Python function corresponding to C's fclose is
    _____
    .
    Hint

    It releases the file after processing.

    Answer

    close

  15. 15
    The Python keyword that automatically closes a file after leaving its indented block is
    _____
    .
    Hint

    It begins a context-management statement.

    Answer

    with

  16. 16
    The Python CSV function that returns rows as lists is
    _____
    .
    Hint

    It is called from the csv module.

    Answer

    reader

  17. 17
    Calling
    _____
    on a CSV reader skips the header row by retrieving the next row before the loop begins.
    Hint

    It advances an iterator.

    Answer

    next

  18. 18
    Because Python lists use zero-based indexing, row[1] refers to the
    _____
    column of a three-column row.
    Hint

    Index 0 refers to the first column.

    Answer

    second

  19. 19
    The CSV reader returns each row as a list whose elements correspond to the row's
    _____
    .
    Hint

    The survey rows contain timestamp, language, and problem.

    Answer

    columns

  20. 20
    The Python CSV tool that uses the header names as dictionary keys is
    _____
    .
    Hint

    Its name combines dictionary functionality with the ordinary reader.

    Answer

    DictReader

  21. 21
    With DictReader, a row's language value can be accessed using the key
    _____
    .
    Hint

    The key comes directly from the header row.

    Answer

    "language"

  22. 22
    Using named dictionary keys is more robust than numeric indices because moving columns does not break the code unless the
    _____
    is renamed.
    Hint

    The code still depends on the field's name.

    Answer

    column

  23. 23
    A spreadsheet interface is considered fragile because users can easily move, delete, or add
    _____
    .
    Hint

    Position-based code can then refer to the wrong data.

    Answer

    columns

  24. 24
    The Python syntax that increments a counter by one without using ++ is
    _____
    .
    Hint

    Python supports augmented assignment but not C's increment operator.

    Answer

    += 1

  25. 25
    A dictionary associates
    _____
    with values, making it useful for counting categories.
    Hint

    Scratch, C, and Python can serve as these labels.

    Answer

    keys

  26. 26
    An empty Python dictionary can conventionally be created with
    _____
    .
    Hint

    It uses two empty curly braces.

    Answer

    {}

  27. 27
    The Python expression favorite in counts checks whether favorite is already a
    _____
    in the dictionary.
    Hint

    It does not search the dictionary's values in this context.

    Answer

    key

  28. 28
    When a language is encountered for the first time, its count should be initialized to
    _____
    .
    Hint

    The current row is already the first observation.

    Answer

    one

  29. 29
    When a previously observed language appears again, its dictionary value is incremented by
    _____
    .
    Hint

    Each row represents one additional response.

    Answer

    one

  30. 30
    The Python function that sorts dictionary keys alphabetically by default is
    _____
    .
    Hint

    It can be used directly in a for loop.

    Answer

    sorted

  31. 31
    A Python dictionary can be iterated over with for favorite in counts to process its
    _____
    .
    Hint

    These are the entries on the left-hand side of the mapping.

    Answer

    keys

  32. 32
    The counts.get method can be supplied to sorted to sort dictionary entries by their
    _____
    .
    Hint

    For a counting dictionary, these are the frequencies.

    Answer

    values

  33. 33
    Passing reverse=True to sorted changes the order from ascending to
    _____
    .
    Hint

    This produces the most popular item first.

    Answer

    descending

  34. 34
    Arguments supplied according to their left-to-right position are called
    _____
    arguments.
    Hint

    Their meaning depends on where they appear in the call.

    Answer

    positional

  35. 35
    Arguments supplied using explicit parameter names are called
    _____
    parameters.
    Hint

    They make clear which option is being selected.

    Answer

    named

  36. 36
    The Python class designed to provide built-in counting capabilities is
    _____
    .
    Hint

    It comes from the collections module.

    Answer

    Counter

  37. 37
    A Counter automatically initializes an unseen item to
    _____
    when it is incremented.
    Hint

    This removes the need for a separate first-observation case.

    Answer

    zero

  38. 38
    The Counter method that returns items ordered from most common to least common is
    _____
    .
    Hint

    Its name describes the ranking it produces.

    Answer

    most_common

  39. 39
    Python permits a loop to assign two values per iteration by separating the loop variables with a
    _____
    .
    Hint

    This is useful when iterating over key-value pairs.

    Answer

    comma

  40. 40
    SQL stands for
    _____
    Query Language.
    Hint

    It is the first word in the language's full name.

    Answer

    Structured

  41. 41
    SQL is described as a
    _____
    language because it specifies the desired data rather than usually specifying loops and conditionals.
    Hint

    It describes what answer is wanted instead of every step for obtaining it.

    Answer

    declarative

  42. 42
    The four-part database operation paradigm abbreviated CRUD consists of create, read, update, and
    _____
    .
    Hint

    It is the most destructive of the four basic operations.

    Answer

    delete

  43. 43
    In SQL terminology, adding new rows is performed with the
    _____
    keyword.
    Hint

    It corresponds to creating or adding data.

    Answer

    INSERT

  44. 44
    In SQL terminology, reading or retrieving data is performed with the
    _____
    keyword.
    Hint

    It asks the database to return specified data.

    Answer

    SELECT

  45. 45
    The SQL keyword that changes existing data is
    _____
    .
    Hint

    It modifies values that are already stored.

    Answer

    UPDATE

  46. 46
    The SQL keyword that removes rows from a table is
    _____
    .
    Hint

    It is part of the CRUD acronym's final operation.

    Answer

    DELETE

  47. 47
    The SQL command that can destructively remove an entire table is
    _____
    .
    Hint

    It is more destructive than deleting selected rows.

    Answer

    DROP

  48. 48
    In a relational database, a spreadsheet-like collection of rows and columns is called a
    _____
    .
    Hint

    A database can contain multiple related structures of this type.

    Answer

    table

  49. 49
    SQLite is described in the lecture as a
    _____
    implementation of SQL.
    Hint

    It focuses on core functionality and is commonly used on phones and computers.

    Answer

    lightweight

  50. 50
    SQLite databases are stored in a binary file containing
    _____
    and ones.
    Hint

    Binary data uses two possible digits.

    Answer

    zeros

  51. 51
    The SQLite command that displays a table's design or creation statement is
    _____
    .
    Hint

    It is a SQLite-specific command beginning with a dot.

    Answer

    .schema

  52. 52
    The SQL query pattern used to retrieve columns from a table begins with
    _____
    and specifies the source using FROM.
    Hint

    It is the primary SQL command for reading data.

    Answer

    SELECT

  53. 53
    In SELECT * FROM favorites, the asterisk is a
    _____
    that requests every column.
    Hint

    It means “everything” in this context.

    Answer

    wildcard

  54. 54
    SQL statements in the SQLite command-line interface are conventionally terminated with a
    _____
    .
    Hint

    It marks the end of the query.

    Answer

    semicolon

  55. 55
    The SQL keyword that restricts the number of returned rows is
    _____
    .
    Hint

    It is useful when a table contains thousands of records.

    Answer

    LIMIT

  56. 56
    The SQL aggregate function that counts rows is
    _____
    .
    Hint

    It can be used with an asterisk to count all rows.

    Answer

    COUNT

  57. 57
    Using COUNT(*) is conventional when the goal is to count the number of
    _____
    rather than a particular field.
    Hint

    Every row has the same number of columns.

    Answer

    rows

  58. 58
    The SQL keyword that removes duplicate values from a result is
    _____
    .
    Hint

    It can reveal the unique languages in the survey.

    Answer

    DISTINCT

  59. 59
    SQL functions can be
    _____
    so that the output of one function becomes the input of another.
    Hint

    For example, a count can be applied to distinct values.

    Answer

    nested

  60. 60
    The SQL keyword used to filter rows according to a condition is
    _____
    .
    Hint

    It replaces many explicit conditional branches in this example.

    Answer

    WHERE

  61. 61
    To find responses where the language is C, SQL compares the language column with C using a
    _____
    clause.
    Hint

    This clause filters the table before returning results.

    Answer

    WHERE

  62. 62
    SQL combines conditions with the word
    _____
    rather than C's && operator.
    Hint

    It requires both conditions to be true.

    Answer

    AND

  63. 63
    In SQL, equality comparisons use a
    _____
    equal sign rather than the double equal sign used in C and Python.
    Hint

    SQL follows the comparison style used in Scratch in this respect.

    Answer

    single

  64. 64
    The SQL clause that combines rows with the same value for a column is
    _____
    .
    Hint

    It can group all Python rows, all C rows, and all Scratch rows.

    Answer

    GROUP BY

  65. 65
    To rank grouped results by a count, SQL uses the clause
    _____
    .
    Hint

    It controls the ordering of the result set.

    Answer

    ORDER BY

  66. 66
    The default ordering direction for ORDER BY is abbreviated
    _____
    .
    Hint

    It places smaller values before larger values.

    Answer

    ASC

  67. 67
    To display the largest counts first, SQL uses the ordering direction
    _____
    .
    Hint

    It reverses the default ascending order.

    Answer

    DESC

  68. 68
    The SQL keyword used to give a calculated column a simpler name is
    _____
    .
    Hint

    It can rename COUNT(*) to n.

    Answer

    AS

  69. 69
    A query that asks for the most popular single language can combine ORDER BY with
    _____
    .
    Hint

    Only one result row is needed.

    Answer

    LIMIT 1

  70. 70
    The SQL command for adding a row specifies the destination table with the phrase
    _____
    .
    Hint

    It is followed by the table name.

    Answer

    INSERT INTO

  71. 71
    In an INSERT INTO statement, the first parenthesized list contains the names of the
    _____
    being populated.
    Hint

    The second parenthesized list contains their values.

    Answer

    columns

  72. 72
    In an INSERT INTO statement, the second parenthesized list contains the
    _____
    to store.
    Hint

    They correspond positionally to the listed columns.

    Answer

    values

  73. 73
    In SQL, the special value representing the absence of data is
    _____
    .
    Hint

    It does not represent a memory address in SQL.

    Answer

    NULL

  74. 74
    An UPDATE statement changes existing rows by assigning new values after the keyword
    _____
    .
    Hint

    It is followed by column-value assignments.

    Answer

    SET

  75. 75
    An UPDATE or DELETE statement without a
    _____
    clause can affect every row in the table.
    Hint

    This clause limits the operation to matching records.

    Answer

    WHERE

  76. 76
    The process of separating duplicated data into related tables is called
    _____
    the data.
    Hint

    It creates a canonical source of truth and reduces redundancy.

    Answer

    normalizing

  77. 77
    Giving each show a unique numeric identifier creates a
    _____
    key for the shows table.
    Hint

    It uniquely identifies each row in its own table.

    Answer

    primary

  78. 78
    A column that refers to a primary key in another table is called a
    _____
    key.
    Hint

    Its meaning is relative to another table.

    Answer

    foreign

  79. 79
    A table containing one row for each show and its rating represents a
    _____
    relationship.
    Hint

    Each show has one corresponding rating.

    Answer

    one-to-one

  80. 80
    A relationship in which one show can have several genres is called
    _____
    .
    Hint

    One record on one side can correspond to multiple records on the other.

    Answer

    one-to-many

  81. 81
    A relationship in which a show can have many stars and a person can star in many shows is called
    _____
    .
    Hint

    Both sides can have multiple related records.

    Answer

    many-to-many

  82. 82
    The intermediary table connecting shows and people contains show ID and
    _____
    ID.
    Hint

    This field identifies the individual associated with a show.

    Answer

    person

  83. 83
    The table whose purpose is to connect shows to people in a many-to-many relationship is called
    _____
    .
    Hint

    It records which people star in which shows.

    Answer

    stars

  84. 84
    A table that connects two other tables in a many-to-many relationship is an
    _____
    table.
    Hint

    It sits between the two related entity tables.

    Answer

    intermediary

  85. 85
    Using separate columns named star, star, and star for different numbers of actors creates a sparse or
    _____
    table design.
    Hint

    Different rows would require different numbers of columns.

    Answer

    jagged

  86. 86
    Repeating a show's title for every actor wastes space because duplicated
    _____
    are less efficient than duplicated numeric IDs.
    Hint

    The alternative is to repeat a compact integer identifier.

    Answer

    strings

  87. 87
    The database design principle of storing each show's name and each person's name only once creates a canonical source of
    _____
    .
    Hint

    It avoids conflicting duplicate copies of the same information.

    Answer

    truth

  88. 88
    The SQL operation that combines related tables into a wider temporary result is
    _____
    .
    Hint

    It connects tables using common values.

    Answer

    JOIN

  89. 89
    In a join, the condition introduced by the keyword
    _____
    specifies which columns must match.
    Hint

    It is followed by an equality such as shows.id = ratings.show_id.

    Answer

    ON

  90. 90
    When joining a one-to-many relationship, duplicate rows may appear in the temporary
    _____
    even though the original tables are not duplicated.
    Hint

    It is the output produced by the query.

    Answer

    result set

  91. 91
    A query placed inside another SQL query is called a
    _____
    query.
    Hint

    Parentheses help determine which query runs first.

    Answer

    nested

  92. 92
    In a nested query, parentheses indicate that the inner query should be evaluated
    _____
    .
    Hint

    This follows the same general idea as parentheses in arithmetic.

    Answer

    first

  93. 93
    A database structure that speeds up searches on selected columns is called an
    _____
    .
    Hint

    It avoids repeatedly scanning an entire column linearly.

    Answer

    index

  94. 94
    The SQL command used to create a search index is
    _____
    .
    Hint

    It is followed by the index name, table, and column.

    Answer

    CREATE INDEX

  95. 95
    In SQLite, a primary key is automatically
    _____
    .
    Hint

    Searching by a primary key does not require a full linear scan.

    Answer

    indexed

  96. 96
    Foreign keys in SQLite are not
    _____
    by default.
    Hint

    Additional indexes may be needed when they are frequently used in searches or joins.

    Answer

    indexed

  97. 97
    The tree structure commonly used by database indexes is called a
    _____
    .
    Hint

    It is a short, wide tree rather than a binary tree.

    Answer

    B-tree

  98. 98
    A B-tree is described as short and
    _____
    because each node can have many children.
    Hint

    The large branching factor reduces the tree's height.

    Answer

    wide

  99. 99
    Indexes improve query speed by trading additional storage
    _____
    for reduced execution time.
    Hint

    This is a classic space-time trade-off.

    Answer

    space

  100. 100
    Indexes can slow down inserts, updates, and deletes because the index structure must be
    _____
    .
    Hint

    Changes to table data may require changes to the tree.

    Answer

    maintained

  101. 101
    The SQLite command used to measure query execution time is
    _____
    .
    Hint

    It can be turned on at the SQLite prompt.

    Answer

    .timer

  102. 102
    Searching an unindexed column generally requires a
    _____
    search through the values.
    Hint

    The database may inspect entries from top to bottom.

    Answer

    linear

  103. 103
    A Python program can access a SQLite database through the CS50 library's
    _____
    function.
    Hint

    The library provides a simplified interface for executing database commands.

    Answer

    SQL

  104. 104
    The database connection string used in the example begins with sqlite:/// followed by the database
    _____
    .
    Hint

    The example connected to favorites.db.

    Answer

    filename

  105. 105
    The CS50 database method used to run a SQL query from Python is
    _____
    .
    Hint

    It sends a command to the database.

    Answer

    execute

  106. 106
    In the Python database query, a question mark serves as a
    _____
    for a value supplied separately.
    Hint

    It is analogous in purpose to a format-string substitution marker.

    Answer

    placeholder

  107. 107
    The result returned by a database query is stored in a temporary collection of
    _____
    .
    Hint

    The first result can be accessed with index zero.

    Answer

    rows

  108. 108
    The first row of a Python query result can be accessed with index
    _____
    .
    Hint

    Python sequences use zero-based indexing.

    Answer

    zero

  109. 109
    A database query can be used to provide a value for a Python program's
    _____
    interface.
    Hint

    Python can collect input and SQL can retrieve the corresponding data.

    Answer

    user

  110. 110
    Using Python for the interface and SQL for database retrieval demonstrates that different tools are suited to different
    _____
    .
    Hint

    The lecture emphasizes choosing the right tool for the task.

    Answer

    jobs

  111. 111
    A SQL query that retrieves a count can be embedded in Python to build a web or
    _____
    application.
    Hint

    The lecture mentions applications that run on phones.

    Answer

    mobile

  112. 112
    Using placeholders rather than formatting user input directly into SQL helps prevent
    _____
    injection attacks.
    Hint

    The attack causes user input to be interpreted as database commands.

    Answer

    SQL

  113. 113
    A condition in which simultaneous operations produce an incorrect result because they interleave unpredictably is a
    _____
    condition.
    Hint

    Multiple servers are effectively racing to update shared data.

    Answer

    race

  114. 114
    If three users read one million likes before updating the value, all three might write
    _____
    likes instead of one million three.
    Hint

    Each update is based on the same stale value.

    Answer

    one million one

  115. 115
    The refrigerator-and-milk example illustrates that two people can make decisions based on the same outdated
    _____
    of a shared variable.
    Hint

    Both roommates see that the refrigerator is empty before either purchase is recorded.

    Answer

    state

  116. 116
    A group of database operations that either all happen or none happen is called a
    _____
    .
    Hint

    It groups related operations into one unit.

    Answer

    transaction

  117. 117
    A transaction is described as
    _____
    when its operations occur without interruption or do not occur at all.
    Hint

    This property prevents partial execution.

    Answer

    atomic

  118. 118
    In the CS50 Python library, a transaction can be started with
    _____
    transaction.
    Hint

    This keyword marks the start of a grouped database operation.

    Answer

    BEGIN

  119. 119
    The SQL command that permanently applies a transaction's changes is
    _____
    .
    Hint

    It confirms the completed operation.

    Answer

    COMMIT

  120. 120
    In SQLite, the comment marker that causes the rest of a line to be ignored is two
    _____
    .
    Hint

    It is written as --.

    Answer

    hyphens

  121. 121
    An SQL injection vulnerability can occur when an application directly
    _____
    user input into a query string.
    Hint

    Formatting user input into an f-string is an unsafe example.

    Answer

    interpolates

  122. 122
    Entering a username followed by a quote and SQL's comment marker can cause the password check to be
    _____
    .
    Hint

    The remainder of the query becomes a comment.

    Answer

    ignored

  123. 123
    The safest general solution to SQL injection is to use parameterized queries with
    _____
    .
    Hint

    The example uses question marks instead of interpolated values.

    Answer

    placeholders

  124. 124
    In SQL string escaping, a pair of adjacent single quotes represents a literal
    _____
    .
    Hint

    This is SQL's way of escaping the delimiter itself.

    Answer

    quote

  125. 125
    SQL keywords are generally not case sensitive, but user-created table and column names must be used
    _____
    .
    Hint

    Naming conventions such as lowercase or camel case do not change the underlying requirement.

    Answer

    consistently

1 of 125
Question 1 of 125

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent