SET A Flashcards

1
Q

Enumerate the three levels of data modeling and briefly explain each.

A
  1. Conceptual Model - High-level overview of entities and relationships
  2. Logical Model - Detailed model design including attributes and keys
  3. Physical Model - implementation leveling, includes data types and indexes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List four advantages of having a well-structured ER diagram in database design.

A

-It organizes data effectively
-Ensures database efficiency
-Prevents redundancy
-Enhances communication with shareholders

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Enumerate the key steps involved in converting a conceptual data model to a logical
data mode

A
  • Identify entity and relationships
  • Define attributes for each entity
  • Choose primary keys for entities
    -Add foreign keys and map relationships
    -Normalize the data
    -Define constraints
    -Review and refine model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consider a Python function that processes a sequence of grades to compute the
average

A

-Error Handling for Empty Strings: If grades_str is an empty string, it would
result in division by zero causing a runtime error. Add a condition to check if there
are no grades before dividing.

-Handling Non-integer inputs (Can be combined with the third one): If
grades_str contains non-integer values, the int() conversion will raise a
ValueError. Use a try-except block to catch invalid inputs.

-Better Input Validation (Can be combined with the second one): The function
doesn’t handle invalid characters, negative grades, or grades that exceed a
reasonable limit (like 100). Add a logic to validate the grades.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the difference between logical and physical data models and provide a
scenario where a logical data model may differ significantly from the physical model.

A

-A Logical Model primarily defines the attributes and keys of entities while the
Physical Model defines its data types and indexes.

  • A logical model might show a customer’s full name as a single attribute,
    but the physical model could split it into separate first_name and
    last_name columns for easier sorting and searching. This change makes
    data manipulation more efficient at the database level.
  • In a logical model, a product’s price might be represented as a simple
    number, but in the physical model, it could be stored as an integer in cents
    to avoid floating-point precision issues. For example, $10.99 would be
    stored as 1099.
  • A logical model could represent a user’s address as one entity, while the
    physical model might normalize it into separate tables for addresses,
    cities, states, and countries to reduce data redundancy. This allows for
    more efficient storage and easier updates of shared information.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Reason how Python’s flexibility with data types can impact the design of algorithms
and functions. Provide an example where this flexibility can lead to errors or
inefficiencies.

A

-Python’s dynamic typing allows variables to hold different types of data, which
can make code more versatile but also requires careful consideration in algorithm
design.

  • Possible Examples:
  • A function designed to calculate the average of numbers might
    accidentally include a string in the input list, causing a TypeError when
    attempting to perform arithmetic operations. For instance, calculating the
    average of [1, 2, ‘3’, 4] would raise an error because ‘3’ is a string, not a
    number.
  • A sorting algorithm might behave unexpectedly when given a list
    containing both numbers and strings, as Python’s default sorting
    compares strings lexicographically. This could lead to counterintuitive
    results, such as [1, 2, 10, 20] being sorted as [1, 10, 2, 20] if the numbers
    were initially stored as strings.
  • A function that concatenates user input might work fine with strings but fail
    if given a number, requiring explicit type conversion. For example, “Hello”
    + 5 would raise a TypeError, while “Hello” + str(5) would work as expected.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a Python function that accepts a number and prints the square of all numbers
from 1 to that number.
Input: 4
Output:
1
4
9
16

A

def print_squares(n):
for i in range(1, n+1):
print (i*i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a Python function that accepts a number and prints the square of all numbers
from 1 to that number.
Input: 4
Output:
1
4
9
16

A

def is_palindrome(ans):
num = str(ans)
return num == num[:: -1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly