Analysis of Algorithms: Understanding the Efficiency of Iterative and Recursive Algorithms, Study notes of Algorithms and Programming

An overview of the concepts covered in a university course on the analysis of algorithms. The motivation behind the study of algorithms, the difference between programs and algorithms, and the importance of measuring algorithmic running time. It also introduces various techniques for comparing functions, such as upper and lower bounds, and discusses the efficiency of different types of algorithms, including iterative, recursive, brute force, and divide and conquer algorithms. The document also covers various techniques for solving recurrences and provides examples of recursive algorithms, such as merge sort and quick sort.

Typology: Study notes

2019/2020

Uploaded on 11/25/2020

koofers-user-uet
koofers-user-uet 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS483 Midterm Review:
Analysis of Algorithms
General Motivation:
Objective of the course: how to design and analyze algorithms
Algorithms: recipes for solving problems , they are realized
by programs
Programs: sequences of instructions
One alternative: take a program and count the number of instructions
(this may be depend on implementa tion)
We need some measure how to compare them which would be
independent of machine, details and it would depend on the METHOD used
to solve the problem
In general given a program the number of in structions will depend
on input:
- depends of the size of input (number of input elements n)
- depends on particular input
Comparing algorithms/programs
We want to compare algorithms in the same class:
(trying to solve the same problems, without worrying about deta ils
of speed of computer, implementation)
Running time -> Number of instructions as a function of input size n:
Algorithm 1 takes f(n) steps, algorithm 2 takes g(n) steps, we
Want to compare them = > compare functions f, g, for large n
Order of growth of functions:
Definitions of classes of functions
Upper bound, lower bound, tight bound, not tight uppe r (lower) bound
Asymptotic Efficiency
Measuring input size
What is elementary operation
Definition of asymptotic notations
Basic Efficiency classes
Asymptotic running time of some
elementary algorithms (sequential search,
binary search, brute force algorithms,
closest pair, convex hull etc)
(computing summations – see appendix)
Techniques how to compare functions
Facts: polynomials are dominated by higher order terms
To show it from definition choose
c
and
n
o
such that
inequalities hold
Facts:
Facts: exponential functions grow faster then polynomials
Comparing functions using limits (L’Hospital rule):
pf3
pf4

Partial preview of the text

Download Analysis of Algorithms: Understanding the Efficiency of Iterative and Recursive Algorithms and more Study notes Algorithms and Programming in PDF only on Docsity!

CS483 Midterm Review:

Analysis of Algorithms

General Motivation: Objective of the course: how to design and analyze algorithms Algorithms: recipes for solving problems , they are realized by programs Programs: sequences of instructions

One alternative: take a program and count the number of instructions (this may be depend on implementation)

We need some measure how to compare them which would be independent of machine, details and it would depend on the METHOD used to solve the problem

In general given a program the number of instructions will depend on input:

  • depends of the size of input (number of input elements n)
  • depends on particular input

Comparing algorithms/programs

We want to compare algorithms in the same class: (trying to solve the same problems, without worrying about details of speed of computer, implementation)

Running time -> Number of instructions as a function of input size n:

Algorithm 1 takes f(n) steps, algorithm 2 takes g(n) steps, we Want to compare them = > compare functions f, g, for large n

Order of growth of functions:

Definitions of classes of functions Upper bound, lower bound, tight bound, not tight upper (lower) bound

Asymptotic Efficiency

  • Measuring input size
  • What is elementary operation
  • Definition of asymptotic notations
  • Basic Efficiency classes
  • Asymptotic running time of some

elementary algorithms (sequential search,

binary search, brute force algorithms,

closest pair, convex hull etc)

  • (computing summations – see appendix)

Techniques how to compare functions

Facts: polynomials are dominated by higher order terms

To show it from definition choosec andno such that inequalities hold

Facts:Facts:^ exponential functions grow faster then polynomials

Comparing functions using limits (L’Hospital rule):

Worst case running-time

Longest running time on any input Regardless of the input it will takeat mostat most w(n) steps It is the upper bound of the algorithm on any input

Lower bound on the worst-case running time There is some input that the algorithm will perform at leastat least f(n) steps

Worst case result on a particular array Best case result on a particular array If we make statement about the algorithm, it has to be for any input

Design and analysis of algorithms

Types of algorithms: Iterative (multiple loops)

Compute exact running time (bounding summations)

Design and analysis of algorithms

Iterative (multiple loops) Compute exact running time (bounding summations)

Recursive algorithms – partition into smaller sub-problems

To establish the running time, we need to solve the recurrent equations. Techniques for solving recurrences:

  1. Expansion (expand and compute (or bound summations)
  2. Master’s Theorem (for divide and conquer problems)

Examples of recursive algorithms: (Merge Sort, Quick Sort, Binary Search, Selection, Tower of Hanoi etc., number of bits in n’s binary represent.)

Brute force algorithms

  • Selection Sort – worst case running time
  • Bubble Sort – worst case running time
  • Sequential Search, String Matching
  • Closest Pair, Convex Hull problems
  • Exhaustive Search – knapsack, traveling

salesman, assignment problems

Transform and Conquer

  • Pre-sorting
  • AVL trees – properties of AVLtrees

efficiency of insert operation

  • How to do rotations
  • Heaps and heapsort

Median and order statistics

MinMin MaxMax^

worst case (at most) and best casen-

Selection problemSelection problem^ expected average running time randomized partition

Selection problemSelection problem^ average case running time quick sort idea

Heapsort

Implicit data structure (correspondence heap – array) Heap properties

Build HeapBuild Heap

Loose bound upper bound

Tighter bound

HeapifyHeapify

Heap SortHeap Sort (^) extract max, replace root, Heapify(A,1)

Heapsort is

Need to know how these work Does it depend on whether array is sorted or not?