Programming concepts Flashcards

(52 cards)

1
Q

What is data normalization?

A

Data normalization in programming is the process of organizing and structuring data within a database to reduce redundancy, eliminate anomalies, and enhance overall data integrity.

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

What are main objectives of data normalization?

A

The main objectives of data normalization are:
- Reduce data redundancy and improve data integrity.
- Eliminate undesirable insertion, update, and deletion dependencies.
- Make the database more informative and adaptable to changes.
- Enhance the efficiency of data storage and retrieval.

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

What are benefits of data normalization? (4)

A
  1. Improved data consistency and accuracy.
  2. Reduced data redundancy and storage requirements.
  3. Easier data maintenance and updates5.
  4. Enhanced query performance and data analysis capabilities3.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 normal forms in data normalization?

A

First Normal Form (1NF)
- Ensures that each column contains atomic (indivisible) values.
Eliminates repeating groups and ensures each row is unique2.

Second Normal Form (2NF)
- Builds on 1NF by ensuring all non-key attributes are fully dependent on the primary key.
- Requires the creation of separate tables for subsets of data that apply to multiple rows.

Third Normal Form (3NF)
- Eliminates transitive dependencies between non-key attributes.

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

What are the 5 kind of relationships in databases?

A

One-to-One (1:1) Relationship
One-to-Many (1:M) Relationship
Many-to-One (M:1) Relationship
Many-to-Many (M:M) Relationship
Self-Referencing (Recursive) Relationship

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

One-to-One (1:1) Relationship

A

Definition: In this relationship, each record in one table is associated with exactly one record in another table.

Example: A person has one passport. Each passport is assigned to exactly one person.

Use Case: This relationship is used when one entity is closely linked to another, and both share a unique identifier.

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

One-to-Many (1:M) Relationship

A

Definition: In a one-to-many relationship, a single record in one table can be associated with multiple records in another table, but each record in the second table is associated with only one record in the first table.

Example: A department can have many employees, but each employee belongs to only one department.

Use Case: This is the most common type of relationship. It is typically used to represent parent-child relationships between entities.

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

Many-to-One (M:1) Relationship

A

Definition: This is essentially the reverse of the one-to-many relationship. Many records in one table can be linked to a single record in another table.

Example: Many employees work in one department. Here, each employee belongs to one department, but a department can have many employees.

Use Case: This is used when multiple entities point to a single entity.

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

Many-to-Many (M:M) Relationship

A

Definition: In this relationship, many records in one table can be related to many records in another table. This is often implemented using a junction (or associative) table that holds the foreign keys of both related tables.

Example: A student can enroll in many courses, and a course can have many students.

Use Case: This relationship is used when entities are mutually related and both sides can have multiple associations.

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

Self-Referencing (Recursive) Relationship (in databases)

A

Definition: This is when a table has a relationship with itself. This can represent hierarchical or recursive relationships within the same table.

Example: An employee manages other employees. The “employees” table would have a “manager_id” column that references the same table.

Use Case: Used for hierarchical structures or when an entity has relationships with other instances of the same entity (e.g., an organizational structure).

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

What is A/B testing?

A

A/B testing is a method of comparing two versions of a webpage, app, or other variable to determine which one performs better. It involves randomly showing different variants to users and using statistical analysis to measure which version achieves better results for specific conversion goals.

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

Why would you use generators instead of list/arrays in Python/JS? (3)

A
  1. Memory Efficiency
  2. Working with a big files
  3. Creating Infinite Sequences
  4. Generators are substantially more memory efficient than lists or arrays because they generate values on-the-fly rather than storing the entire sequence in memory at once.
  5. Generators employ lazy evaluation, computing values only when requested through iteration
  6. def infinite_counter():
    i = 0
    while True:
    yield i
    i += 1

4.

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

What does the ‘S’ in SOLID stand for?

A

Single Responsibility Principle

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

What is the main idea of the Single Responsibility Principle?

A

A class should have only one reason to change

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

How does the Single Responsibility Principle improve code?

A

By making classes easier to understand, test, and maintain

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

What is an example of a violation of the Single Responsibility Principle?

A

A class that handles both data processing and logging

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

How can you implement the Single Responsibility Principle in Python?

