




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to algorithms and data structures from the perspective of computer science. It covers the concept of an algorithm, its motivation, and examples of algorithms such as euclid's algorithm for finding the greatest common divisor and sequential and binary search algorithms. The document also emphasizes the characteristics of algorithms, including finiteness, definiteness, input, output, and effectiveness.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Solving the problem
Problem’s instance
Problem’s solution
N. Wirth, Algorithms + Data Structures = Programs Prentice-Hall, Englewood Cliffs, NJ 1976
The study of algorithms represents the core of computer science Proving the existence of a solution to problem and investigating the algorithm’s properties
A practitioner’s toolkit of known algorithms Framework for designing and analyzing algorithms for new problems.
Example: gcd Algorithms
Problem: Finding the greatest common divisor (gcd) of two nonnegative, not-both-zero integers, m and n , denoted gcd( m, n )****.
Solution: Several algorithms exist for solving this problem
Euclid’s algorithm: Apply repeatedly the equality gcd( m, n ) = gcd( n, m mod n ) until m mod n is 0. The last value of m is the gcd.
Definition-based algorithm: Start by checking whether t = min{ m, n } divides both m and n : If it does, t is the answer; if not, decrease t by 1 and try again. The last value of t which divides both integers is the gcd.
Middle-school algorithm: Find the prime factors of both m and n , identify all the common factors whose product is the gcd.
Example: Binary Search
Algorithm BinarySearch ( A[0.. n - 1], K )
//Implements a nonrecursive binary search
//Output: An index of the array’s element that is equal to K // or -1 if there is no such element
l ← 0; r ← n - while l ≤ r do m ← ( l + r)/2 if K = A[ m] return m else if K < A[m] r ← m - else l ← m + 1 return -
Finiteness:
terminates after a finite number of steps
Definiteness:
rigorously and unambiguously specified
Input:
valid inputs are clearly specified
Output:
can be proved to produce the correct output given a valid input
Effectiveness:
steps are sufficiently simple and basic.