Self-assessment quiz

Presentation & objectives

The following quizzes are here to help you check that you understood the articles you had to study. At the end of a quiz, you will be given explanations on your answers. If some of them are wrong, you will have the possibility to click on the question you failed to try again.

These quizzes are provided for self-assessment and will not be graded or stored.

Don’t hesitate to reach out on the Discord server for any precision/explanation!

Quizzes

What is an algorithm?

# What sentence best describes an algorithm? 1. [x] A solution to a specific problem that takes input values and produces a result value > ✅ This is the core definition of an algorithm: it takes inputs and processes them to generate an output solution for a problem. 1. [ ] A sequence of algorithmic statements applied to input data > ❌ This option is incorrect because it only focuses on the mechanical steps of an algorithm without considering the problem-solving nature. 1. [ ] A way to compare different solutions to a problem > ❌ Algorithms are not comparison tools but can be compared based on their performance. 1. [ ] A set of instructions to create a cake > ❌ While it describes a process, the context is unrelated to algorithmic problem solving. # How can algorithms be compared? - [x] By their complexity > ✅ Complexity determines how an algorithm scales with input size, impacting performance. - [x] By the time they take to produce the output value > ✅ Time complexity is a key factor in algorithm efficiency. - [x] By the memory space they require during processing > ✅ Memory or space complexity measures how much memory is used during execution. - [x] By their use of randomness > ✅ Some algorithms, like randomized algorithms, rely on randomness to solve problems. # What is a pseudo-code? - [x] A syntax restricted to algorithmic statements > ✅ Pseudo-code simplifies the presentation of algorithms by focusing on logic rather than syntax. - [x] A less rigorous form of formal programming languages > ✅ Pseudo-code doesn't require strict programming language rules, making it accessible for explanations. - [x] A way to quickly write algorithms without focusing on programming language details > ✅ It allows algorithm representation without worrying about language-specific details. - [x] A mathematical formulation of an algorithm > ✅ Pseudo-code often uses mathematical notation to outline the logic behind an algorithm. # What are the advantages of using standard functions in programming languages? - [x] It saves time > ✅ Standard functions are pre-built, so programmers don't need to reinvent the wheel. - [x] It provides optimized and efficient solutions > ✅ These functions are optimized by experts and often tested extensively. - [ ] It increases the size of the code > ❌ This is incorrect as using standard functions generally reduces the code size. - [ ] It reduces the memory space required > ❌ Standard functions are optimized but may not always minimize memory usage depending on the scenario.

What is a variable?

# What sentence best describes what a variable is? 1. [x] A value representing a name > ✅ A variable is a symbolic name associated with a value in programming. 1. [ ] A memory address > ❌ Variables can refer to values stored in memory, but they are not the address themselves. 1. [ ] An assignment operator > ❌ This option confuses the role of variables with operators used to assign values to them. 1. [ ] A dynamically typed language > ❌ This refers to a property of some programming languages, not a variable. # Which of the following are basic types in Python? - [ ] Array > ❌ Arrays are collections of elements, not basic types. - [x] Integer > ✅ Integer is a fundamental data type representing whole numbers. - [x] String > ✅ Strings are basic data types used to represent sequences of characters. - [x] Float > ✅ Floats represent real numbers with decimal points, making them a basic type. - [x] Character > ✅ Characters represent individual letters or symbols and are a fundamental data type. - [x] Boolean > ✅ Booleans represent true or false values, a basic type in many programming languages. - [ ] Function > ❌ Functions are not basic types; they are blocks of code that perform actions. - [ ] Program > ❌ Programs are collections of functions and logic, not basic data types. # What propositions are true regarding variables in Python? - [ ] Their type is determined at compile time > ❌ Python is a dynamically typed language, meaning type checking is done at runtime. - [x] Their type is determined at runtime > ✅ Python's dynamic typing determines the type of a variable when it is assigned a value. - [ ] Their type needs to be explicitly declared > ❌ Python does not require explicit type declarations. - [x] Declaring their type is optional > ✅ Python infers types automatically, making explicit declarations optional. # How do you assign a value to a variable in Python? - [x] `variable = value` > ✅ This is the correct syntax to assign values to variables in Python. - [ ] `variable == value` > ❌ This is used for comparison, not assignment. - [ ] `value <- variable` > ❌ This is not valid Python syntax. - [ ] `variable := value` > ❌ This is not valid Python syntax. - [ ] `value = variable` > ❌ This is in the wrong order. # In Python (and Java), what is the first index of an array? 1. [x] 0 > ✅ Both Python and Java use zero-based indexing, meaning the first element is at index 0. 1. [ ] 1 > ❌ One-based indexing is not used in Python or Java. # What is the negation of the following proposition? I like the seaside (proposition $S$) and meeting cool people (proposition $C$), formalized as $S \wedge C$. - [x] $\neg(S \wedge C)$ > ✅ This is the direct negation of the whole proposition. - [x] $\neg S \vee \neg C$ > ✅ This is De Morgan's law, which states the negation of a conjunction is the disjunction of the negations. - [ ] $\neg(S \vee C)$ > ❌ This negates a disjunction, which is incorrect here. - [ ] $\neg S \wedge \neg C$ > ❌ This is incorrect as it implies both negations must be true simultaneously.

Algorithmic statements

# What sentence best describes a statement? 1. [x] A basic instruction that can be executed by a computer > ✅ A statement is the smallest executable unit in a program, such as a command. 1. [ ] A mathematical formula > ❌ While some statements involve mathematics, not all do. 1. [ ] A logical proposition > ❌ Logical propositions are often evaluated by statements but aren't statements themselves. 1. [ ] A function > ❌ A function is a block of code, which may contain multiple statements. # When does a loop invariant need to be true? - [x] Before entering the iteration > ✅ The invariant must hold true before the iteration starts. - [x] After each round of the iteration > ✅ It must remain true after each iteration. - [x] At the end of the iteration > ✅ The invariant holds true when the iteration completes. - [ ] Only before the first round of the iteration > ❌ Invariants must hold before, during, and after the iteration, not just initially. # What is true for a loop? - [x] It is a way to repeat a block of code > ✅ Loops execute a block of code multiple times based on a condition. - [ ] It is a way to execute a block of code only once > ❌ This would describe a simple statement, not a loop. - [ ] It is a way to execute a block of code in parallel > ❌ Loops are sequential, not parallel. - [ ] It can only be used with arrays > ❌ Loops can operate on various data structures, not just arrays. - [ ] It is always unbounded > ❌ `for` loops are bounded, and some `while` loops can be. - [x] It can run infinitely in some cases > ✅ If improperly coded, loops can become infinite if their exit conditions are never met. # What is the order of the values of list *l* if the following iteration is applied? ```python from typing import List l = [5, 4, 8, 9, 0, -5, 1, 3] i = 1 j = 0 while i < len(l) - 1: if l[i] < l[len(l) - 1]: l[j] += l[i] l[i] = l[j] - l[i] l[j] = l[j] - l[i] j += 1 i += 1 l[j] += l[len(l) - 1] l[len(l) - 1] = l[j] - l[len(l) - 1] l[j] = l[j] - l[len(l) - 1] ``` 1. 0 2. -5 3. 1 4. 3 5. 5 6. 4 7. 8 8. 9