A

By creating small classes that focus on a single task or responsibility

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

How can you implement the Single Responsibility Principle in React?

A

By using functional components and hooks to separate concerns

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

How does the Single Responsibility Principle relate to design patterns?

A

Many design patterns, like MVC (Model-View-Controller), promote this principle

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

What does the ‘O’ in SOLID stand for?

A

Open/Closed Principle

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

What is the Open/Closed Principle?

A

Software entities should be open for extension but closed for modification

22
Q

How can you apply the Open/Closed Principle in Python?

A

By using abstract base classes or interfaces and extending them

23
Q

What is an example of the Open/Closed Principle in React?

A

Using higher-order components to add functionality without modifying existing components

24
Q

What is a violation of the Open/Closed Principle?

A

Modifying existing classes to add new features instead of extending them

25
How does the Open/Closed Principle relate to design patterns?
Many design patterns, like Strategy and Decorator, support this principle
26
What does the 'L' in SOLID stand for?
Liskov Substitution Principle
27
What is the Liskov Substitution Principle?
The Liskov Substitution Principle (LSP) states that subclasses must be interchangeable with their parent classes without breaking code or altering expected behavior.
28
How can you violate the Liskov Substitution Principle in Python?
By overriding a method in a subclass so it behaves differently than expected
29
How can you violate the Liskov Substitution Principle in React?
By using a component that does not adhere to the expected interface of its parent component
30
What does the 'I' in SOLID stand for?
Interface Segregation Principle
31
What is the Interface Segregation Principle?
Clients should not be forced to depend on interfaces they do not use
32
How can you follow the Interface Segregation Principle in Python?
By creating small, specific interfaces instead of large, general ones
33
What is an example of the Interface Segregation Principle in React?
Creating separate components for different functionalities instead of one large component
34
How can you violate the Interface Segregation Principle in Python?
By creating a large interface that forces clients to implement unnecessary methods
35
How can you violate the Interface Segregation Principle in React?
By creating a single component that handles multiple unrelated functionalities
36
What does the 'D' in SOLID stand for?
Dependency Inversion Principle
37
What is the Dependency Inversion Principle?
High-level modules should not depend on low-level modules; both should depend on abstractions
38
What is an example of Dependency Inversion in Python?
Using interfaces or abstract classes to define dependencies
39
What is an example of Dependency Inversion in React?
Using context providers to manage state instead of directly using state in components
40
What is an example of Dependency Inversion in Angular?
Using dependency injection to provide services to components
41
What is a common anti-pattern that violates the Dependency Inversion Principle?
Tightly coupling high-level and low-level modules
42
Why are SOLID principles important for developers?
They help create code that is maintainable, flexible, and scalable
43
Which SOLID principle helps avoid 'God classes'?
Single Responsibility Principle
44
Which SOLID principle encourages extending functionality without modifying existing code?
Open/Closed Principle
45
Which SOLID principle is most related to inheritance and polymorphism?
Liskov Substitution Principle
46
How does dependency injection relate to SOLID?
It supports the Dependency Inversion Principle by decoupling class dependencies
47
What is a common anti-pattern that violates the Single Responsibility Principle?
A class that handles both data storage and user interface logic
48
What is the main benefit of following SOLID principles in team projects?
It makes codebases easier to understand, modify, and scale collaboratively
49
How it works that when user enters password on registration it is saved as a hash and when he/she log in with this password it knows if the password is correct or no. It should require encoding hash password which means that passwords are readable if we know how they are decoded.
Yes, we are storing hashes of password, but we are not decoding them at any way, we cant take hash and make from them password again. Instead we are taking user password and decoding it to hash, then we compare if this two hashes are the same.
50
What is salt in terms of password auth?
A salt in cryptography is a random piece of data that is added to a password before it is processed by a hashing algorithm.
51
Why unique salt is required when generating password?
A salt’s role isn’t secrecy but uniqueness. Each salt forces attackers to recompute hashes individually, even for identical passwords.
52
Why every user should have unique salt saved to his record in user table? Why no only one the same salt for every password?
If we would use the same salt same password used by two different persons would be written in database as the same hashes. This raises security issues such us easy findings of users with potential easy passwords.