Week 1
Week 1
ALGORITHMS
Course Code : AR212
Credit Hours :3
Prerequisite : AR211
Instructor Information
[Pre-req. AR211
Textbook: Introduction to Algorithms, Thomas Cormen, Charls Leiserson & Ronald Rivest. 3rd Edition,
MIT Press, 2009.
• Example:
• Input: an integer number n
• Output: Is the number prime?
• Example:
• Input: A list of names of people
• Output: The same list sorted alphabetically
Dr. Aryaf Al-Adwan 10
Algorithms
Input Algorithm
Dr. Aryaf Al-Adwan
Output 11
Correct and incorrect algorithms
Analysis
Problem
specification
Design
Algorithm
Implementation
Program
Compilation
Executable
Dr. Aryaf Al-Adwan (solution) 14
Practical Examples
• Electronic Commerce
• The ability of keeping the information (credit card numbers, passwords, bank
statements) private, safe, and secure.
• Algorithms involves encryption/decryption techniques.
• We can identify the Efficiency of an algorithm from its speed (how long does the
algorithm take to produce the result).
• Some problems have unknown efficient solution.
• These problems are called NP-complete problems.
• If we can show that the problem is NP-complete, we can spend our time developing
an efficient algorithm that gives a good, but not the best possible solution.
• Selections
• An instruction that decides which of two possible sequences is
executed
• The decision is based on true/false condition
• Repetitions
• Also known as iteration or loop
• Documentation
• Records what the algorithm does
2. Pseudo code
• Consider now:
• A faster computer A running insertion sort against
• A slower computer B running merge sort
• Both must sort an array of one million numbers
• Suppose
• Computer A execute one billion (109) instructions per second
• Computer B execute ten million (107) instructions per second
• So computer A is 100 times faster than computer B
• Assume that
• c1 = 2 and c2 = 50
• By using algorithm whose running time grows more slowly, Computer B runs 20 times faster than
Computer A
• For ten million numbers
• Insertion sort takes 2.3 days
• Merge sort takes 20 minutes
• There are various ways to classify algorithms, each with its own merits:
1)By implementation
2)By design paradigm
3)By field of study
4)By complexity
• Every field of science has its own problems and needs efficient algorithms.
1. Search Algorithms
2.Sorting Algorithms
3. Graph Algorithms
4.String Algorithms
5.Machine learning Algorithms
6. Cryptography Algorithms
7.And more