Download presentation

Presentation is loading. Please wait.

Published byAubrey Golden Modified over 2 years ago

1
CS 345 Ch 4. Algorithmic Methods Spring, 2015

2
Misconceptions about CS Computer Science is the study of Computers. “Computer Science is no more about computers than astronomy is about telescopes, biology is about microscopes, or chemistry is about beakers and test tubes. Science is not about tools. It is about how we use them and what we find out when we do.” Michael Fellows and Ian Parberry in Computing Research News

3
Computer Science is the study of the uses and applications of computers and software. Learning to use a software package is no more a part of computer science than driver education is a branch of automotive engineering. A wide range of people use computer software, but it is the computer scientist who is responsible for specifying, designing, building, and testing software packages and the computer systems on which they run.

4
Computer Science is the study of how to write computer programs In computer science, it is not only the construction of a high-quality program that is important but also the methods it embodies, the services it provides, and the results it produces. One can become so enmeshed in writing code and getting it to run that one forgets a program is only a means to an end, not an end in itself.

5
A Definition of CS Computer Science is the study of algorithms, including their 1. Formal and mathematical properties 2. Hardware realizations 3. Linguistic realizations 4. Applications Norman E. Gibbs and Allen B. Tucker, “A Model Curriculum for a Liberal Arts Degree in Computer Science,” Communications of the ACM, 29(3), (1986): 204.

6
Algorithm Derived from the name of a Persian Mathematician: Mohammed ibn Musa al Khowarizmi. (c. 825 A.D.) A procedure for solving a mathematical problem in a finite number of steps that frequently involves repetition of an operation; broadly: a step-by-step method for accomplishing some task

7
Expressing Algorithm Pseudocode –Is there a “standard” pseudocode? Flowchart:

8
Traversing a Data Structure Many times a problem can be represented by some data structure, and the solution to the problem is found by traversing the data structure. Think of finding the maximum or minimum of a list of values.

9
Graphs and Trees A common data structure for representing a problem is a graph. Recall that a tree is just a special type of graph known as a DAG. Graphs have two basic forms of traversals: a breadth-first or a depth-first traversal.

10
BFT’s and DFT’s When a general graph is traversed in a breadth-first or a depth-first manner, the nodes of the graph and the edges of the graph that were traversed form a tree. This tree is called either the Breadth-First Tree (BFT), sometimes the Breadth-First Search Tree, or the Depth-First Tree (DFT), also called the Depth-First Search Tree.

11
Depth-First Tree DFT( Node S ) mark S for each node X adjacent to S that is not marked do visit X DFT( X )

12
Breadth-First Tree BFT( Node S ) mark S put S in a queue while the queue is not empty do remove node W from the queue for each node X adjacent to W that is not marked do mark X visit X put X in the queue

13
AB C D E F

14
Tree Traversals Depth-First –Pre Order –In Order –Post Order Breadth-First –Level Order Data Structures and Space Requirements

15
Some Uses Of Traversals Binary Search Tree and In Order Traversal Expression Tree and –Pre Order: Prefix notation –Post Order: Postfix notation –In Order: Infix notation State Space Search –Examples: Water-Jug problem, 16-Puzzle, and Stack Permutation.

16
Backtracking A very general technique that also traverses a tree. The traversal is a depth-first traversal. Used with problems that deal with a set of solutions or an optimal solution satisfying some constraints. Because it is depth-first, backtracking is often implemented recursively.

17
Backtracking II Solutions often are expressed as an n-tuple, (x 1,…x n ) where x i are from a finite set S i When a node is reached that cannot be part of the solution, the remainder of the branch is pruned: the algorithm backs up to the parent node and is restarted. A similar method that traverses the tree in a breadth-first manner is called Branch and Bound.

18
Examples of Backtracking N-Queens problem Sum of Subset problem Knight’s Tour problem

19
Divide And Conquer Divide and Conquer means to break a problem into two or more parts, solve each part separately, and merge the results together. When can divide-and-conquer be used?

20
Divide and Conquer II Divide and Conquer can be used when: (1)There is a natural way of dividing a problem in parts. (2)There is a natural way of merging solutions to the divided problem. (3)The run-time order of the solution to the problem is (N 2 ) or higher.

21
Examples of Divide and Conquer Bubble Sort of 1,000 elements. Merge Sort Maximum Subsequence Sum

22
Greedy Algorithms Often applies to situations in which the problem can be viewed as a sequence of decisions or choices. Develops an approach in which we chose, at each step, the “most attractive” choice. Advantages: Simple and natural algorithms. Disadvantage: Does not work in every situation.

23
Greedy Properties Greedy algorithms do not work in all cases. It can be very difficult to tell when a greedy approach works. There are two key properties a problem must exhibit Greedy-Choice Property Optimal Substructure Property

24
Greedy Choice Property A globally optimal solution can be arrived at by making a locally optimal choice.

25
Optimal Substructure Property A problem exhibits optimal substructure if an optimal solution to the problem contains within it optimal solutions to subproblems. Example: Single Source Shortest Path

26
Examples of Greedy Method Minimum coin problem –US Coins –Slobovian Coins Knapsack problem –0/1 (integer) version –fractional (continuous) version Lazy Contractor (pp 87-89) Prim’s Alg.

27
Dynamic Programming Overlapping Subproblems –As in Divide-and-Conquer, we want to divide the problem into subproblems. –Pascal’s Triangle and the Binomial Theorem –Divide and Conquer does more work than necessary to solve this problem.

28
Weary Traveler Problem (p. 89) –Rather than a minimum spanning tree (lazy contractor), the weary traveler is looking for a minimum path. –A Greedy Solution does not solve this problem because a Greedy method cannot “look ahead”.

29
Quote from page 91 “Dynamic planning can be thought of as divide-and-conquer taken to the limit: all subproblems are solved in an order of increasing magnitude, and the results are stored in some data structure to facilitate easy solutions to larger ones.”

30
Steps in a Dynamic Solution 1. View the problem in terms of subproblems. 2. Devise a recursive solution. 3. Replace the recursion with a table and compute an optimal solution in a bottom-up fashion.

31
Examples of Dynamic Programming Slobovian Coin Problem 0/1 Knapsack Problem Longest Common Subsequence Problem

32
Memoized Solution A memoized solution is a cross between a dynamic programming solution and a recursive solution. Uses the control structure of recursion, but records the result of each recursive call in an array. This way, each subproblem is calculated only once.

Similar presentations

OK

CS 46101 Section 600 CS 56101 Section 002 Dr. Angela Guercio Spring 2010.

CS 46101 Section 600 CS 56101 Section 002 Dr. Angela Guercio Spring 2010.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on enterprise java beans Ppt on instrument landing system receiver Free ppt on american war of independence Ppt on solar system for class 8th Ppt on review of related literature introduction Free ppt on motions of the earth Mis ppt on nokia phones Ppt on marketing strategy of nokia and samsung Convert pdf to ppt online free without email Ppt on satellite orbit chart