On Some Entertaining Applications of the Concept of Set in Computer Science Course

Similar documents
ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

An Optimal Algorithm for Prufer Codes *

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

CMPS 10 Introduction to Computer Science Lecture Notes

Solving two-person zero-sum game by Matlab

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

Optimization Methods: Integer Programming Integer Linear Programming 1. Module 7 Lecture Notes 1. Integer Linear Programming

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

SENSITIVITY ANALYSIS IN LINEAR PROGRAMMING USING A CALCULATOR

CHAPTER 2 DECOMPOSITION OF GRAPHS

Programming in Fortran 90 : 2017/2018

Load Balancing for Hex-Cell Interconnection Network

Mathematics 256 a course in differential equations for engineering students

An Entertaining Example for the Usage of Bitwise Operations in Programming

Problem Set 3 Solutions

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Machine Learning: Algorithms and Applications

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

A Binarization Algorithm specialized on Document Images and Photos

Lecture 5: Multilayer Perceptrons

Type-2 Fuzzy Non-uniform Rational B-spline Model with Type-2 Fuzzy Data

Module Management Tool in Software Development Organizations

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Kent State University CS 4/ Design and Analysis of Algorithms. Dept. of Math & Computer Science LECT-16. Dynamic Programming

Sum of Linear and Fractional Multiobjective Programming Problem under Fuzzy Rules Constraints

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

CE 221 Data Structures and Algorithms

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Lecture #15 Lecture Notes

Solitary and Traveling Wave Solutions to a Model. of Long Range Diffusion Involving Flux with. Stability Analysis

Support Vector Machines

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Hermite Splines in Lie Groups as Products of Geodesics

Array transposition in CUDA shared memory

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

Cracking of the Merkle Hellman Cryptosystem Using Genetic Algorithm

Notes on Organizing Java Code: Packages, Visibility, and Scope

MULTISPECTRAL IMAGES CLASSIFICATION BASED ON KLT AND ATR AUTOMATIC TARGET RECOGNITION

Multiblock method for database generation in finite element programs

A Facet Generation Procedure. for solving 0/1 integer programs

Introduction. Leslie Lamports Time, Clocks & the Ordering of Events in a Distributed System. Overview. Introduction Concepts: Time

Related-Mode Attacks on CTR Encryption Mode

A New Approach For the Ranking of Fuzzy Sets With Different Heights

A Topology-aware Random Walk

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

3D vector computer graphics

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

UNIT 2 : INEQUALITIES AND CONVEX SETS

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

Cluster Analysis of Electrical Behavior

A NOTE ON FUZZY CLOSURE OF A FUZZY SET

Non-Split Restrained Dominating Set of an Interval Graph Using an Algorithm

CS221: Algorithms and Data Structures. Priority Queues and Heaps. Alan J. Hu (Borrowing slides from Steve Wolfman)

Fast Computation of Shortest Path for Visiting Segments in the Plane

The Shortest Path of Touring Lines given in the Plane

Brave New World Pseudocode Reference

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

F Geometric Mean Graphs

An Application of Network Simplex Method for Minimum Cost Flow Problems

Positive Semi-definite Programming Localization in Wireless Sensor Networks

Private Information Retrieval (PIR)

Parallel Numerics. 1 Preconditioning & Iterative Solvers (From 2016)

Esc101 Lecture 1 st April, 2008 Generating Permutation

The Greedy Method. Outline and Reading. Change Money Problem. Greedy Algorithms. Applications of the Greedy Strategy. The Greedy Method Technique

Insertion Sort. Divide and Conquer Sorting. Divide and Conquer. Mergesort. Mergesort Example. Auxiliary Array

Professional competences training path for an e-commerce major, based on the ISM method

AC : TEACHING SPREADSHEET-BASED NUMERICAL ANAL- YSIS WITH VISUAL BASIC FOR APPLICATIONS AND VIRTUAL IN- STRUMENTS

K-means and Hierarchical Clustering

