Algorithms

What is an algorithm?

  • A set of instructions that tell you how to do something step by step
  • In computers, algorithms are also considered a set of instructions or rules that the computer uses to solve a problem or perform a specific task
    • Used in many different areas, such as computer programming, math, science, everyday life
  • Ex. google search engine
    • Uses an algorithm to determine what results to show you based on your query
  • Algorithms can be simple and complex
    • Can be written in various programming languages or represented in various forms
    • Ex. flowcharts or code

Characteristics of an algorithm

Well defined inputs and outputs

  • An algorithm intakes specific inputs and produces well defined outputs
  • The inputs and outputs should be clearly defined and understood to ensure that the algorithm performs the desired task accurately

Clear and unambiguous instructions

  • An algorithm consists of a series of instructions that are clear and precise and unambiguous
  • Each step of the algorithm should be easy to understand and leave no room for interpretation or ambiguity

Finite steps

An algorithm must have a finite number of steps

It should eventually terminate/stop and produce a results, either by:

  • Reaching a solution
  • Indication that no solution is possible

Infinite loop or recursive cycles should be avoided in a good algorithm

Deterministic

An algorithm is deterministic

  • Means that it will produce the same output for the same input every time it is executed
    • Aka the algorithm must be consistent

Meat analogy: decapitation: if it is a good algorithm then each time the cow is decapitated then the head will fall in the basket. If the cow gets decapitated and the head starts floating then there is a problem in your algorithm
Good algorithm = decapitated head will fall in basket
Bad algorithm = decapitated head will start floating (then you fucked up big time)

Well defined computational complexity

  • An algorithms complexity, in terms of time and space requirements, should be well defined and understood
  • It is important to analyze and optimize the algorithms efficiency and resource usage to ensure it can be executed in a reasonable amount of time and with limited resources

Correctness

  • An algorithm must be designed to produce the correct output or result for the given inputs and problem it is intended to solve
  • The correctness of an algorithm can be verified through rigorous testing and verification techniques

Modularity

  • An algorithm can be modular
    • It can be broken down into smaller, manageable steps or sub problems
    • Allows for easier implementation, debugging, and maintenance of the algorithm

Reproducibility

  • An algorithm’s steps and instruction should be well documented and reproducible, allowing for other to understand and reproduce the results

Flexibility

  • An algorithm should be flexible enough to accommodate different input values and variations of the problem it is designed to solve
  • Should be able to handle different cases and adapt accordingly

Components of an algorithm

  1. Instructions:

    • Steps or actions that the algorithm follows to perform a task or solve a problem
    • Each instruction must be clear, prices, and unambiguous to ensure that the algorithm performs correctly
  2. Variables

    • Data values that are used and manipulated by the algorithm as it processes the input and produces the output
    • Variables can represent different types of data
      • Ex. numbers, text, or boolean values
  3. Conditionals

    • Logical statements that evaluate whether a certain condition is true or false
    • Based on the result of of this evaluation, the algorithm can take different paths or perform different instructions
  4. Loops

    • Structures that allow the algorithm to repeat a set of instruction multiple times
    • Either for a fixed number of iterations or until a certain condition is met

Ways of representing algorithm

Natural language
- Most basic and simple way of explaining an algorithm
- Involves pain and simple language steps of an algorithm

Flowchart
- Graphical representation of an algorithm,
- Uses symbols and arrows to show the low of the algorithm, from input of data to the output of data

Programming language
- Formal language used to write computer programs
- Involves writing code using a specific syntax and structure that the computer can understand and execute

Uses of algorithm

Two main functions:

  1. Prioritization algorithm
    • A sorting algorithm used to prioritize tasks after learning from input from users
  2. Association rule of algorithm
    • Uses algorithm to collect data and reveal how items are associated with each other and reveals the relationship between different items in a database

Real world uses of algorithms

Search engines

  • Used to determine search rankings
  • provide relevant search results for users

Social media

  • Used to personalize news feeds
  • recommended content based on user interests and behavior

Financial systems

  • Used to analyze financial data
  • make investment decisions

Medical diagnosis

  • Used to analyze medical data
  • provide diagnoses based on symptoms and other factors

Transportation systems

  • Used to optimize routes
  • schedules for transportation like buses, trains, and planes

E-commerce

  • Used to recommend products to users based on their browsing history and purchase history

Fraud detection

  • Used to analyze transactions
  • detect potential fraudulent activity in banking and other industries

Weather forecasting

  • Used to analyze weather data
  • provide accurate forecasts and warnings

Gaming

  • Used to power game engines
  • Provides realistic physics simulations and other effects

Robotics

  • Used to control and coordinate the movements of robots in industrial and other applications

Algorithmic dilemmas

Human errors

  • Failure to program a fail safe for the robot
    Algorithm may take things too seriously
  • Lack of critical thinking skills
    Potential to reflect the stereotypes and biases of society

Algorithmic bias

Formed when an algorithm develops with a dataset that doesn’t represent the entire population / the dataset used is biased towards certain groups

Algorithmic bias is created from:

  • Human bias
  • Lack of diversity 
  • Lack of conscience
  • Human input leads to bias

Ex. amazon recruitment algorithm in 2018

  • In 2018, it was revealed that amazon was using a ai power recruiting tool that was biased against women
    • This was the result of the algorithm being trained on the resumes of past job applicants, most of whom were men
  • This results in the algorithm learning to prefer male candidates and subsequently proceeded to downgrades resumes that contained words like women or female

the algorithm above was trained on data that was biased towards men, as as a result learned to prefer male candidates over female candidates

The bias was not intentional, but rather a result of the data used to train the algorithm

Black box algorithms

  • An algorithm that provide insight without clarity on how the conclusions were reached from the data input
  • Lacks transparency as you are not enable to understand how it came to be
  • Think of it as a box where you insert an orange and it gives you back an apple. You then input the apple and you get a banana as an output. 

Proper algorithm:

inputprocessoutput
orangeOrange fruit sweet & sour appleapple

Black box algorithm

inputprocessoutput
orange?????????Box of tissues