0% found this document useful (0 votes)
2 views

Algorithms_and_Programming_Exercises_Memo

The document provides an answer key for algorithms and programming exercises, covering general theory and Python-focused concepts. It includes definitions, code examples, and explanations of key programming constructs such as loops, conditionals, and data types. The answers address various algorithmic principles and Python-specific implementations, emphasizing the importance of structure and syntax.

Uploaded by

shavhanipopps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Algorithms_and_Programming_Exercises_Memo

The document provides an answer key for algorithms and programming exercises, covering general theory and Python-focused concepts. It includes definitions, code examples, and explanations of key programming constructs such as loops, conditionals, and data types. The answers address various algorithmic principles and Python-specific implementations, emphasizing the importance of structure and syntax.

Uploaded by

shavhanipopps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Answer Key - Algorithms and Programming Exercises

Part 1: General Theory of Algorithms and Programming - Answer Key

1. An algorithm is a step-by-step procedure or formula for solving a problem.


2. b) It should have clear steps and terminate in a finite amount of time
3. Pseudocode is a high-level description of an algorithm that uses plain language and structural conventions of
programming.
4. Compare the numbers pairwise using if-else statements.
5. Input: two numbers; Process: add them; Output: print the result.
6. A compiler translates code all at once into machine code. An interpreter executes code line by line.
7. c) String
8. 2
9. Use modulo operator:
if number % 2 == 0: print("Even") else: print("Odd")
10. range(1, 6)
11. c) Iteration
12. if age >= 18: print("Eligible") else: print("Not eligible")
13. for loops iterate a known number of times; while loops continue as long as a condition is true.
14. Loop from 1 to n and multiply. Example: result = 1; for i in range(1, n+1): result *= i
15. c) Merge Sort

Part 2: Python-Focused Theory and Exercises - Answer Key

1. An algorithm is implemented in Python using code structures such as functions, loops, and conditionals.
2. c) A reusable block of code that performs a task
3. def max_of_three(a, b, c): return max(a, b, c)
4. Indentation defines blocks of code. Missing indentation causes syntax errors.
5. a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(a + b)
6. Output: 1
7. b) value_2
8. name = input("What is your name?") print(f"Hello, {name}!")
9. range(1, 6)
10. = assigns a value; == compares two values. Example: x = 5; if x == 5: print("Yes")
11. Use if-elif-else to check number sign.
12. Output: False; because a and b = True and False
13. for loops for known repetitions; while loops for unknown condition-based repetition.
14. Use loop: result = 1; for i in range(1, n+1): result *= i
15. c) Timsort (used by sorted())

You might also like