17
Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora [email protected]

Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora [email protected]

Embed Size (px)

Citation preview

Page 1: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Design and Analysis of Algorithms

4th Semester Computer Engineering

Spring 2015

Conf.dr.ing. Ioana [email protected]

Page 2: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

design algorithms

that are correct

and efficient

Our goal:

Page 3: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

The Need for Correctness

• Much too often, algorithms are designed in an ad-hoc manner and “validated” through testing on a few particular data sets …

Page 4: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Example of a “sorting algorithm”

The algorithm:

A:array[1..n] of integer

for i=1 to n-1 do

if A[i]>A[i+1]

swap(A[i], A[i+1])

The “tests”:

But it does not work for 3, 2, 1, 5, 4 !

5, 1, 2, 7, 6

15, 2, 4, 17,16

Page 5: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

The Need for Correctness

• Much too often, algorithms are designed in an ad-hoc manner and “validated” through testing on a few particular data sets …

• The fact that an algorithm passed a number of tests on certain data sets DOES NOT guarantee that the algorithm is correct

• The fact that an algorithm fails a test on ONE data set proves that it is NOT correct

Page 6: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

The Bubblesort Algorithm

A:array[1..n] of integer

for l:=n downto 1

for i=1 to l-1 do

if A[i]>A[i+1]

swap(A[i], A[i+1])

• How can we know for sure that the algorithm is correct ? (Other than simply believing the programming textbooks ;-))

Page 7: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Analyzing Algorithms

• We need methods and metrics to analyze algorithms for:– Correctness

• Methods for proving correctness

– Efficiency• Time complexity, Asymptotic analysis

Page 8: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Designing Algorithms

• Ok, so you will know (will learn) how to analyze a given algorithm.

• But where do these algorithms come from ?– Clever people already designed a plethora of

solutions (algorithms) for different problems and we find them in textbooks, internet, etc.

– But how will you design solutions for new problems ?

Page 9: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

How to learn algorithms ?

http://www.neatorama.com/twaggies/2010/11/07/no-112-robcorddry/

Page 10: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Prim’s algorithm

Dijkstra’s algorithm

Tarjan’s algorithm

Floyd’s algorithm

Kruskal’s algorithm

Design methods:

• Greedy

• Design by Induction

• Divide and Conquer

• Dynamic Programming

Page 11: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

What about data structures ?

• Fundamental data structures: – Model fundamental data

• lists, queues, graphs

• Special data structures: – Created to optimize a specific (set of)

operation(s) for a specific context• Search trees, balanced trees• Optimal trees• Disjoint sets

Page 12: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Course Goals

• Learn to design algorithms that are correct and efficient– How do we know that:

• an algorithm is correct ? -> correctness proofs• an algorithm is efficient ? -> analysis of algorithms (time

complexity)

– How to design solutions for new problems ?• Learning general techniques for design• Studying a set of well-known algorithms, to serve as examples

of success stories for applying general design techniques

• Become aware that good algorithms are key parts of software engineering practice !

Page 13: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Course Schedule

• Review: Analysis• Proving Correctness of Algorithms. Induction• Design of Algorithms by Induction• Dynamic Programming• Graphs• Data structures: Search Trees, Balanced trees,

Augmented data structures• Great algorithms in real life problems:

– Data compression– Search engines

Page 14: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Textbooks

Page 15: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Course Webpage

All official information related to the Algorithm Design and Analysis classes:

http://bigfoot.cs.upt.ro/~ioana/algo/

Page 16: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Lab Assignments

• Comprise different types of exercises: – Questions - to be solved with pen on paper – Simple implementation problems - implement something that

was described in the course– Algorithm design problems

• This kind of assignments require to: – Describe the proposed algorithm – Analyze your algorithm (prove correctness and efficiency) – Implement the algorithm

– Tool projects • Complex projects containing also a part of algorithm design and

implementation

• They are optional, but: in order to get a 10 for the lab activity, you have to do at least one tool project

Page 17: Design and Analysis of Algorithms 4 th Semester Computer Engineering Spring 2015 Conf.dr.ing. Ioana Sora ioana.sora@cs.upt.ro

Examination and Grading

• Final grade = 2/3 final written exam + 1/3 work during the semester

• Written exam:– Questions and Algorithm design problems (such as these the lab

description above)

• Work during the semester:– Lab assignments– Lab quizzes– Tool project (for 10)

• Optional bonus points: for exceptional activity = doing more than one optional tool project during the semester, you can gain extra-points to the grade of your final written exam