1 What NOT to do I get sooooo Frustrated! Marking the SAME wrong answer hundreds of times! I will give a list of mistakes which I particularly hate marking.

Slides:



Advertisements
Similar presentations
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Advertisements

Introduction to Algorithms Quicksort
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
CSC1016 Coursework Clarification Derek Mortimer March 2010.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
Greedy Algorithms CIS 606 Spring Greedy Algorithms Similar to dynamic programming. Used for optimization problems. Idea – When we have a choice.
Recursion Credits: Jeff Edmonds, Ping Xuan. MULT(X,Y): If |X| = |Y| = 1 then RETURN XY Break X into a;b and Y into c;d e = MULT(a,c) and f =MULT(b,d)
29-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
CS 206 Introduction to Computer Science II 02 / 25 / 2009 Instructor: Michael Eckmann.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Algorithm Cost Algorithm Complexity. Algorithm Cost.
COMP s1 Computing 2 Complexity
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
A Review of Recursion Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Making a great Project 2 OCR 1994/2360. Analysis This is the key to getting it right. Too many candidates skip through this section. It’s worth 20% of.
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
10/14/ Algorithms1 Algorithms - Ch2 - Sorting.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
CSC 413/513: Intro to Algorithms NP Completeness.
CSC401: Analysis of Algorithms CSC401 – Analysis of Algorithms Chapter Dynamic Programming Objectives: Present the Dynamic Programming paradigm.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Getting Started Introduction to Algorithms Jeff Chastine.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Greedy Algorithms. Surprisingly, many important and practical computational problems can be solved this way. Every two year old knows the greedy algorithm.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
Recursive Back Tracking & Dynamic Programming Lecture 7.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
Recurrences David Kauchak cs161 Summer Administrative Algorithms graded on efficiency! Be specific about the run times (e.g. log bases) Reminder:
Algorithm Design Methods (II) Fall 2003 CSE, POSTECH.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Course Review Fundamental Structures of Computer Science Margaret Reid-Miller 29 April 2004.
Divide-and-Conquer UNC Chapel HillZ. Guo. Divide-and-Conquer It’s a technique instead of an algorithm Recursive in structure – Divide the problem into.
Bahareh Sarrafzadeh 6111 Fall 2009
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
CSE373: Data Structures & Algorithms Lecture 9: Disjoint Sets and the Union-Find ADT Lauren Milne Summer 2015.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Review I. Final exam Date TBD. Don ’ t be late! Open book, open notes No calculators or any electronics Worth 50% of final grade.
Loop Invariants and Binary Search Chapter 4.4, 5.1.
CSC317 1 So far so good, but can we do better? Yes, cheaper by halves... orkbook/cheaperbyhalf.html.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Course Review Fundamental Structures of Computer Science Margaret Reid-Miller 28 April 2005.
Team assignments in CS 322 “Data Structures & Algorithms II” Jey Veerasamy CIS Adjunct Faculty Baker College Online.
Lecture 2 What is a computational problem? What is an instance of a problem? What is an algorithm? How to guarantee that an algorithm is correct? What.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Greedy algorithms: CSC317
Recursion Topic 5.
Communication & Entropy
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Lecture 7 Greedy Algorithms
CS 3343: Analysis of Algorithms
Presentation transcript:

1 What NOT to do I get sooooo Frustrated! Marking the SAME wrong answer hundreds of times! I will give a list of mistakes which I particularly hate marking & for which there is no excuse. If you do any of these things you will get -20% on the question.

2 Think about Algorithms Abstractly Devastated by the midterm Change your thinking now. This course requires completely changing the way you think about algorithms. Though I keep warning people, they tend not to get it until they are

3 Easy algorithmic problems testing whether you get the correct structure of iterative & recursive programs. –Get the structure correct, even if you can’t get the details of the algorithm correct. –Tell me that you know what you need to do and where you get stuck Types of Questions

4 In high school, I hated teachers who marked answers wrong if not done their way. Now I do the same. The method of thinking abstractly is important. 99% of other types of answers are wrong. Types of Questions

5 Did you learn the basics of the algorithms taught in class? Can you trace them? Did you do the homework? Did you read the solution set? Math: summing, recurrence relations,  & , running time

6 Give the exact time complexity (running time). No one gave the correct answer! Do not measure running time using the value of the input. Size = log n = s. n = 2 s. Time = 2n 2 + 3n + 4 = 2·2 2s + 3·2 s + 4.

7 T(n) = T(n / 4) + T(n-5) + 3. Not T(n) = 3 T(n / 4) + T(n-5) + 3. Not Eg(n) = Eg(n / 4) + Eg(n-5) + 3. Give the exact time complexity (running time).

8 T(n) = T(n / 4) + T(n-5) + n + 3. Not T(n) = T(n / 4) + T(n-5) + T(n) + 3. Give the exact time complexity (running time).

9 Typical Loop Invariant If the input consists of an array of objects Each iteration considers the next input item. Loop Invariants are pictures of current state. Not actions Not algorithms

10 Typical Loop Invariant If the input consists of an array of objects We have considered the i th input element. What about elements [1...i]?

11 Typical Loop Invariant If the input consists of an array of objects We have considered input elements [1..i]. So?

12 Typical Loop Invariant If the input consists of an array of objects We have a solution for the prefix consisting of elements [1..i]. plus some additional information

13 Typical Loop Invariant If the output consists of an array of objects I have produced the first i objects.

14 For all major algorithms covered. Learn pre and post conditions. Learn the Loop Invariant Learn how to make progress while maintaining the LI.

