Module 6
Algorithms
Outline Chapter 7
Chapter 7 Problem Solving and Algorithms
7.1 How to Solve Problems
Ask Questions
Look for Familiar Things
Divide and Conquer
Algorithms
Computer Problem-Solving Process
Summary of Methodology
Testing the Algorithm
7.2 Algorithms with Simple Variables
An Algorithm with Selection
Algorithms with Repetition
7.3 Composite Variables
Arrays
Records
7.4 Searching Algorithms
Sequential Search
Sequential Search in a Sorted Array
Binary Search
7.5 Sorting
Selection Sort
Bubble Sort
Insertion Sort
7.6 Recursive Algorithms
Subprogram Statements
Recursive Factorial
Recursive Binary Search
Quicksort
7.7 Important Threads
Information Hiding
Abstraction
Naming Things
Testing
Ethical Issues: Open-Source Software
Related FGCU Courses
http://icarus.fgcu.edu:8080/CourseDescriptions/
COP 3530 Data Structures & Algorithms
SE Requirement
Data structure design, implementation, application, and analysis are explored. Abstract data types (ADTs) are introduced and uses of interfaces is emphasized. Topics include stacks, queues, linked lists, and trees. Recursion is revisited, the O notation is introduced, and computational complexity of searching and sorting algorithms are explored.
Prerequisites: COP 3003 and MAD 3107
ISM 2051 Intro Website Development w/DB
Elective
This course prepares students as website developers who can create an attractive, socially, culturally sensitive site containing dynamic components as well as static components using an integrated tool with a database.
Lesson
Day One
Chapter questions review
Algorithm - Unambiguous instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data
An algorithm must be written before any coding in a programming language can be done
Making a peanut butter and jelly sandwich
49e?
Card trick
Country trick
Computing the average of a list of numbers
Finding the min
Searching
What do programmers actually do? video (9:19)
Intro to Algorithms Brilliant course
Plus Delta
Day Two
Paper pieces 23 41 66 20 2 90 9 34 19 40 99
Bubble Sort (two at a time)
Selection Sort (do comparisons to select the lowest number in unsorted sublist and swap it into the end of the sorted sublist)
Insertion (get the next number and do comparisons to see where it should be inserted into sorted sublist / beginning to end)
Merge (divide and conquer)
People sort
Folk dance sorting! (intercultural knowledge!)
Introduction to Efficiency / Big O (more in chapter 18)
(n - 1) + (n - 2) + ... + 1
n(n - 1) / 2
n2 / 2 - n / 2
1,000,000 items = 500,000,000,000 - 500,000
basically n2 / on the order of (ignoring / 2 and - n / 2)
O(n2)
Multiplying two n-digit numbers by a simple algorithm; simple sorting algorithms, such as bubble sort, selection sort and insertion sort
Side note: lattice multiplication
Project Review
CSS
<link rel="stylesheet" type="text/css" href="theme.css">
MUST be in <head>
Run Brackets.
Select File > Extension Manager...
Find “Emmet” extension and click “Install” button
Project Preview
Web site creation
Review storyboard
No spaces in file names
Add links
Overview of GitHub. Basic terminology: git, repository (remote & local), commit, push, pull.
Challenge by choice: Codecademy Learn Git
Create GitHub repository named username.github.io on github.com, initialize with README, in Settings choose to use GitHub Pages
Install / open GitHub Desktop
Clone repository to OneDrive folder
Move contents of website folder into repository
Commit and Push
Any problems with GitHub Desktop, just use github.com to upload / edit.
Algorithms and Complexity (AL)
"Algorithms are fundamental to computer science and software engineering. The real-world performance of any software system depends on: (1) the algorithms chosen and (2) the suitability and efficiency of the various layers of implementation. Good algorithm design is therefore crucial for the performance of all software systems. Moreover, the study of algorithms provides insight into the intrinsic nature of the problem as well as possible solution techniques independent of programming language, programming paradigm, computer hardware, or any other implementation aspect. An important part of computing is the ability to select algorithms appropriate to particular purposes and to apply them, recognizing the possibility that no suitable algorithm may exist. This facility relies on understanding the range of algorithms that address an important set of welldefined problems, recognizing their strengths and weaknesses, and their suitability in particular contexts. Efficiency is a pervasive theme throughout this area. This knowledge area defines the central concepts and skills required to design, implement, and analyze algorithms for solving problems. Algorithms are essential in all advanced areas of computer science: artificial intelligence, databases, distributed computing, graphics, networking, operating systems, programming languages, security, and so on."
Basic Analysis
KA Topics:
Differences among best, expected, and worst case behaviors of an algorithm
Asymptotic analysis of upper and expected complexity bounds
Big O notation: formal definition
Complexity classes, such as constant, logarithmic, linear, quadratic, and exponential
Empirical measurements of performance
Time and space trade-offs in algorithms
KA Learning Outcomes:
Explain what is meant by “best”, “expected”, and “worst” case behavior of an algorithm.
In the context of specific algorithms, identify the characteristics of data and/or other conditions or assumptions that lead to different behaviors. [Assessment]
Determine informally the time and space complexity of simple algorithms. [Usage]
State the formal definition of big O. [Familiarity]
List and contrast standard complexity classes. [Familiarity]
Perform empirical studies to validate hypotheses about runtime stemming from mathematical analysis. Run algorithms on input of various sizes and compare performance. [Assessment]
Give examples that illustrate time-space trade-offs of algorithms. [Familiarity]
Algorithmic Strategies
KA Topics:
Brute-force algorithms
Greedy algorithms
Divide-and-conquer (cross-reference SDF/Algorithms and Design/Problem-solving strategies)
Recursive backtracking
Dynamic Programming
KA Learning Outcomes:
For each of the strategies (brute-force, greedy, divide-and-conquer, recursive backtracking, and dynamic programming), identify a practical example to which it would apply. [Familiarity]
Use a greedy approach to solve an appropriate problem and determine if the greedy rule chosen leads to an optimal solution. [Assessment]
Use a divide-and-conquer algorithm to solve an appropriate problem. [Usage]
Use recursive backtracking to solve a problem such as navigating a maze. [Usage]
Use dynamic programming to solve an appropriate problem. [Usage]
Determine an appropriate algorithmic approach to a problem. [Assessment]
Fundamental Data Structures and Algorithms
KA Topics:
Simple numerical algorithms, such as computing the average of a list of numbers, finding the min, max, and mode in a list, approximating the square root of a number, or finding the greatest common divisor
Sequential and binary search algorithms
Worst case quadratic sorting algorithms (selection, insertion)
Worst or average case O(N log N) sorting algorithms (quicksort, heapsort, mergesort)
Hash tables, including strategies for avoiding and resolving collisions
Binary search trees
Common operations on binary search trees such as select min, max, insert, delete, iterate over tree
Graphs and graph algorithms
Representations of graphs (e.g., adjacency list, adjacency matrix)
Depth- and breadth-first traversals
KA Learning Outcomes:
Implement basic numerical algorithms. [Usage]
Implement simple search algorithms and explain the differences in their time complexities. [Assessment]
Be able to implement common quadratic and O(N log N) sorting algorithms. [Usage]
Describe the implementation of hash tables, including collision avoidance and resolution. [Familiarity]
Discuss the runtime and memory efficiency of principal algorithms for sorting, searching, and hashing. [Familiarity]
Discuss factors other than computational efficiency that influence the choice of algorithms, such as programming time, maintainability, and the use of application-specific patterns in the input data. [Familiarity]
Explain how tree balance affects the efficiency of various binary search tree operations. [Familiarity]
Solve problems using fundamental graph algorithms, including depth-first and breadth-first search. [Usage]
Demonstrate the ability to evaluate algorithms, to select from a range of possible options, to provide justification for that selection, and to implement the algorithm in a particular context. [Assessment]