Data Structures & Programming

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

EECS 311: Chapter 2 Notes Chris Riesbeck EECS Northwestern.
Semantics Static semantics Dynamic semantics attribute grammars
22C:19 Discrete Structures Induction and Recursion Spring 2014 Sukumar Ghosh.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
Reasoning About Code; Hoare Logic, continued
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Bubble sort (LList,n) not_sorted  true; while not_sorted do not_sorted  false; cur  LList.first; while cur.next  NIL do if cur.data> cur.next.data.
Proof Points Key ideas when proving mathematical ideas.
Recursion Rosen 5 th ed., § Recursion Sometimes, defining an object explicitly might be difficult.Sometimes, defining an object explicitly might.
Self-Reference - Induction Cmput Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.
Proof Techniques and Recursion. Proof Techniques Proof by induction –Step 1: Prove the base case –Step 2: Inductive hypothesis, assume theorem is true.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Recursive Algorithms Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Fall 2008 Insertion Sort – review of loop invariants.
Strong Induction, WOP and Invariant Method Leo Cheung.
Introduction to Analysis of Algorithms Prof. Thomas Costello (reorganized by Prof. Karen Daniels)
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Proving correctness. Proof based on loop invariants  an assertion which is satisfied before each iteration of a loop  At termination the loop invariant.
Lecture 4 Discrete Mathematics Harper Langston. Algorithms Algorithm is step-by-step method for performing some action Cost of statements execution –Simple.
Fundamental in Computer Science Recursive algorithms 1.
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.
Chapter 2 - Mathematical Review Functions
1 “Not all recursive solutions are better than iterative solutions…” “… recursion, however, can provide elegantly simple solutions to problems of great.
MATH 224 – Discrete Mathematics
Recursion l Powerful Tool l Useful in simplifying a problem (hides details of a problem) l The ability of a function to call itself l A recursive call.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 13 Recursion Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
Implementation of the Hangman Game in C++
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Mar 3, 2006.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Logical Reasoning:Proof Prove the theorem using the basic axioms of algebra.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Feb 18, 2005.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 6: Recursion Lecturer: Santokh Singh Assignment 1 due tomorrow. Should have started working.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
Foundations II: Data Structures and Algorithms
Types of Proof Lecture 4 Sections 0.4 Wed, Aug 29, 2007.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE
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.
1 Review for Quiz 1. 2 Summations 3 Binomial expansion.
CSCI 125 & 161 Lecture 12 Martin van Bommel. Prime Numbers Prime number is one whose only divisors are the number 1 and itself Therefore, number is prime.
1 Computer Algorithms Tutorial 2 Mathematical Induction Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Identities, Contradictions and Conditional Equations.
ALGORITHMS PROVING ALGORITHMS (PROGRAMS) CORRECT WITH AND WITHOUT INDUCTION.
(Proof By) Induction Recursion
11.7 – Proof by Mathematical Induction
Methods of Proof.
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2012
Direct Proof by Contraposition Direct Proof by Contradiction
More Computational Theory
Use mathematical induction to prove that the formula is true for all natural numbers m. {image} Choose the first step of the proof from the following:
Copyright © Cengage Learning. All rights reserved.
Analysis and design of algorithm
Indirect Proof by Contradiction Direct Proof by Cases
Follow me for a walk through...
CSE 373 Optional Section Led by Yuanwei, Luyi Apr
CSC 172 DATA STRUCTURES.
Recursion as a Problem-Solving Technique
DS.I.1 CSE 373: Data Structures and Algorithms Autumn Quarter 2000
Tutorial Number 8 - Daniel Razavi
Data Structures & Programming
Data Structures & Programming
Data Structures & Programming
Data Structures & Programming
Presentation transcript:

Data Structures & Programming Justification Techniques Golnar Sheikhshab

Simple Justification Techniques Counterexample Proof by contradiction (contra attack) Induction Loop Invariant

Counterexample To show some predicate is not correct

Contra Attack

Induction A very important tool for proving many complexities. Also, the main tool for showing the correctness of recursive algorithms.

Loop invariant Great tool for proving correctness of iterative or even recursive algorithms. loop invariant: x is not equal to any of the first elements of A.

Loop invariant (2) bool solutionExists(int i){ // there is a solution that is consistent with the board so far if (i >=n ) // base case return true; // the board is a complete solution. for (int j=0; j<n; j++){ if (valid(i,j)){ board[i]=j; print_until(i); if (solutionExists(i+1)) return true; } return false; Loop invariant: queens in board[0]....board[i] don't threaten each other.

Reading material Section 4.3 of your textbook