CSE101: Design and Analysis of Algorithms Ragesh Jaiswal, CSE, UCSD - - PowerPoint PPT Presentation

cse101 design and analysis of algorithms
SMART_READER_LITE
LIVE PREVIEW

CSE101: Design and Analysis of Algorithms Ragesh Jaiswal, CSE, UCSD - - PowerPoint PPT Presentation

CSE101: Design and Analysis of Algorithms Ragesh Jaiswal, CSE, UCSD Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms Administrative Information Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms


slide-1
SLIDE 1

CSE101: Design and Analysis of Algorithms

Ragesh Jaiswal, CSE, UCSD

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-2
SLIDE 2

Administrative Information

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-3
SLIDE 3

Administrative Information

Course Instructor:

Ragesh Jaiswal Office: 3130, CSE Email: rajaiswal@ucsd.edu

Course webpage:

http://www.cs.ucsd.edu/~rajaiswal/Winter2020/cse101/. The discussion sections will be held this week. We will recap. material from the previous courses that will be used in this course. The first lecture is being conducted by Prof. Russell Impagliazzo. The detailed administrative information will be discussed in the second lecture by the course instructor.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-4
SLIDE 4
  • Recap. of Data Structures and Algorithms

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-5
SLIDE 5

Recap.

What is an algorithm?

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-6
SLIDE 6

Recap.

What is an algorithm?

A step-by-step way of solving a problem.

How do we measure the performance of an algorithm?

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-7
SLIDE 7

Recap.

What is an algorithm?

A step-by-step way of solving a problem.

How do we measure the performance of an algorithm? Main ideas for performance measurement:

Worst-case analysis: Largest possible running time over all input instances of a given size n and then see how this function scales with n. Asymptotic order of growth: The worst-case running time for large n (e.g., T(n) = 5n3 + 3n2 + 2n + 10)

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-8
SLIDE 8

Recap.

What is an algorithm?

A step-by-step way of solving a problem.

How do we measure the performance of an algorithm? Main ideas for performance measurement:

Worst-case analysis: Largest possible running time over all input instances of a given size n and then see how this function scales with n. Asymptotic order of growth: The worst-case running time for large n (e.g., T(n) = 5n3 + 3n2 + 2n + 10) Figure: Plot of n2 and 2n + 2

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-9
SLIDE 9

Recap.

What is an algorithm?

A step-by-step way of solving a problem.

How do we measure the performance of an algorithm? Main ideas for performance measurement:

Worst-case analysis: Largest possible running time over all input instances of a given size n and then see how this function scales with n. Asymptotic order of growth: The worst-case running time for large n (e.g., T(n) = 5n3 + 3n2 + 2n + 10)

Asymptotic order of growth (O, Ω, Θ):

T(n) is O(f (n)) (or T(n) = O(f (n))) iff there exists constants c > 0, n0 ≥ 0 such that for all n ≥ n0, we have T(n) ≤ c ·f (n).

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-10
SLIDE 10

Recap.

Growth rates:

Arrange the following functions in ascending order of growth rate:

n 2

√log n

nlog n 2log n n/ log n nn

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-11
SLIDE 11

Introduction

Algorithm: A step-by-step way of solving a problem. Design of Algorithms:

“Algorithm is more of an art than science” However, we will learn some basic tools and techniques that have evolved over time. These tools and techniques enable you to effectively design and analyse algorithms.

Analysis of Algorithms:

Proof of correctness: An argument that the algorithm works correctly for all inputs. Analysis of worst-case running time as a function of the input size.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-12
SLIDE 12

Introduction

Algorithm: A step-by-step way of solving a problem. Design of Algorithms:

“Algorithm is more of an art than science” However, we will learn some basic tools and techniques that have evolved over time. These tools and techniques enable you to effectively design and analyse algorithms.

Analysis of Algorithms:

Proof of correctness: An argument that the algorithm works correctly for all inputs.

Proof: A valid argument that establishes the truth of a mathematical statement.

Analysis of worst-case running time as a function of the input size.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-13
SLIDE 13

Introduction

Proof: A valid argument that establishes the truth of a mathematical statement.

