### Lecture_01_Spring_2023.pdf

1. Lecture 1 1 Design and Analysis of Algorithms Adnan Rashid Adnan Rashid CS-251: Design and Analysis of Algorithms (Spring 2023) Email: adnan.rashid@seecs.edu.pk Web: http://save.seecs.nust.edu.pk/adnanrashid/
2. Outline ▪ Course Objectives ▪ Introduction ▪ Assessment Plan ▪ What is an algorithm? ▪ About us ▪ General Instructions 2 Design and Analysis of Algorithms Adnan Rashid ▪ Algorithm vs Program ▪ Properties of Algorithms
3. Lecture’s Content Introduction to Algorithms (4th Edition) by Thomas H. Cormen et al. Section 1.1 (Page 28 onwards) 3 Design and Analysis of Algorithms Adnan Rashid
4. Objectives of Course Objective 1: Understand the operation, implementation and performance of fundamental algorithms and data structures, and the relative merits and suitability of each for various applications 4 Design and Analysis of Algorithms Adnan Rashid Objective 2: Ability to model and implement efficient software solutions for various application areas using appropriately selected algorithms and data structures Objective 3: Ability to analyze data structures and algorithms, to compare and evaluate them with respect to time and space requirements, in order to make the most appropriate design choices when solving real-world problems
5. Algorithm Definition ▪ An algorithm is a step-by-step procedure for solving a particular problem in a finite amount of time ▪ More generally, an algorithm is any well-defined computational procedure that takes collection of elements as input and produces a collection of elements as output 5 Design and Analysis of Algorithms Adnan Rashid Input X Some mysterious processing Output Y = F(X) ALGORITHM F: X→Y
6. Algorithm: Examples 6 Design and Analysis of Algorithms Adnan Rashid ▪ Repairing a lamp ▪ Matrix multiplication ▪ Calling a friend on the phone ▪ The rules of how to play a game ▪ Directions for driving from A to B ▪ A car repair manual ▪ Human brain project ▪ Internet and communication links (Graphs) ▪ A cooking recipe
7. Algorithm vs Program ▪ A computer program is an instance, or concrete representation, for an algorithm in some programming language ▪ Set of instructions, which the computer follows to solve a problem Problem High Level Language Program Algorithm: A sequence of instructions describing how to do a task 7 Design and Analysis of Algorithms Adnan Rashid
8. Solving Problems 8 Design and Analysis of Algorithms Adnan Rashid When faced with a problem: 1. First clearly define the problem 2. Think of possible solutions 3. Select the one that seems the best under the prevailing circumstances 4. And then apply that solution 5. If the solution works as desired, fine; else go back to Step 2
9. Solving Problems: General Solution-Algorithm 9 Design and Analysis of Algorithms Adnan Rashid ▪ It is quite common to first solve a problem for a particular case ▪ Then for another ▪ And, possibly another ▪ And watch for patterns and trends that emerge ▪ And to use the knowledge from these patterns and trends in coming up with a general solution ▪ And this general solution is called an algorithm
10. One Problem, Many Algorithms 10 Design and Analysis of Algorithms Adnan Rashid Problem ▪ The statement of the problem specifies, in general terms, the desired input/output relationship Algorithm ▪ The algorithm describes a specific computational procedure for achieving input/output relationship ▪ Sorting a sequence of numbers into non-decreasing order Example ▪ Various algorithms e.g., merge sort, quick sort, heap sorts etc. Algorithms
11. Problem Instances 11 Design and Analysis of Algorithms Adnan Rashid ▪ An input sequence is called an instance of a Problem ▪ A problem has many particular instances ▪ An algorithm must work correctly on all instances of the problem it claims to solve ▪ Many interesting problems have infinitely many instances ▪ Since computers are finite, we usually need to limit the number and/or size of possible instances in this case ▪ This restriction doesn’t prevent us from doing analysis in the abstract
12. Properties of Algorithms 12 Design and Analysis of Algorithms Adnan Rashid ▪ It must be composed of an ordered sequence of precise steps ▪ It must have a finite number of well-defined instructions /steps ▪ The execution sequence of instructions should not be ambiguous ▪ It must be correct ▪ It must terminate
13. Syntax and Semantics 13 Design and Analysis of Algorithms Adnan Rashid An algorithm is “correct” if its: ▪ Semantics are correct ▪ Syntax is correct Semantics: ▪ The concept embedded in an algorithm (the soul!) Syntax: ▪ The actual representation of an algorithm (the body!) WARNINGS: 1. An algorithm can be syntactically correct, yet semantically incorrect – dangerous situation! 2. Syntactic correctness is easier to check as compared to semantic correctness
14. Algorithm Summary 14 Design and Analysis of Algorithms Adnan Rashid ▪ Problem Statement ▪ Relationship between the input and output ▪ Algorithm ▪ Procedure to achieve the relationship ▪ Definition ▪ A sequence of steps that transform the input to output ▪ Instance ▪ The input needed to compute solution ▪ Correct Algorithm ▪ For every input it halts with correct output
15. About Us ▪ Instructor ▪ Dr. Adnan Rashid (A-226, Faculty Block, SEECS) ▪ Contact: adnan.rashid@seecs.edu.pk ▪ Telephone: +92 51 9085 2176 ▪ Web: http://save.seecs.nust.edu.pk/adnanrashid/ https://seecs.nust.edu.pk/faculty/adnan-rashid/ 15 Design and Analysis of Algorithms Adnan Rashid
16. Course Updates ▪ Updates (on LMS, Email): ▪ Updates and Discussions (on WhatsApp): https://tinyurl.com/yckj3x52 16 Design and Analysis of Algorithms Adnan Rashid
17. Course Updates 17 Compiler Construction Adnan Rashid ▪ Office Hours: By appointment only (via email) ▪ Code for Course Self Enrollment on LMS: 183750294
18. Class Schedule, LMS and CMS 18 Compiler Construction Adnan Rashid ▪ Consult LMS for ▪ Lecture Notes, Quizzes, Assignments and Labs ▪ Online Feedback Day BESE-12B Thursday 0900-1000 (Lecture Hall–IAEC) Thursday 1000-1100 (Lecture Hall–IAEC) Friday 1000-1100 (CR-20–SMRIMMS) ▪ Consult Qalam for ▪ Attendance and grades
19. Attendance Policy 19 Compiler Construction Adnan Rashid ▪ 75-100% required at the end of semester! ▪ No compensation for attendance! ▪ Attendance will be taken at any moment
20. Textbook 20 Compiler Construction Adnan Rashid ▪ Thomas H. Cormen, Introduction to Algorithms (4th edition) 2022, MIT Press
21. Assessment Plan (Tentative) 21 Compiler Construction Adnan Rashid ▪ 40% Final Exam (Closed Books, Closed Notes, Comprehensive) ▪ 30% Mid Term (Closed Books, Closed Notes, Comprehensive) ▪ 10% Quizzes (Minimum 05, Surprise!) ▪ 10% Project ▪ 10% Assignments (Minimum 03)
22. Homework/Assignment Policy 22 Compiler Construction Adnan Rashid ▪ All homework assignments must be done individually or as directed ▪ May also require uploading a soft-copy on LMS (for plagiarism check) ▪ Cheating ▪ Helping others, getting help, looking up websites for solutions etc. ▪ Late Submissions ▪ Late submission will get a –20% penalty up to one day ▪ -40% penalty up to 2 days (No acceptation after 2 days from deadline)
23. Homework/Assignment Policy 23 Compiler Construction Adnan Rashid ▪ Any deviation from the above rule will be considered cheating and will be subject to the SEECS academic dishonesty policy ▪ Contact instructor at least 03 days before the deadline in case of emergency http://seecs.nust.edu.pk/Internal/downloads/downloads/SE ECS_Plagiarism_Policy_Dec2010_v1.0.pdf
24. Lecture Basics 24 Compiler Construction Adnan Rashid ▪ Classes will mainly involve Slides ▪ Lectures (pdf) will be available on LMS ▪ However, no scribes from the class will be made available ▪ Therefore, take your own notes in the class ▪ For latest/updated slides, download before each use ▪ As I might update/correct slides at any stage
25. Thank you! 25 Design and Analysis of Algorithms Adnan Rashid