TOWARDS ADVANCED DATA RETRIEVAL FROM LEARNING OBJECTS REPOSITORIES

Mathematical Modeling of Earthwork Optimization Problems

CS 534: Computer Vision Model Fitting

Routing on Switch Matrix Multi-FPGA Systems

OPL: a modelling language

Sorting. Sorting. Why Sort? Consistent Ordering

CS1100 Introduction to Programming

Proper Choice of Data Used for the Estimation of Datum Transformation Parameters

Analysis of Continuous Beams in General

Dijkstra s Single Source Algorithm. All-Pairs Shortest Paths. Dynamic Programming Solution. Performance

Cordial and 3-Equitable Labeling for Some Star Related Graphs

TECHNIQUE OF FORMATION HOMOGENEOUS SAMPLE SAME OBJECTS. Muradaliyev A.Z.

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

Circuit Analysis I (ENGR 2405) Chapter 3 Method of Analysis Nodal(KCL) and Mesh(KVL)

Analysis of EEG of shooters

Smoothing Spline ANOVA for variable screening

Programming Assignment Six. Semester Calendar. 1D Excel Worksheet Arrays. Review VBA Arrays from Excel. Programming Assignment Six May 2, 2017

Intra-Parametric Analysis of a Fuzzy MOLP

AMath 483/583 Lecture 21 May 13, Notes: Notes: Jacobi iteration. Notes: Jacobi with OpenMP coarse grain

Loop Transformations, Dependences, and Parallelization

An Approach in Coloring Semi-Regular Tilings on the Hyperbolic Plane

PYTHON IMPLEMENTATION OF VISUAL SECRET SHARING SCHEMES

CS246: Mining Massive Datasets Jure Leskovec, Stanford University

Design and Analysis of Algorithms

Data Representation in Digital Design, a Single Conversion Equation and a Formal Languages Approach

Parallel matrix-vector multiplication

Transcription:

On Some Entertanng Applcatons of the Concept of Set n Computer Scence Course Krasmr Yordzhev *, Hrstna Kostadnova ** * Assocate Professor Krasmr Yordzhev, Ph.D., Faculty of Mathematcs and Natural Scences, South-West Unversty, Blagoevgrad, Bulgara, Е-mal: yordzhev@swu.bg ** Ph.D. student Hrstna Kostadnova, Faculty of Mathematcs and Natural Scences, South- West Unversty, Blagoevgrad, Bulgara, Е-mal: kostadnova@swu.bg Abstract: Some aspects of programmng educaton are examned n ths work. It s emphassed, based on the entertanment value, the most approprate examples are chosen to demonstrate the dfferent language constructons and data structures. Such an example s the demonstrated algorthm for solvng the wdespread nowadays Sudoku puzzle. Ths s made, because of the connecton wth the term set and puttng t nto practce n the programmng. Usng the so bult program there are solved some combnatoral problems, connected to the Sudoku matrces. Key words: Educaton n programmng, programmng languages, data structures, set, Sudoku matrx, Sudoku puzzle. INTRODUCTION The present work s contemplated to help the lecturer n programmng n hs aspraton for gvng an approprate, nterestng and entertanng example of the advantage to use the term set n programmng. For ths purpose the students have to be famlar wth the basc defntons of the set theory and to be skllful at the basc operatons wth sets. It follows the well-known fact that to be a good programmer t s necessary (but not effcent) to be a good mathematcan. A classcal example for the use of sets n programmng has become the programmng realzaton of the problem for fndng prme numbers usng the method Seve of Eratosthenes [,5,8]. How to construct a faster algorthm, solvng the problem for recevng all n n bnary matrces, whch contan exactly k ones n each row and each column, wth the help of the set theory and the operatons over sets, s shown n [10]. We wll examne the entertanng and actual problem, whch s very nterestng for the students algorthms for solvng Sudoku. It s wdespread puzzle nowadays, whch presents n the entertanng pages n most of the newspapers and magaznes and n entertanng web stes. Sudoku, or Su Doku, s a Japanese word (or phrase) meanng somethng lke Number Place. On the other sde, Sudoku matrces fnd an nterestng combnatoral applcaton, for example n the desgn theory [7]. The connecton between the set of all m m permutaton matrces (.e. bnary matrces whch contan ust one 1 n every row and every column) and the set of all m m Sudoku matrces, s shown n [3].

