Refining algorithms to make them more robust Flashcards

1
Q

What is the goal of refining algorithms to make them more robust?

A

To write code that anticipates a range of possible inputs

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

What should you consider when refining algorithms for robustness regarding user inputs?

A

Ensure prompts for the user are descriptive and helpful

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

What is one common way to handle errors in programming languages?

A

Using simple exception handling commands.

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

What is a potential issue with forcing users to input certain data types?

A

The program may crash if anything other than the expected data type (e.g.

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

How can you improve user feedback when invalid data is entered?

A

By making the prompt to the user more descriptive and helpful.

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

How can you prevent a program from crashing when invalid data is entered?

A

By using error-catching code

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

What is exception handling in programming?

A

A mechanism where you “try” a line of code

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

Why is it important to check for missing or blank data when refining algorithms?

A

To ensure the program can handle incomplete or absent inputs without crashing or producing incorrect results.

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

What are two ways to make user prompts more effective?

A

1) Make them descriptive and helpful. 2) Ensure they guide the user to enter data of the correct type.

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

What does it mean to “catch” an error in exception handling?

A

It means to intercept an error that occurs during the execution of code and handle it gracefully

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

What is the purpose of the “try” block in exception handling?

A

To execute a block of code that might generate an error

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

What happens if an error occurs in the “try” block and is not caught?

A

The program will crash or terminate unexpectedly.

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

What is the role of the “except” block in exception handling?

A

To specify the code that should run if an error occurs in the “try” block

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

Why is anticipating a range of possible inputs important for robust algorithms?

A

It ensures the program can handle unexpected or invalid inputs without failing or producing incorrect results.

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

What is one example of invalid or erroneous data that algorithms should anticipate?

A

Data of the wrong type (e.g.

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