Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

CIS 115

Algorithms

al-Khwārizmī

Abū ʿAbdallāh Muḥammad ibn Mūsā al-Khwārizmī

Image Source: Wikipedia

Algorithm

A finite list of specific instructions for carrying out a procedure or solving a problem

Euclid

Image Source: Wikipedia

Euclid's Algorithm (GCD)

  1. Start with 2 numbers, A and B
  2. If either one is zero, the answer is the other number
  3. Subtract the smaller number from the larger number
  4. Repeat steps 2 - 4 until an answer is found

Example: GCD of 1071 & 462

Example: GCD of 1071 & 462

Sorting Algorithms

Insertion Sort

Image Source: Wikipedia

  1. Choose an element from the source
  2. Place it in the correct place in the destination
  3. Repeat until source is emtpy

Bubble Sort

Image Source: Wikipedia

  1. Compare the first two elements
  2. If they are out order, swap them
  3. Move one element over and repeat
  4. When the end is reached, start over
  5. Continue until no more swaps are made

Big O Notation

Image Source: Wikipedia

Big O Notation

Bubble Sort - Worst Case?

Bubble Sort - Worst Case?

Bubble Sort - Worst Case?

Sorting Algorithms

Merge Sort

Image Source: Wikipedia

Merge Sort

  1. Split the items into two halves
  2. Repeat step 1 until each has 1 item
  3. Choose 2 parts and merge them together by choosing the smallest item repeatedly from the front of each part
  4. Continue merging parts together until no more remain

Quicksort

Image Source: Wikipedia

Quicksort

  1. Choose an item from the list as a "pivot"
  2. Put all items less than that item to its left, and put all items greater to its right
  3. Repeat these steps for the items on each side of the pivot.

Sorting Algorithms

Everyday Heuristics

Traveling Salesman Problem

Image Source: Wikipedia

Traveling Salesman Problem: Algorithms

Traveling Salesman Problem: Heuristic

Nearest Neighbor (Greedy Algorithm)

Traveling Salesman Problem

Greedy Solution: 67 miles

Image Source: Wikipedia

Traveling Salesman Problem

Optimal Solution: 62 miles

Image Source: Wikipedia

Traveling Salesman Problem: Heuristic

Nearest Neighbor (Greedy Algorithm) - O(d n)


Time can vary widely based on how the data is presented and sorted

Assignments

Blog 2: Algorithms

There are many important algorithms in Computing Science. In fact, we’re going to learn about many of them later in this class. For now, however, I’d like you to pick an algorithm from Wikipedia’s list of algorithms (https://en.wikipedia.org/wiki/List_of_algorithms) and write about it. Some things you can cover:

Bubble Sort

Image Source: Wikipedia

  1. Compare the first two elements
  2. If they are out order, swap them
  3. Move one element over and repeat
  4. When the end is reached, start over
  5. Repeat these steps as many times as the number of items in the list