As far as the authors of ths study know there s not a unversal formula for the number of Sudoku matrces n wth every natural number n. We consder t as an open problem n mathematcs. When n 3 n [4] s shown that there are exactly = 6 670 903 75 01 07 936 960 = n number Sudoku matrces. 3 7 = 9! 7 7 704 67 971 = 0 8 = 3 57 7 704 67 971 6.67110 PROBLEM FORMULATION AND ALGORITHM DESCRIPTION Let n s a postve nteger and let n. Let S s s a square m m matrx, whose elements n ths table are ntegers, belongng to the closed nterval1,m. The matrx S s dvded to n, n n square submatrces, whch are not ntersected and wll be called blocks, wth the help of n 1 horzontal and n 1 vertcal lnes (the matrx S, when n 3, s shown on fg. 1). 1 m s 11 s 1 s 13 s 14 s 15 s 16 s 17 s 18 s 19 s 1 s s 3 s 4 s 5 s 6 s 7 s 8 s 9 s 31 s 3 s 33 s 34 s 35 s 36 s 37 s 38 s 39 s 41 s 4 s 43 s 44 s 45 s 46 s 47 s 48 s 49 s 51 s 5 s 53 s 54 s 55 s 56 s 57 s 58 s 59 s 61 s 6 s 63 s 64 s 65 s 66 s 67 s 68 s 69 s 71 s 7 s 73 s 74 s 75 s 76 s 77 s 78 s 79 s 81 s 8 s 83 s 84 s 85 s 86 s 87 s 88 s 89 s 91 s 9 s 93 s 94 s 95 s 96 s 97 s 98 s 99 Fg. 1 Let denote by A, k, l n the blocks n the above descrbed matrx S s. Then by defnton f s A, then ( k 1) n kn and ( l 1) ( l 1). Let s belong to the block Ak l and let and are known. Then t s easy to guess that k and l can be calculated wth the help of the formulas 1 k 1 n and 1 l 1, n where, as usual, we denote by x the functon: whole part of the real number x. set We say that s 1,,, m n 1 S, 1, m n s a Sudoku matrx f there s ust one number of the Z m n every row, every column and every block. The puzzle named Sudoku s wdespread nowadays. It s gven a Sudoku matrx, n whch some of the elements are erased. The mssng elements wll be equal to 0, f we need ths. The task n the puzzle s to restore the mssng elements of the Sudoku matrx. It s supposed that the authors