15 Trust your friends to solve subinstances. The subinstance given must be smaller and must be an instance to the same problem. Combine solution given by friend to construct your own solution for your instance. Focus on one step. Do not talk of their friends friends friends. Solve small instances on your own. I am obsessed with the Friends - Strong Induction View of Recursion.

16 I am obsessed with the Friends - Strong Induction View of Recursion. For binary trees, make sure that your program works for generic

17 Define pre & post conditions Don't have inputs or outputs that are not explained! Typical Test Answer

18 Typical Test Answer Call recursively on the correct types of input k,num,v

19 Typical Test Answer Call recursively Save the results (or don't bother calling) returning the correct types of output

20 Typical Test Answer Combine solutions given by friends to construct your own solution.

21 Typical Test Answer Return things of the correct types. Not an element In every path through code the root?

22 Typical Test Answer Subinstances need to be smaller. “Size” is size of the tree

23 Typical Test Answer Subinstances need to be smaller. When the instance sufficiently small solve on your own. This does not act as base case because k is not getting smaller

24 Typical Test Answer Subinstances need to be smaller. When the instance sufficiently small solve on your own. Code does not check whether the tree is empty.

25 Typical Test Answer Local variables (other than those holding and combining solutions) are not usually needed. Value of n? Local variables don't change outside of the current stack frame. n = 2 No global variables allowed!

26 Typical Test Answer No global returns. Things returned by your friends do not get returned to your boss unless you do the returning. My friend finds and returns the answer. I drop his answer. And return nothing!

27 Typical Test Answer Loops are rarely used in recursive programs. on the same input getting the same result each time! Returns the root?? Called n times

28 Typical Test Answer Don’t expect your marker to be a compiler!

29 Typical Test Answer Traverse nodes in in-order. Count the nodes. Output the k th one. Reasonable Sounding Alg This is an iterative alg not a recursive alg. Hard to write a recursive program that implements an iterative algorithm. Fine (though asked for recursive)

30 Greedy Algorithms Don’ts What is the loop invariant of any greedy algorithm? We prove that the algorithm's solution is … The algorithm has made some commitments already, but this does not yet constitute a valid solution.

31 Greedy Algorithms Don’ts What the algorithm has done so far is optimal. What does this mean? The “More of the Input” loop invariant does not work. What is the loop invariant of any greedy algorithm?

32 Greedy Algorithms Don’ts “There exists an opt solution consistent with choices made so far.” What is the loop invariant of any greedy algorithm?

33 Greedy Algorithms Don’ts We prove it is consistent, optimal, and valid. Don't say "it" without saying what "it" is. The loop invariant of any greedy algorithm is “There exists an opt solution consistent with choices made so far.” How we prove that this loop invariant is maintained?

34 Greedy Algorithms Don’ts We tell the fairy god mother to change her solution optS LI into optS ours. We must prove optS ours is consistent, optimal, and valid. Great, but what does this mean? The loop invariant of any greedy algorithm is “There exists an opt solution consistent with choices made so far.” How we prove that this loop invariant is maintained?

35 Greedy Algorithms Don’ts The Prover is unable to see the Fairy Godmother's optimal solution. The Prover compares the Fairy Godmother's optimal solution to what the algorithm has done. How do we prove optS ours is consistent?

36 Greedy Algorithms Don’ts By the LI, optS LI is consistent with what the algorithm did in the first i steps. The Prover instructs the Fairy Godmother to change it to optS ours to make it consistent with the i+1 st step without missing up the earlier commitments. How do we prove optS ours is consistent?

37 Greedy Algorithms Don’ts It is true that is important. But it is not what we need here. Show that the steps taken by the algorithm are valid. How do we prove optS ours is valid?

38 Greedy Algorithms Don’ts By the LI, optS LI is valid (ie does not contain conflicts within it.) The Prover instructs the Fairy Godmother to change it to optS ours in a way that provably does not introduce conflicts. How do we prove optS ours is valid?

39 Greedy Algorithms Don’ts It is true that is important. But it is not what we need here. Show that the steps taken by the algorithm are the best choice available. How do we prove optS ours is optimal?

40 Greedy Algorithms Don’ts By the LI, optS LI is optimal (ie there is not a valid solution worth more.) The Prover instructs the Fairy Godmother to change it to optS ours in a way that provably does not decrease its worth. How do we prove optS ours is valid? Good

41 Optimization Problems Don’t mix up the following –What is an instance –What are the objects in an instance –What is a solution –What are the objects in a solution –What is the cost of a solution Greedy algorithm –What does the algorithm do & know –What does the prover do & know –What does the fairy god mother do & know Recursive Backtracking / Dynamic Programming –What does the algorithm do & know –What does the little bird do & know –What does the friend do & know

42 Dynamic Programming don’ts Yes, the code has a basic structure that you should learn. But don’t copy other code verbatim Don’t say if(a i = b j ) (i.e. Longest Common Subsequence) when our problem has not b j

43 Dynamic Programming don’ts When looping over the subinstances be clear what the set of subinstances are which is currently being solved, i.e. which instance is cost(i,j)? If you know that the set of subinstances are the prefixes of the input, i.e., then don’t have a two dimensional table. Table[1..n,1..n]. Don’t loop over i and loop over j if j never gets mentioned again.

44 Dynamic Programming don’ts.When trying all bird answers be clear what the set of bird answers are, which is currently being tried, & what it says about the solution being looked for. When getting help from your friend, be clear what the subinstance is that you are giving him How do you use the current instance and the birds answer to form his subinstance. Don’t simply say cost(i-1,j-1)

45 Dynamic Programming don’ts.Think about what the base cases should be. Don’t make an instances a base cases if they can be solved using the general method. % is used to start a comment. Don’t put it in front of code.

46 End