Terms to Know

  • input = instructions you give to a computer
  • output = the information the computer gives to you
  • sequence = several lines of code together
  • key (name) -> value (Sarah)
  • types of variables: Strings, Integers, Float, List, Dictionary

Python Linux Commands

  • pwd = print working directory
  • cd = change directory
  • mkdir = make directory
  • ls = list directory
  • Python syntax print(“”)
  • </ul> Lists, Dictionaries, Iterations
    • index –> position of string in a list
    • Lists & Dictionaries used to collect and store information
    • .append(expression) –> adds to list

Unit 3 Algorithms

  • Algorithm A conceptually generalized solution to a problem that may be later used in the actual world, such as a computer program.

def get_even_numbers(numbers: List[int]) -> List[int]: even_numbers = []

for number in numbers:
    if number % 2 == 0:
        even_numbers.append(number)

return even_numbers
  • Binary The study of encoding and decoding signals to ensure their security. Coding is done using a key that should ideally only be known by the message’s sender and intended receiver.One of the lowest levels of abstraction employs a base-2 numeric system that only uses combinations of the digits zero and one. In boolean logic, a single binary digit can stand in for True (1) or False (0), but many binary digits can be combined to store enormous amounts of data and carry out intricate operations. Computers convert between binary and the real data you need, such as numbers.

def decimal_to_binary(n: int) -> str: binary_digits = []

while n > 0:
    binary_digits.append(n % 2)
    n = n // 2

return "".join(str(d) for d in binary_digits[::-1])
  • Binary Search The study of encoding and decoding signals to ensure their security. Coding is done using a key that should ideally only be known by the message’s sender and intended receiver. It finds the location of a target value within a sorted array by continually halving the search interval. The amount of effort needed to discover an object rises considerably more slowly with Binary Search than with Sequential Search due to its divide-and-conquer strategy.

def binary_search(arr: List[int], target: int) -> int: low = 0 high = len(arr) - 1

while low <= high:
    mid = (low + high) // 2
    
    if target < arr[mid]:
        high = mid - 1  # Narrow the search range to the lower half
    elif target > arr[mid]:
        low = mid + 1  # Narrow the search range to the upper half
    else:
        return mid  # Return the index of the target element
    return -1
  • Boolean Functionof libraries The study of encoding and decoding signals to ensure their security. Coding is done using a key that should ideally only be known by the message’s sender and intended receiver. Any function that is based on AND, OR, and NOT and whose constituent parts fall under the purview of boolean algebra or a function that takes values from a two-element set (often 0 and 1) for both its inputs and the function itself.

def bool_func(x: bool, y: bool) -> bool: if x and not y: return True else: return False

  • Cryptography The study of encoding and decoding signals to ensure their security. Coding is done using a key that should ideally only be known by the message’s sender and intended receiver.

print(‘Plaintext: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG’) print(‘Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD’)

  • Hexadecimal Integers can be positive, negative, or zero and are full numbers, not fractions. A datum of integral data type, or data type that represents a limited subset of the mathematical integers, is what is known as an integer in computer science. Different widths and the ability to include negative values are both options for integral data types.

print(‘FF6699’) FF6699

  • Integers An integer is a whole number that can be positive, negative, or zero and is not a fraction. A data type that represents a limited subset of the mathematical numbers is known as an integer in computer science. Different widths and the presence of negative values are also possible for integral data types.

x = 10 print(x) # prints 10 print(type(x)) # prints <class ‘int’>

y = x + 5 print(y) # prints 15 z = x * y print(z) # prints 150

  • Iterations The repetition of part of an algorithm until a condition is met or for a specified number of times. This is often called a ‘loop’. Recursive functions repeatedly execute themselves as part of their operation. Upon completing all instructions and resetting to the first one iteration has been completed.

numbers = [1, 2, 3, 4, 5] for number in numbers: print(number)

words = [“apple”, “banana”, “cherry”] for word in words: print(word)

  • Libraries A collection of non-volatile data that a program may often access to create new software. They are helpful for storing frequently used functions. When the linker cannot find a procedure elsewhere, it automatically searches libraries for it. Data, documentation, message templates, pre-written code, classes, and values are examples of resources that may be found in libraries.

import math x = math.sqrt(9) print(x) # prints 3.0

y = math.sin(math.pi / 2) print(y) # prints 1.0

import random

data = [1, 2, 3, 4, 5] random.choice(data)

  • Linear/Sequential Search A method that progressively examines each element in the list until the target element is discovered or every element has been examined.

def linear_search(data, target): for i in range(len(data)): if data[i] == target: return i return -1

data = [1, 2, 3, 4, 5] target = 3

index = linear_search(data, target)

if index == -1: print(f”{target} not found in data”) else: print(f”{target} found at index {index}”)

  • Lossless Data Compression When a file is compressed without any loss of quality, all of the original data is still present when the file is decompress. The information has been fully recovered. This method is typically used for text or spreadsheet files where the loss of words or financial information might be problematic. A format for images that offers lossless compression is PNG.

compressed_data = zlib.compress(data) decompressed_data = zlib.decompress(compressed_data) assert data == decompressed_data

  • Metadata Information about other information. Basic information about data is summarized in metadata, which can facilitate identifying and interacting with specific instances of data. It offers details on an item’s content, such as the size and resolution of the images.
Sarah
  • Pseudocode A thorough yet understandable specification of what an algorithm or computer program must accomplish. It might also be used to define a working principle. Instead of being represented in a programming language made for humans, it is done so in a professionally stylized natural language. Normal programming practices continue.

maxValue = 0 FOR each number in list: IF number > maxValue: maxValue = number OUTPUT maxValue

  • Sequencing The process of carrying out each step/action in a particular algorithm in the exact sequence that is specified.

def greet(name): print(“Hello, “ + name + “!”)

x = 5

print(x)

greet(“Mr.Mort”)

print(“Goodbye!”)