of the concrete puzzle have chosen the mssng elements, so the problem has only one soluton. Ths condton we wll mss and wll not reckon wth t. In ths work we wll buld our programmng product to show the number of every possble soluton. If the task has no soluton ths number has to be zero. The most popular puzzles Sudoku are when n 3,.e. m 9. We are gong to descrbe an algorthm for creatng a computer program, whch fnds all solutons (f there are some) of random Sudoku. For ths am we wll use the knowledge of the set theory. We examne the sets, and, where 1, m n, 1 k, l n. For every R C B 1,,,m, the set R conssts of all mssng numbers n the -th row of the matrx. Analogously we defne the sets C, 1,,, m correspondngly for the mssng numbers n the -th column and B, k, l 1,,, n correspondngly for the mssng numbers n the blocks A of S. When the algorthm starts workng t traverses many tmes all of the elements S, such that s 0,.e. these are the elements, whch real values we have to fnd. Let s 0 and let s A. We assume Then the followng three cases are possble: P R C B. ) P (empty set). The task has no soluton n ths case; ) P d, d Z m 1,,, m,.e. P : the number of the elements of P s equal to 1 ( P s a set contanng one element). Then the only one possblty for s s s d,.e. we have found the unknown value of s n ths case. After ths we remove the common element d from the sets R, C and B, and then we contnue to the next zero element of the matrx S (f there s such an element); ) P. Then we can not say anythng about the unknown value of s and we move on the next mssng (zero) element of the matrx S. We traverse all zero elements of the matrx S untl one the followng events occur: е1) For some, {1,,, m} s true s 0, but P R C B ; е) All elements n S become postve; е3) All zero elements of S are traversed, but t does not occur nether event е1, nor event е. In other words for all the remanng zero elements n S, the above descrbed case s always true. In case that t occurs one of the events е1 or е, then the procedure stops ts work and vsualzes the obtaned result. In case that event e3 occurs, then the algorthm has to contnue workng by usng other methods, for example t has to apply the tral and error method. In the concrete case ths method conssts of the followng thngs: 1 1 We choose random s S, such that s 0 and let k 1, l 1 n n. Let P R C B d, d, d }. Then for every d r P, r 1,,, t we assume s d. Such { 1, t an assumng we call a random tral. We count the number of all random trals, untl the soluton s found, n the programmng realzaton of the algorthm. After ths we solve the problem for fndng the unknown elements of the Sudoku matrx, whch contan one element less than the prevous s r

matrx. It s comfortable to use a recurson here. The base of the recurson,.e. we go out of the procedure f there occurs event e1 or e. It s absolutely sure that t wll happen (.e. there wll not be an nfnte cycle ), because when we do the random trals we reduce the number of the zero elements by 1. The above descrbed algorthm s realzed n the Pascal programmng language, because of the two man reasons: 1) Pascal s chosen, of the most educatonal nsttutons n the system of the secondary educaton, as a frst programmng language. Ths means that the basc am of ths work s realzed to help the teacher n hs preparaton n the process of fndng nterestng applcaton of the teachng materal. That s the way the presented materal becomes more nterestng for the pupls. ) There are bult n nstruments used to work wth sets n the Pascal programmng language. The above descrbed deas can be realzed n other random programmng language, for example C++. But n ths case we have to look for addtonal nstruments to work wth sets for example the assocatve contaners set and multset realzed n Standard Template Lbrary (STL) [1,5]. It can be used the template class set of the system of computer algebra Symbolc C++, programmng code s gven n detals n [9]. Of course can be bult another class set, and specfc methods of ths class can be descrbed, as a tranng. Ths s a good exercse, havng n mnd the fact that the cardnal number of the basc ( unversal ) set s not very bg. For example the standard puzzle Sudoku has basc set the set of the ntegers from 1 to 9 plus the empty set. SOME COMBINATORIAL APPLICATION Obvously, f for solvng gven Sudoku, there s no need to use the tral and error method,.e. the problem can be solved by usng set theoretcal operatons (0 random trals), then ths Sudoku has a unque soluton. Such a Sudoku s shown on fgure. The opposte proposton s not true, as t s n the next example, shown on fgure 3, where there s a unque soluton and program has made 18 random trals only to receve ths soluton, as the number of the random trals (after the fnal soluton s receved, the program contnues workng f t s necessary) s 33. 3 5 3 8 4 1 6 4 5 7 7 8 5 9 1 6 4 6 3 3 1 7 6 1 4 7 8 3 4 8 6 7 1 5 7 3 4 9 1 1 4 9 7 4 5 3 8 1 7 6 3 7 5 8 4 9 Fg. Fg. 3 Sometmes the Sudoku authors do not examne f the soluton s unque. For example the Sudoku, shown on fgure 4 (s publshed n a newspaper s rubrc Easy Sudoku, the name of the newspaper we wll not menton) has 4 dfferent solutons, the program does 16 random trals untl the fnal soluton s obtaned, and the common number of the random trals s 18. The Sudoku puzzle shown on fgure 5 has no soluton, although on a frst sght there s not contradcton n the condton. The program has to make 1 random trals to receve the result that ths puzzle has no soluton.

