Notes

Algorithms

  • A step-by-step procedure for problem-solving.
  • Clear input, operations, and output.
  • Finite and can be represented in various forms (e.g., pseudocode).

Pseudocode

  • Algorithm description using natural language and structured programming.
    • Main language on CSP tests - easy to understand

String Operations

  • Manipulating and processing text or character sequences.
  • Includes concatenation, substring extraction, searching, and replacement.

Palindrome

  • Palindromes are strings that read the same forwards and backward.

Math Algorithms

  • Addition: a + b
  • Subtraction: a - b
  • Multiplication: a * b
  • Division: a / b
  • Modules: a MOD b

Fibonacci Sequence

  • Series of numbers where each is the sum of the two preceding ones.
    • Infinite sequence of integers

Time Complexity

  • Measures algorithm efficiency in terms of time and input size.
  • Common notations: O(1), O(n), O(log n), O(n^2), etc.
  • Helps analyze and optimize algorithm performance.

Homework

# 1. Write Python Code or Psuedo Code that is able to take a string as input and detect if its a palindrome
def is_palindrome(input_string):
    return input_string == input_string[::-1]

input_string = input("Enter a string: ")

if is_palindrome(input_string) == True:
    print(f"{input_string} is a palindrome.")
else:
    print(f"{input_string} is not a palindrome.")
# 2. Create a program that uses at least 1 of the algorithmic concepts covered in this notebook in a real-world application
def binary_search(arr, target):
    left = 0
    right = len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        mid_value = arr[mid
        if mid_value == target:
            return mid
        elif mid_value < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

arr = [1, 3, 5, 7, 9, 11, 13]
target = 1
result = binary_search(arr, target)
if result != -1:
    print(f"Element {target} found at index {result}")
else:
    print(f"Element {target} not found in the array")