EGR 115 Introduction to Computing for Engineers

Slides:



Advertisements
Similar presentations
Chapter 8. Data Structure: A variable that stores more than one value Matrices/vectors and character arrays are types of data structures MATLAB also provides.
Advertisements

CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
What is entry A in the matrix multiplication: ( a) 1 (b) -2(c) 5 (d) 11(e) 13 (f) 0.
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Analysis of Algorithms
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
Click Here to Begin the Game CHOICE 1CHOICE 2CHOICE 3 CHOICE CHOICE
SOLVING SUDOKU WITH MATLAB VERIFICATION FUNCTION correctness verification of the puzzle: checks if the current element appears twice in the same line,
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 Data Structures CSCI 132, Spring 2014 Lecture 32 Tables I.
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Working with Arrays in MATLAB
EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 3 Friday 17 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
 Chapter 7 introduces the stack data type.  Several example applications of stacks are given in that chapter.  This presentation shows another use called.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Searching and Sorting Searching algorithms with simple arrays
Fundamentals of Algorithms MCS - 2 Lecture # 11
EGR 115 Introduction to Computing for Engineers
Flood fill algorithm Also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array, When applied.
Lecture 5 of Computer Science II
EGR 2261 Unit 10 Two-dimensional Arrays
EGR 115 Introduction to Computing for Engineers
Data Structures I (CPCS-204)
Recursive stack-based version of Back-chaining using Propositional Logic
EGR 115 Introduction to Computing for Engineers
Microsoft Visual Basic 2005: Reloaded Second Edition
EGR 115 Introduction to Computing for Engineers
Lesson 5-15 AP Computer Science Principles
Chapter 4 MATLAB Programming
Other Kinds of Arrays Chapter 11
Chapter 7 Arrays.
Scripts & Functions Scripts and functions are contained in .m-files
Use of Mathematics using Technology (Maltlab)
Lecture 6 2d Arrays Richard Gesick.
Sparse matrices, hash tables, cell arrays
Chapter2 Creating Arrays
Matlab Intro.
Multidimensional Arrays
Arrays Week 2.
CS2011 Introduction to Programming I Multidimensional Arrays
Review for Test1.
Algorithms CSCI 235, Spring 2019 Lecture 28 Dynamic Programming III
‘If’ statements, relational operators, and logical operators
Can you think of 2 purposes of the operating system?
Using Script Files and Managing Data
Sudoku.
Introduction to Matlab
Introduction to Computer Science
Chapter 8 Multidimensional Arrays
EECS Introduction to Computing for the Physical Sciences
Topic 25 - more array algorithms
Working with Arrays in MATLAB
Constraint Graph Binary CSPs
ICS103: Programming in C Searching, Sorting, 2D Arrays
Matlab Intro.
GCSE Computing.
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

EGR 115 Introduction to Computing for Engineers Designing The Sudoku Game in MATLAB – Part 2 lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Rules of the game: It is our job to complete the Sudoku array by filling-in the empty array entries Every row must contain all of the numbers from 1 to 9 Every col must contain all of the numbers from 1 to 9 Every sub-array must contain all of the numbers from 1 to 9 No number can be repeated in a row, a col, or a sub array Many strategies exist, however, we will be developing our own strategies!! lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #1 Consider the empty element at row 3 and col 6 Sudoku_array(3, 6) belongs to: Row 3, col 6, and sub-matrix (1:3, 4:6) Based only on row 3, what is the set of possible choices? Based only on col 6, what is the set of possible choices? Based only on sub-matrix (1:3, 4:6) what is the set of possible choices? Allowed by all three? Sudoku_array(3, 6) = 1 2 3 4 5 6 7 8 9 1,3,4,8,9 1, 3, 5, 6, 9 ? 2, 3, 4, 7, 9 3, 9 lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #1 Algorithm: Identify an empty element in the table Determine the row, col, and sub-matrix to which this element belongs Determine element choices based only on: Row -> row_set Col -> col_set Sub-matrix -> sub_matrix_set Compute the intersection of the three sets Return to step 1. until all empty elements have been considered lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #1 We will need to run this algorithm up to 81 times Very painful!! Could start with row #1 and “loop” through all 9 cols then row #2 and “loop” through all 9 cols , … We do not know how to “code” that yet!! Need to be able to determine “if” a particular number is contained in an array Logical operations? What type of variable (or data structure) can we use to store the possible choices for each empty element? Three dimensional array? lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #2 Consider the empty element at row 3 and col 6 Sudoku_array(3, 6) belongs to: Row 3, col 6, and sub-matrix (1:3, 4:6) With NO constraints could be: Considering row 3: Next, considering col 6: Next, considering sub-mat (1:3, 4:6): Conclusion: Sudoku_array(3, 6) = 1 2 3 4 5 6 7 8 9 ? 3, 9 lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #2 Algorithm: Identify an empty element in the table Determine the row, col, and sub-matrix to which this element belongs Assume that the element can be any of the set 1, …, 9 Reduce the set choices based on: Row: Remove any numbers present in the row, then Col: Remove any numbers present in the col, then Sub-matrix: Remove any numbers present in the sub-matrix Return to step 1. until all empty elements have been considered lecture 13 EGR 115 Introduction to Computing for Engineers

Designing The Sudoku Game in MATLAB Approach #2 We will need to run this algorithm up to 81 times Very painful!! Could start with row #1 and “loop” through all 9 cols then row #2 and “loop” through all 9 cols , … A loop within a loop? We do not know how to “code” that yet!! Need to be able to determine “if” a particular number is contained in an array Logical operations? We do not know how to “code” that yet!! What type of variable (or data structure) can we use to store the possible choices for each empty element? Could create a unique file for each empty cell For example: row2_col5.mat lecture 13 EGR 115 Introduction to Computing for Engineers

EGR 115 Introduction to Computing for Engineers Next Lecture Mid-Term Exam#1 lecture 13 EGR 115 Introduction to Computing for Engineers