The statements used in a proof can include axioms, definitions, the premises, if any, of the theorem, and previously proven theorems and uses rules of inference to draw conclusions.

A proof technique very commonly used when proving correctness of Algorithms is Mathematical Induction. Definition (Strong Induction) To prove that P(n) is true for all positive integers, where P(n) is a propositional function, we complete two steps: Basis step: We show that P(1) is true. Inductive step: We show that for all k, if P(1), P(2), ..., P(k) are true, then P(k + 1) is true.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-14
SLIDE 14

Introduction

Definition (Strong Induction) To prove that P(n) is true for all positive integers, where P(n) is a propositional function, we complete two steps: Basis step: We show that P(1) is true. Inductive step: We show that for all k, if P(1), P(2), ..., P(k) are true, then P(k + 1) is true. Question: Show that for all n > 0, 1 + 3 + ... + (2n − 1) = n2.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-15
SLIDE 15

Introduction

Question: Show that for all n > 0, 1 + 3 + ... + (2n − 1) = n2. Proof Let P(n) be the proposition that 1 + 3 + 5 + ... + (2n − 1) equals n2. Basis step: P(1) is true since the summation consists of only a single term 1 and 12 = 1. Inductive step: Assume that P(1), P(2), ..., P(k) are true for any arbitrary integer k. Then we have: 1 + 3 + ... + (2(k + 1) − 1) = 1 + 3 + ... + (2k − 1) + (2k + 1) = k2 + 2k + 1 (since P(k) is true) = (k + 1)2 This shows that P(k + 1) is true. Using the principle of Induction, we conclude that P(n) is true for all n > 0.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-16
SLIDE 16

Introduction

Algorithm: A step-by-step way of solving a problem. Design of Algorithms:

“Algorithm is more of an art than science” However, we will learn some basic tools and techniques that have evolved over time. These tools and techniques enable you to effectively design and analyse algorithms.

Analysis of Algorithms:

Proof of correctness: An argument that the algorithm works correctly for all inputs.

Proof: A valid argument that establishes the truth of a mathematical statement.

Analysis of worst-case running time as a function of the input size.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-17
SLIDE 17

Introduction

Algorithm Design Techniques

Divide and Conquer Greedy Algorithms Dynamic Programming Network Flows

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-18
SLIDE 18

Introduction

Material that will be covered in the course:

Basic graph algorithms Algorithm Design Techniques

Divide and Conquer Greedy Algorithms Dynamic Programming Network Flows

Computational intractability

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-19
SLIDE 19

Introduction

Divide and Conquer

Some examples of Divide and Conquer Algorithms:

Binary Search Median finding Multiplying numbers Merge sort, quick sort.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-20
SLIDE 20

Introduction

Greedy Algorithms

Problem Interval scheduling: You have a lecture room and you get n requests for scheduling lectures. Each request has a start time and an end time. The goal is to maximise the number of lectures.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-21
SLIDE 21

Introduction

Dynamic Programming

Problem Interval scheduling: You have a lecture room and you get n requests for scheduling lectures. Each request has a start time, an end time, and a price (that you will get in case the lecture is scheduled). The goal is to maximise your earnings.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-22
SLIDE 22

Introduction

Network Flows

Problem Job assignment: There are n people and n jobs. Each person has a list of jobs he/she could possibly do. Find a job assignment so that:

1 each job is assigned to a different person, and 2 each person is assigned a job from his/her list.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-23
SLIDE 23

Introduction

Computational Intractability

Is it always possible to find a fast algorithm for any problem? Problem Given a social network, find the largest subset of people such that no two people in the subset are friends.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-24
SLIDE 24

Introduction

Computational Intractability

The problem in the previous slide is called the Independent Set problem and no one knows if it can be solved in polynomial time (quickly). There is a whole class of problems to which Independent Set belongs. If you solve one problem in this class quickly, then you can solve all the problems in this class quickly. You can also win a million dollars!! We will see techniques of how to show that a new problem belongs to this class:

Why: because then you can say to your boss that the new problem belongs to the difficult class of problems and even the most brilliant people in the world have not been able to solve the problem so do not expect me to do it. Also, if I can solve the problem there is no reason for me to work for you!

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

slide-25
SLIDE 25

End

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms