1 / 8

Warming up for the 2 nd Term

Warming up for the 2 nd Term. 1. An example - Solving a problem from graph theory 2. A Cryptarithmetic Puzzle Another case study. Problem: constructing a program for drawing a graph using a continuous line. Issues: Which algorithm? How to represent data? Efficient implementation.

thyra
Download Presentation

Warming up for the 2 nd Term

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Warming up for the 2nd Term 1. An example - Solving a problem from graph theory 2. A Cryptarithmetic Puzzle Another case study

  2. Problem: constructing a program for drawing a graph using a continuous line. Issues: • Which algorithm? • How to represent data? • Efficient implementation

  3. Data representation - 2 alternatives 1 use a set of facts edge(a,b). edge(a,c). edge(a,d). edge(b,c). edge(b,d). edge(c,e). edge(c,d). edge(d,e). total_number_of_edges(8). 2 use a list of edges graph([a-b, a-c, a-d, b-c, b-d, c-e, c-d, d-e]). Algorithm – use a simple blind search

  4. Program 1 – using the 1st representation • Very similar to what we did for London tube • Adding a counter to count down how many edges left • draw1( Sol, PartialSol, Counter) draw1(Sol, Sol, 0). % base draw1(Sol, [Y-Z|ParSol], N):- N > 0, (edge(X,Y) ; edge(Y,X)), N1 is N-1, \+ member(X-Y, [Y-Z|ParSol]), \+ member(Y-X, [Y-Z|ParSol]), draw1(Sol, [X-Y,Y-Z|ParSol], N1). % top level draw1(Sol):- total_number_of_edges(N), (edge(X,Y); edge(Y,X)), N1 is N-1, draw2(Sol, [X-Y], N1).

  5. Program 2 – using the 2nd representation • Using delete program (see next slide) • Don’t need membership checking • draw2( EdgesNeedToDraw, Sol ) draw2([X],[X]). % base draw2(G,Sol):- (delete(X-Y, G, T); delete(Y-X, G, T)), Sol = [X-Y,Y-Z|R], draw2(T, [Y-Z|R]). % top level draw2(Sol):- graph(G), draw2(G, Sol).

  6. A useful program for search problems % delete( an_item, a_list, list_after_delete) delete( X, [X|T], T). delete( X, [Y|T], [Y|R]) :- delete( X, T, R ).

  7. How to assign decimal digits to letters, so that the following sum is valid? Assume that we already know that The possible digits set for the letters is {0,1,2,…9}; M must be 1; Two different letters can't be assigned the same digit SEND + MORE -------- MONEY A Cryptarithmetic Puzzle Problem Statement

  8. using c1,c2 and c3 to represent carrieschanging problem to solve 4 equations S E N D D+E = Y+10*C1 M O R E C1+N+R = E+10*C2 + C3 C2 C1 C2+E+O = N+10*C3 ---------------------- C3+S+M = O+10*M M O N E Y

More Related