Solving Minesweeper Using CSP
|
|
- Ezra Preston
- 5 years ago
- Views:
Transcription
1 Solving Minesweeper Using CSP AI Course Final Project Gil & Chai
2 Usage (After using Makefile) java player/aiplayer <height> <width> <#mines> <method> <flag: trivial> <flag: subtract> <flag: sectors> <flag: gui> <flag: sleep> <optional: trivial-sleep> <optional: backtracking-sleep> <optional: guesssleep> <height> and <width> are the dimensions of the board (must be positive). <#mines> is the number of mines on board (between 0 and height*width). <method> is the method for selecting the variable in the backtracking algorithm (see explanation in the backtracking algorithm part). 1=random, 2=least-constrained, 3=most-constrained, 4=smallest-constraint, 5=biggest-constraint. the trivial, subtract and sectors flags are optional algorithms that should increase the efficiency of the program (explanations will follow). enter 1 for 'true' or 0 for 'false'. <flag: gui>: enter 1 ('true') unless you want to measure performance time, etc. <flag: sleep>: enter 1 to enter some sleep values, in order to see the progress of the game.
3 the rest are the sleep values. Recommended values: (when making a guess, the program will hold for 600 milliseconds). Output: output to stdout: <flag: won> <time> <trivialcounter> <sutractcounter> <backtrackcounter> <guesscounter> <crapshotcounter> <flag:won> is 1 if the game has been won, and 0 otherwise. <time> is the running time of the program, in seconds. the next values are counters: how many times in this game we have used the trivial algorithm, the subtracting operation, the backtracking algorithm, how many times we've made an educated guess and how many times we have made a crap shot (explanations will follow), respectively. The Minesweeper Game Minesweeper is a simple computer game. It has many graphical versions and was integrated in some popular operation systems. The game is played on a square-based board. Squares' content is hidden. Each square can either contain a mine or not. The goal: opening all squares that doesn t contain a mine. When opening a hidden square (left mouse click): if the square contains a mine, the game is lost. If the square doesn t contain a mine, a number appears on the square- the number of mines in the
4 squares around it. When it is known that a square contains a mine, it is marked with a flag (right mouse click). A short demonstration on how the game is played suppose we are in the next game state: In this state, there are four 1-squares that has only one hidden square near them. Therefore these squares must be mines (or there will be 1-squares with no mines around them). After we've flagged those 1-squares, we are in this game state. Now, we have five 1-squares near flagged-squares (mines). This means that all other squares near those 1-squares (beside the mines) must be non-mine squares
5 (or the 1-squares would have at least 2 mines around them). After we've opened those squares, we are in this state. notice we've pressed on an "air pocket" - a 0-square. In this case all squares around it are safe and are being opened automatically. now, there are four 2-squares that obligate 4 squares to be mines. We keep using the same considerations and progress in the game.
6 And the game is won. Notice that this was the "beginner level" (of the
7 Microsoft Windows version), that only rarely requires making hard-guesses. Other configurations might give the best player in the world less than 50% chance of success (for example, Microsoft Windows "expert level"). Constraint Satisfaction Problem (CSP) A special search problem. Defined by a set of variables V, their domains D, and a set of constraints on the variables values C. A state is defined by an assignment of values to some or all variables in V, each value from the according domain. A goal state is an assignment of values to all variables in V, which satisfies all constraints in C. Solving Minesweeper Using CSP In order to solve Minesweeper, it is impossible to use regular CSP. The reason is that regular CSP finds one complete and satisfying assignment, while there are more than one assignment possible (i.e., there are multiple goal states). However, only one of these goal states matches the true (and hidden) mine locations, while the other ones will cause a game loss. Another important point is the fact that Minesweeper is dynamic: When a square is opened, assuming it's not a mine a number appears. This number is a new information about the mine locations, and therefore a new constraint. From those reasons we needed a modified, new type of CSP. In our CSP, each game-state is considered one CSP (Thus, we would probably need to solve many CSPs in order to solve a single Minesweeper game. Moreover, we will soon see that we might have several CSPs per one game state). The variables are all hidden squares we have information about, which are all hidden squares adjacent to an open square. Each variable can be assigned 1 (mine) or 0 (safe square). The constraints are originated in the open squares, one constraint for each open square. for an open square with number n on it (0<=n<=8), the constraint would be: [<sum of all unassigned variables around this square> = n]. Comments: 1. Unassigned variables are all hidden and unflagged squares adjacent to an
8 open square. 2. We would use the next form to describe a constraint: [v 1 + v v k = n] for 0 <= n,k <= 8. Example: In this example we have five hidden square which are adjacent to an open square, marked with letters a to e. The CSP for this state would be: V = {a,b,c,d,e} D = {{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}} C = {(a+b=2),(a+b+c+d+e=3),(d+e=1),(e=1)} Modeling The Constraint Class: The constraint object consists of an origin square (Point origin), a list of variables around it (maximal number of variables: 8, Each variable is represented simply by a Point object indicating it s location) and the desired sum of those variables. Main data structure: a hash map with key Point (origin square) and value Constraint. The variables aren t saved in any other data structure, and can be extracted using our hash map. The Algorithm "The Layer Model": Each layer describes an algorithm or some operation, and we try those operations in the given order. Whenever an operation fails, we try the next operation. Whenever an operation succeeds, we try the operations all over again from
9 the beginning. Notice we would never use more than one layer on one CSP. Once we've assigned a value to at least one integer, we try the first layer again for the new CSP we obtained. Finding Trivial Constraints: When a constraint has n variables and it s sum is either 0 or n, it has only one possible assignment and is considered a trivial constraint. In this layer we find all trivial constraints, and open/flag each constraint s variables according to the constraint s sum. Example: In the figure above, (a+b=2) and (e=1) are trivial constraints. Subtracting Constraints: We say that constraint c contains constraint c if each variable in c is also in c. In this layer, we find all pairs of constraints (c,c ) such that c contains c, and subtract the variables in c from the variables in c. Consider the following situation: c has 7 variables and sum 4, c has 5 variables and sum 2. If c contains c, after subtracting c from c, c becomes a trivial constraint! Example: In the figure above, subtracting (a+b+c+d+e=3) from (a+b=2) turns the first constraint into (c+d+e=1). Subtracting (e=1) from (d+e=1) turns the first constraint into (d=1) - a trivial constraint!
10 Backtracking: In this layer we get to the main algorithm we use for solving our CSP. In the backtracking algorithm we find all of the safe moves (unlike the previous layers, where we find only some of them). If we fail here, we re going to have to make a guess in order to progress in the game. The backtracking we use is different than the one we ve seen in class, because we want to find all possible assignments (and not only one). We use a function to assign the variables in a certain order (more about this function soon). The algorithm for finding all possible assignments: assign 0 to the first variable and recursively find all possible assignments for the rest of the variables, assign 1 to the first variable and do the same thing, return the union of the two groups (of assignments) you ve found. For each variable that has the same value in all assignments, assign this value to it. Order of Selecting Variables: Well, in which order should we select the variables? Does it even matter? Unlike classical CSP, we go over all of the solutions. What difference does it make? In the course we ve learned about the least constrained first order, which means: select the variable that has the least constraints on it first. Will it be useful in our CSP? In the time-measures part of this presentation we will see that selecting the least constrained variable first is even worse than selecting a random variable. However, selecting the most constrained variable first gives excellent results, and makes a huge different in the program s running time. When we assign value to the least constrained variable first, we keep most options available. This is good for classical CSP, because we want to find one assignment, and this way we increase the chances for finding it. But in our CSP we go over all of the possible assignments. If an assignment to a variable violates some constraint, it is not a valid assignment and we want to know about this as soon as possible. When we assign value to the most constrained variable first, we increase the chances of finding this violation earlier. Another order of assigning the variables is biggest constraint first : selecting a random variable from the constraint that has (currently) the biggest number of variables. smallest constraint first is defined in a similar way. Surprisingly (in our opinion), both "smallest constraint possible" and "biggest constraint possible" gives good results that are similar to the "most constrained" results - much better than random selection.
11 Out expectations were as follows: "Smallest constraint" will give good results while "Biggest constraint" will give bad ones. The reason: When you select a variable using the "smallest constraint" method, you select it from the smallest constraint - which will definitely be the smallest constraint on the next round (its size decreased by one!). Using this method we try to satisfy constraint by constraint, which will help killing bad assignments while keeping the constraints satisfied. We've expected "Biggest constraint" to give bad results from the same reason - it will never assign a whole constraint; it will always assign to the biggest constraint possible, and will completely assign a constraint only when they all have size 1 - and therefore the biggest constraint too. Why "biggest constraint" gives good results remains a mystery to us. Guessing If we couldn t find any trivial constraints, couldn t find any subtracting possible and couldn t find any safe assignment using backtracking, we have no choice but to take a risk, i.e., make a guess. But we don t have to make a blind guess, we can use the fact that we ve already found all possible assignments in the backtracking layer: In each possible assignment, the variable v gets either one or zero. If we look at the average of the values assigned to it in each assignment, we get the probability that v contains a mine. We find the variable v with the minimal average (denoted as a(v)), and we find the variable v with the maximal a(v ). If a(v) is smaller than 1-a(v ), we assign 0 to v. Else, we assign 1 to v. In other words: we look for the average that is the farthest from ½. By now we have considered only part of the squares on the board. What about all of the squares that aren t adjacent to any open square, and therefore aren t variables yet? We know how many hidden mines are left, but some of them are in the variable-squares and the rest are in the non-variable squares. We know all possible solutions for the variable-squares, so we have a possible range on the number of mines in it. Therefore, we have a possible range on the number of mines in the nonvariable squares. We know the initial number of squares, how many squares are open or flagged, and how many squares are currently variables so we can calculate how many hidden non-variable squares we have left. (#mines / #squares) in the non-variable squares will give as the probability that a random nonvariable square will contain a mine. Because we only have a range for #mines, we will get a range of probabilities.
12 We will take the worst-case probability, i.e., the probability from the range that is the closest to ½. If the probability is farther from ½ than all the probabilities for the variablesquares, we don t assign value to any variable, and we only open/flag a random non-variable square if the probability was smaller/bigger than ½, respectively. (if we open, we get a new constraint). "Crap Shot": When the best guess we could make have exactly probability of ½ to be a mine (and also to be safe), we have to make a guess. This kind of guess is somewhat frequent, so we will use a special term ("crap shot") for it, and give it a special place in the analysis part. After making an assignment of one variable, we make no more guesses, and try all the layers from the beginning (recall: we now have a new CSP!). Measures and Analysis Games Distribution: In this part we have ran a few thousands of games on the three Microsoft- Windows configurations (beginner, intermediate and expert), using some bash scripts. The blue colors are wins, the red colors are losses. "First guess only" is when we win by making a guess only on the first move - which is a necessary guess in every game. "Crap shot" was explained in the "Guessing" part of the algorithm, and "educated guess only" is when winning by making at least one additional guess to the first (and necessary) guess but without any crap shots at all. "loss on first hit" is when losing on the first and necessary guess. Notice: in a perfect measure, "loss on first hit" should be exactly #mines/#squares. The distribution is as follows: Beginner: (9x9 board, 10 mines)
13 Intermediate: (16x16 board, 40 mines)
14 Expert: (16x30 board, 99 mines)
15 Order of Selecting Variables on Backtracking: Here are the results for a comparison between the 5 methods for selecting the variable in the backtracking algorithm. A deep analysis for those results appears in the backtracking algorithm itself. We have ran the game for a fixed mine density of 15%, and checked the performance of each method as the size of the board increases (we ran the game on boards with height=width). We will first show the results in a linear scale, and then in a logarithmic scale on the y axis. Notice: It was difficult to get a large number of results, because we were measuring time, and as a result - we could only compare games that have
16 been won. Some methods made the game run very slow, and we could get only a few results for each board size. This might be the explanation for the big hill around the 60 in the "leased constraint method". Linear Scale: We can see in this scale that the "least constrained" method is (by far) the worst method. We can also see that random selection can be unstable, and sometimes as bad as the least-constrained. Logarithmic Scale:
17 As we can see clearly in this scale, all of the good methods - "most constrained", "biggest constraint", "smallest constraint" are very similar in their performance. Moreover, there is no preferable method for a specific board size - they all give similar results in all board sizes. Success Rate: We have tested the success rate of our program as a function of the mine density, and as a function of the board size. Success Rate as a Function of the Mine density: We have tested this on four different board sizes.
18 The results are interesting: As expected, the success rate is a direct result of the mine density. However, the smaller the board is - the larger is your chance is to "get away" from a large mine density. Our explanation to the phenomenon is that when we have a board of size 2x and a board of size x (the 2x board has 4 times the number of squares in the x board), the mine density in the 4 sub-boards of the 2x board will probably not be even. The sub-board with the highest mine density will more likely to cause a loss. Success Rate as a Function of the Board Size: We have tested this on three different mine densities.
19 Our conclusion from this results is similar to the previous ones: The higher the mine density is, the more important the board size is. Again, large board means lower success rate. Final Conclusions: CSP-Minesweeper Regarding Conclusions: An adjusted CSP was required to solve the minesweeper problem: A new CSP for each game state, finding all solutions instead of one solution. The method for selecting the variable in the backtracking algorithm is very important: a ~1000 factor in the running time. Minesweeper Regarding Conclusions: Making guesses is sometimes inevitable. We try to make the guesses as educated as possible.
20 The chance of winning depends mostly on the mine density, but also on the board size. Minesweeper is fun!
Problem A: Collatz Conjecture
Problem A: Collatz Conjecture The Collatz conjecture which is also known as the 3n + conjecture is a very well known and old conjecture in mathematics. The conjecture is as follows. Take any natural number
More informationCPSC 217 Assignment 3
CPSC 217 Assignment 3 Due: Monday November 23, 2015 at 12:00 noon Weight: 7% Sample Solution Length: 135 lines, including some comments (not including the provided code) Individual Work: All assignments
More informationCOMP 110 Programming Exercise: Simulation of the Game of Craps
COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,
More informationVISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii
More informationThe Dynamic Typing Interlude
CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,
More informationMIT Programming Contest Team Contest 1 Problems 2008
MIT Programming Contest Team Contest 1 Problems 2008 October 5, 2008 1 Edit distance Given a string, an edit script is a set of instructions to turn it into another string. There are four kinds of instructions
More informationAnalysis of Algorithms. 5-Dec-16
Analysis of Algorithms 5-Dec-16 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based on the size of the input (time complexity), and/or developing
More informationMillionaire. Input. Output. Problem limit seconds
Millionaire Congratulations! You were selected to take part in the TV game show Who Wants to Be a Millionaire! Like most people, you are somewhat risk-averse, so you might rather take $250,000 than a 50%
More informationGames and Adversarial Search II Alpha-Beta Pruning (AIMA 5.3)
Games and Adversarial Search II Alpha-Beta Pruning (AIMA 5.) Some slides adapted from Richard Lathrop, USC/ISI, CS 7 Review: The Minimax Rule Idea: Make the best move for MAX assuming that MIN always replies
More informationProject: Minesweeper Online EDA095
Project: Minesweeper Online EDA095 Oscar Axelsson, D11, dat11oax@student.lu.se Elliot Jalgard, D10, ada10eja@student.lu.se Philip Mårtensson, D10, ada10pma@student.lu.se Daniel Olsson, D11, atf10dol@student.lu.se
More informationExcel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller
Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing
More informationAnalysis of algorithms
Analysis of algorithms Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based on the size of the input (time complexity), and/or developing a
More informationUsing Microsoft Excel
Using Microsoft Excel Introduction This handout briefly outlines most of the basic uses and functions of Excel that we will be using in this course. Although Excel may be used for performing statistical
More informationDivisibility Rules and Their Explanations
Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although
More informationRepetition Through Recursion
Fundamentals of Computer Science I (CS151.02 2007S) Repetition Through Recursion Summary: In many algorithms, you want to do things again and again and again. For example, you might want to do something
More informationIdeally your algorithms for both parts should run in linear time. You will receive partial credit for a polynomial-time algorithm.
HW 7: Extra problems Instructor: Sariel Har-Peled CS/ECE 374: Algorithms & Models of Computation, Fall 2017 Version: 1.0 1 Consider a directed graph G, where each edge is colored either red, white, or
More informationCS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych
CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is
More informationCS61B Lecture #35. [The Lecture #32 notes covered lectures #33 and #34.] Today: Enumerated types, backtracking searches, game trees.
CS61B Lecture #35 [The Lecture #32 notes covered lectures #33 and #34.] Today: Enumerated types, backtracking searches, game trees. Coming Up: Graph Structures: DSIJ, Chapter 12 Last modified: Mon Nov
More informationYour First Windows Form
Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is
More informationConstraint Satisfaction Problems
Constraint Satisfaction Problems Adrian Groza Department of Computer Science Technical University of Cluj-Napoca 12 Nov 2014 Outline 1 Constraint Reasoning 2 Systematic Search Methods Improving backtracking
More information/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17
01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are
More information10/11/2017. Constraint Satisfaction Problems II. Review: CSP Representations. Heuristic 1: Most constrained variable
//7 Review: Constraint Satisfaction Problems Constraint Satisfaction Problems II AIMA: Chapter 6 A CSP consists of: Finite set of X, X,, X n Nonempty domain of possible values for each variable D, D, D
More informationLab 4: Super Sudoku Solver CSCI 2101 Fall 2017
Due: Wednesday, October 18, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 In this week s lab, you will write a program that can solve
More informationCMSC 201 Spring 2018 Project 3 Minesweeper
CMSC 201 Spring 2018 Project 3 Minesweeper Assignment: Project 3 Minesweeper Due Date: Design Document: Friday, May 4th, 2018 by 8:59:59 PM Project: Friday, May 11th, 2018 by 8:59:59 PM Value: 80 points
More informationPacific Northwest Region Programming Contest Division 2
Pacific Northwest Region Programming Contest Division 2 November 14th, 2015 Reminders For all problems, read the input data from standard input and write the results to standard output. In general, when
More informationUNM - PNM STATEWIDE MATHEMATICS CONTEST XLI. February 7, 2009 Second Round Three Hours
UNM - PNM STATEWIDE MATHEMATICS CONTEST XLI February 7, 009 Second Round Three Hours (1) An equilateral triangle is inscribed in a circle which is circumscribed by a square. This square is inscribed in
More informationGraph theory. Po-Shen Loh. June We begin by collecting some basic facts which can be proved via bare-hands techniques.
Graph theory Po-Shen Loh June 013 1 Basic results We begin by collecting some basic facts which can be proved via bare-hands techniques. 1. The sum of all of the degrees is equal to twice the number of
More informationOptimization and least squares. Prof. Noah Snavely CS1114
Optimization and least squares Prof. Noah Snavely CS1114 http://cs1114.cs.cornell.edu Administrivia A5 Part 1 due tomorrow by 5pm (please sign up for a demo slot) Part 2 will be due in two weeks (4/17)
More informationWhat Every Programmer Should Know About Floating-Point Arithmetic
What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationError Analysis, Statistics and Graphing
Error Analysis, Statistics and Graphing This semester, most of labs we require us to calculate a numerical answer based on the data we obtain. A hard question to answer in most cases is how good is your
More informationSorting and Selection
Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element
More informationChapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change
Chapter01.fm Page 1 Monday, August 23, 2004 1:52 PM Part I The Mechanics of Change The Mechanics of Change Chapter01.fm Page 2 Monday, August 23, 2004 1:52 PM Chapter01.fm Page 3 Monday, August 23, 2004
More informationXVIII Open Cup named after E.V. Pankratiev Stage 1: Grand Prix of Romania, Sunday, September 17, 2017
Problem A. Balance file: 1 second 512 mebibytes We say that a matrix A of size N N is balanced if A[i][j] + A[i + 1][j + 1] = A[i + 1][j] + A[i][j + 1] for all 1 i, j N 1. You are given a matrix A of size
More informationFunction Call Stack and Activation Records
71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students
More informationMergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015
CS161, Lecture 2 MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015 1 Introduction Today, we will introduce a fundamental algorithm design paradigm, Divide-And-Conquer,
More informationEASY
Downloaded from: justpaste.it/hsfm ------------------------------- EASY ------------------------------- NUMBERS Even or Odd Write a program that accepts a number and returns whether the number is equal
More informationAlgorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs
Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to
More informationLecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40
Lecture 16 Hashing Hash table and hash function design Hash functions for integers and strings Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table
More informationstatic String usersname; public static int numberofplayers; private static double velocity, time;
A class can include other things besides subroutines. In particular, it can also include variable declarations. Of course, you can declare variables inside subroutines. Those are called local variables.
More informationHi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we
Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we have to talk about the way in which we represent the
More information1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1
Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)
More informationConstraint Satisfaction Problems
Last update: February 25, 2010 Constraint Satisfaction Problems CMSC 421, Chapter 5 CMSC 421, Chapter 5 1 Outline CSP examples Backtracking search for CSPs Problem structure and problem decomposition Local
More informationWeek 8: Constraint Satisfaction Problems
COMP3411/ 9414/ 9814: Artificial Intelligence Week 8: Constraint Satisfaction Problems [Russell & Norvig: 6.1,6.2,6.3,6.4,4.1] COMP3411/9414/9814 18s1 Constraint Satisfaction Problems 1 Outline Constraint
More informationASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)
ASSIGNMENT 2 COMP-202A, Fall 2013, All Sections Due: October 20 th, 2013 (23:59) Please read the entire PDF before starting. You must do this assignment individually and, unless otherwise specified, you
More informationNavigating and Managing Files and Folders in Windows XP
Part 1 Navigating and Managing Files and Folders in Windows XP In the first part of this book, you ll become familiar with the Windows XP Home Edition interface and learn how to view and manage files,
More informationB+ Tree Review. CSE332: Data Abstractions Lecture 10: More B Trees; Hashing. Can do a little better with insert. Adoption for insert
B+ Tree Review CSE2: Data Abstractions Lecture 10: More B Trees; Hashing Dan Grossman Spring 2010 M-ary tree with room for L data items at each leaf Order property: Subtree between keys x and y contains
More informationCSE 373 MAY 10 TH SPANNING TREES AND UNION FIND
CSE 373 MAY 0 TH SPANNING TREES AND UNION FIND COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend HW5 out tomorrow
More informationSection Marks Pre-Midterm / 32. Logic / 29. Total / 100
Name: CS 331 Final Exam Spring 2011 You have 110 minutes to complete this final exam. You are only allowed to use your textbook, your notes, your assignments and solutions to those assignments during this
More informationUNC Charlotte 2010 Comprehensive
00 Comprehensive March 8, 00. A cubic equation x 4x x + a = 0 has three roots, x, x, x. If x = x + x, what is a? (A) 4 (B) 8 (C) 0 (D) (E) 6. For which value of a is the polynomial P (x) = x 000 +ax+9
More informationBalanced Search Trees
Balanced Search Trees Computer Science E-22 Harvard Extension School David G. Sullivan, Ph.D. Review: Balanced Trees A tree is balanced if, for each node, the node s subtrees have the same height or have
More informationIntroduction to Domain Testing
Introduction to Domain Testing Cem Kaner January, 2018 Copyright (c) 2018 Cem Kaner Domain Testing 1 What Is Domain Testing? The most widely taught technique for designing software tests Copyright (c)
More informationSPRITES Moving Two At the Same Using Game State
If you recall our collision detection lesson, you ll likely remember that you couldn t move both sprites at the same time unless you hit a movement key for each at exactly the same time. Why was that?
More informationPropositional logic (Ch. 7)
Propositional logic (Ch. 7) Announcements Writing 2 graded - 2 weeks from today to resubmit Complete-state CSP So far we have been looking at incremental search (adding one value at a time) Complete-state
More informationConstraint Satisfaction. AI Slides (5e) c Lin
Constraint Satisfaction 4 AI Slides (5e) c Lin Zuoquan@PKU 2003-2018 4 1 4 Constraint Satisfaction 4.1 Constraint satisfaction problems 4.2 Backtracking search 4.3 Constraint propagation 4.4 Local search
More informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationCPSC 320: Intermediate Algorithm Design and Analysis. Tutorial: Week 3
CPSC 320: Intermediate Algorithm Design and Analysis Author: Susanne Bradley Tutorial: Week 3 At the time of this week s tutorial, we were approaching the end of our stable matching unit and about to start
More informationClasswork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015
Classwork 7: Craps N. Duong & R. Rodriguez, Java Crash Course January 6, 2015 For this classwork, you will be writing code for the game Craps. For those of you who do not know, Craps is a dice-rolling
More informationCS2500 Exam 2 Fall 2011
CS2500 Exam 2 Fall 2011 Name: Student Id (last 4 digits): Section (morning, honors or afternoon): Write down the answers in the space provided. You may use the usual primitives and expression forms, including
More informationAssignment #4 Minesweeper
Assignment #4 Minesweeper Date assigned: Friday, January 9, 2015 Date due: Java Minesweeper, Tuesday, January 13, 2015 Android Minesweeper, Friday, January 17, 2015 Points: 100 Java Minesweeper The game
More informationExcel Basics: Working with Spreadsheets
Excel Basics: Working with Spreadsheets E 890 / 1 Unravel the Mysteries of Cells, Rows, Ranges, Formulas and More Spreadsheets are all about numbers: they help us keep track of figures and make calculations.
More informationWelfare Navigation Using Genetic Algorithm
Welfare Navigation Using Genetic Algorithm David Erukhimovich and Yoel Zeldes Hebrew University of Jerusalem AI course final project Abstract Using standard navigation algorithms and applications (such
More informationModule 4. Constraint satisfaction problems. Version 2 CSE IIT, Kharagpur
Module 4 Constraint satisfaction problems Lesson 10 Constraint satisfaction problems - II 4.5 Variable and Value Ordering A search algorithm for constraint satisfaction requires the order in which variables
More informationProject MineSweeper Collaboration: Solo Complete this Project by yourself or with help from Section Leaders and Rick You are asked to write the non-graphical user interface aspects of the popular game
More informationClustering. (Part 2)
Clustering (Part 2) 1 k-means clustering 2 General Observations on k-means clustering In essence, k-means clustering aims at minimizing cluster variance. It is typically used in Euclidean spaces and works
More informationAP Computer Science Unit 3. Programs
AP Computer Science Unit 3. Programs For most of these programs I m asking that you to limit what you print to the screen. This will help me in quickly running some tests on your code once you submit them
More informationSlide Set 5. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary
Slide Set 5 for ENEL 353 Fall 207 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 207 SN s ENEL 353 Fall 207 Slide Set 5 slide
More informationAlgorithms and Data Structures
Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................
More informationOutline. Best-first search
Outline Best-first search Greedy best-first search A* search Heuristics Local search algorithms Hill-climbing search Beam search Simulated annealing search Genetic algorithms Constraint Satisfaction Problems
More information15-780: Graduate AI Homework Assignment #2 Solutions
15-780: Graduate AI Homework Assignment #2 Solutions Out: February 12, 2015 Due: February 25, 2015 Collaboration Policy: You may discuss the problems with others, but you must write all code and your writeup
More informationSimple Graph. General Graph
Graph Theory A graph is a collection of points (also called vertices) and lines (also called edges), with each edge ending at a vertex In general, it is allowed for more than one edge to have the same
More informationOutline. Best-first search
Outline Best-first search Greedy best-first search A* search Heuristics Local search algorithms Hill-climbing search Beam search Simulated annealing search Genetic algorithms Constraint Satisfaction Problems
More informationCopyright 2000, Kevin Wayne 1
Guessing Game: NP-Complete? 1. LONGEST-PATH: Given a graph G = (V, E), does there exists a simple path of length at least k edges? YES. SHORTEST-PATH: Given a graph G = (V, E), does there exists a simple
More informationBackground. $VENDOR wasn t sure either, but they were pretty sure it wasn t their code.
Background Patient A got in touch because they were having performance pain with $VENDOR s applications. Patient A wasn t sure if the problem was hardware, their configuration, or something in $VENDOR
More informationConstraint Satisfaction Problems. Chapter 6
Constraint Satisfaction Problems Chapter 6 Office hours Office hours for Assignment 1 (ASB9810 in CSIL): Sep 29th(Fri) 12:00 to 13:30 Oct 3rd(Tue) 11:30 to 13:00 Late homework policy You get four late
More informationMidterm I Exam Principles of Imperative Computation André Platzer Ananda Gunawardena. February 23, 2012
Midterm I Exam 15-122 Principles of Imperative Computation André Platzer Ananda Gunawardena February 23, 2012 Name: Sample Solution Andrew ID: aplatzer Section: Instructions This exam is closed-book with
More information(Refer Slide Time: 01.26)
Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.
More information15-451/651: Design & Analysis of Algorithms November 4, 2015 Lecture #18 last changed: November 22, 2015
15-451/651: Design & Analysis of Algorithms November 4, 2015 Lecture #18 last changed: November 22, 2015 While we have good algorithms for many optimization problems, the previous lecture showed that many
More informationMaximum Density Still Life
The Hebrew University of Jerusalem Computer Science department Maximum Density Still Life Project in course AI 67842 Mohammad Moamen Table of Contents Problem description:... 3 Description:... 3 Objective
More informationConstraint Satisfaction
Constraint Satisfaction Philipp Koehn 1 October 2015 Outline 1 Constraint satisfaction problems (CSP) examples Backtracking search for CSPs Problem structure and problem decomposition Local search for
More informationWeek 12: Running Time and Performance
Week 12: Running Time and Performance 1 Most of the problems you have written in this class run in a few seconds or less Some kinds of programs can take much longer: Chess algorithms (Deep Blue) Routing
More informationThe first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.
Graphing in Excel featuring Excel 2007 1 A spreadsheet can be a powerful tool for analyzing and graphing data, but it works completely differently from the graphing calculator that you re used to. If you
More informationCOMP : Practical 9 ActionScript: Text and Input
COMP126-2006: Practical 9 ActionScript: Text and Input This practical exercise includes two separate parts. The first is about text ; looking at the different kinds of text field that Flash supports: static,
More informationParallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs
Lecture 16 Treaps; Augmented BSTs Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Margaret Reid-Miller 8 March 2012 Today: - More on Treaps - Ordered Sets and Tables
More informationConstraint Satisfaction Problems: A Deeper Look
Constraint Satisfaction Problems: A Deeper Look The last problem set covered the topic of constraint satisfaction problems. CSP search and solution algorithms are directly applicable to a number of AI
More informationOutline. Informed Search. Recall: Uninformed Search. An Idea. Heuristics Informed search techniques More on heuristics Iterative improvement
Outline Informed Search ECE457 Applied Artificial Intelligence Fall 2007 Lecture #3 Heuristics Informed search techniques More on heuristics Iterative improvement Russell & Norvig, chapter 4 Skip Genetic
More informationCPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60
CPS 102: Discrete Mathematics Instructor: Bruce Maggs Quiz 3 Date: Wednesday November 30, 2011 NAME: Prob # Score Max Score 1 10 2 10 3 10 4 10 5 10 6 10 Total 60 1 Problem 1 [10 points] Find a minimum-cost
More informationSection 4.1: Introduction to Trigonometry
Section 4.1: Introduction to Trigonometry Review of Triangles Recall that the sum of all angles in any triangle is 180. Let s look at what this means for a right triangle: A right angle is an angle which
More informationAlgorithm Analysis. Big Oh
Algorithm Analysis with Big Oh Data Structures and Design with Java and JUnit Chapter 12 Rick Mercer Algorithm Analysis w Objectives Analyze the efficiency of algorithms Analyze a few classic algorithms
More information1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation
1.00 Lecture 32 Hashing Reading for next time: Big Java 18.1-18.3 Motivation Can we search in better than O( lg n ) time, which is what a binary search tree provides? For example, the operation of a computer
More informationExcel Spreadsheets and Graphs
Excel Spreadsheets and Graphs Spreadsheets are useful for making tables and graphs and for doing repeated calculations on a set of data. A blank spreadsheet consists of a number of cells (just blank spaces
More information/ Approximation Algorithms Lecturer: Michael Dinitz Topic: Linear Programming Date: 2/24/15 Scribe: Runze Tang
600.469 / 600.669 Approximation Algorithms Lecturer: Michael Dinitz Topic: Linear Programming Date: 2/24/15 Scribe: Runze Tang 9.1 Linear Programming Suppose we are trying to approximate a minimization
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationCorrelation. January 12, 2019
Correlation January 12, 2019 Contents Correlations The Scattterplot The Pearson correlation The computational raw-score formula Survey data Fun facts about r Sensitivity to outliers Spearman rank-order
More informationType Checking and Type Equality
Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.
More informationCSE 326: Data Structures Splay Trees. James Fogarty Autumn 2007 Lecture 10
CSE 32: Data Structures Splay Trees James Fogarty Autumn 2007 Lecture 10 AVL Trees Revisited Balance condition: Left and right subtrees of every node have heights differing by at most 1 Strong enough :
More informationCS 231: Algorithmic Problem Solving
CS 231: Algorithmic Problem Solving Naomi Nishimura Module 7 Date of this version: January 28, 2019 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides
More informationCS 3 Midterm 1 Review
CS 3 Midterm 1 Review 1. Quick Evaluations Indicate what each of the following would return if typed into STK. If you think it would error, then please write ERROR. If you think that it would loop forever,
More informationCMPSCI611: Approximating SET-COVER Lecture 21
CMPSCI611: Approximating SET-COVER Lecture 21 Today we look at two more examples of approximation algorithms for NP-hard optimization problems. The first, for the SET-COVER problem, has an approximation
More information18-642: Code Style for Compilers
18-642: Code Style for Compilers 9/6/2018 2017-2018 Philip Koopman Programming can be fun, so can cryptography; however they should not be combined. Kreitzberg and Shneiderman 2017-2018 Philip Koopman
More information