4 9 3 8 8 9 3 3 8 4 1 7 9 4 1 4 7 8 3 7 5 8 7 3 5 7 9 3 8 5 5 9 4 7 9 8 4 8 7 3 1 8 9 5 8 9 3 7 5 3 1 3 4 5 7 4 8 7 8 3 Fg. 4 Fg. 5 There are even more combnatoral results wth dfferent Sudoku matrces, receved by the help of the above descrbed algorthm and some experments. There are 83 576 Sudoku matrces of the knd shown on fgure 6; There are 6 80 Sudoku matrces of the knd shown on fgure 7; There are 680 Sudoku matrces of the knd shown on fgure 8; There are 1 78 Sudoku matrces of the knd shown on fgure 9; There are Sudoku matrces of the knd shown on fgure 10; There are 8 Sudoku matrces of the knd shown on fgure 11; 1 3 * * * * * * 4 5 6 * * * * * * 7 8 9 * * * * * * * * * 1 3 * * * * * * 4 5 6 * * * * * * 7 8 9 * * * * * * * * * 1 3 * * * * * * 4 5 6 * * * * * * 7 8 9 1 3 4 5 6 7 8 9 4 5 6 7 8 9 1 3 7 8 9 1 3 4 5 6 3 1 * * * * * * 5 6 4 * * * * * * 8 9 7 * * * * * * 3 1 * * * * * * 6 4 5 * * * * * * 9 7 8 * * * * * * Fg. 6 Fg. 7 1 3 4 * 6 7 8 9 4 5 6 * * * 1 3 7 8 * * * * * 5 6 * * * * * * * 1 8 * * * * * * * 7 3 4 * * * * * 1 6 7 8 * * * 3 4 5 9 1 3 * 5 6 7 8 1 3 4 5 6 7 8 9 4 5 6 7 8 9 1 3 7 8 9 1 3 4 5 6 3 4 5 6 7 8 9 1 5 6 7 8 9 1 3 4 8 9 1 3 4 5 6 7 Fg. 8 Fg. 9

1 3 4 5 6 7 8 9 4 5 6 7 8 9 1 3 7 8 9 1 3 4 5 6 3 4 5 6 7 * * * 5 6 7 8 9 1 * * * 8 9 1 3 4 * * * 3 4 5 * * * * * * 6 7 8 * * * * * * 9 1 * * * * * * 1 * * 7 * * 4 * * * * * 8 * * 5 * * * 3 * * 9 * * 6 7 * * 4 * * 1 * * * 8 * * 5 * * * * * 9 * * 6 * * 3 4 * * 1 * * 7 * * * 5 * * * * 8 * * * 6 * * 3 * * 9 Fg. 10 Fg. 11 REFERENCES [1] Collns W. J., Data structures and the standard template lbrary. McGraw-Hll, 00. [] Dahl D. J., Dkstra E. W., Hoare C. A. R., Structured Programmng. Academc Press Inc., 197. [3] Dahl G., Permutaton matrces related to Sudoku. Lnear Algebra and ts Applcatons, 009, 430, 457 463. [4] Felgenhauer B., Jarvs F. Enumeratng Possble Sudoku Grds. Preprnt avalable at http://www.afarvs.staff.shef.ac.uk/sudoku/sudoku.pdf [5] Jensen, K., Wrth N., Pascal User Manual and Report. 3 rd ed., Sprnger-Verlag, 1985. [6] Lschener R., STL Pocket Reference. O Relly Meda, 004. [7] Mo Hu-Dong, Xu Ru-Gen, Sudoku Square a New Desgn n Feld Experment. Acta Agronomca Snca, 008, 34(9), 1489 1493. [8] Prce D., UCSD Pascal A Consderate Approach. Prentce-Hall, 1983. [9] Sh T. K., Steeb W.-H., Hardy Y., Symbolc C++: An Introducton to Computer Algebra usng Obect-Orented Programmng, Sprnger, 000. [10] Yordzhev, K., Stefanov S., On Some Applcatons of the Consept of Set n Computer Scence Course. Mathematcs and Educatons n Mathematcs, 003, v.3, 49-5.