CS162 Week 2 Kyle Dewey. Overview Continuation of Scala Assignment 1 wrap-up Assignment 2a.

Slides:



Advertisements
Similar presentations
BAH DAML Tools XML To DAML Query Relevance Assessor DAML XSLT Adapter.
Advertisements

Chapter 7. Binary Search Trees
SAT Encoding For Sudoku Puzzles
Representing Boolean Functions for Symbolic Model Checking Supratik Chakraborty IIT Bombay.
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Copyright © Cengage Learning. All rights reserved.
C++ for Engineers and Scientists Third Edition
Backtracking.
CSE (c) S. Tanimoto, 2007 Search 1: State Spaces 1 State-Space Search Outline: Demonstration with T* State spaces, operators, moves A Puzzle: The.
1 Gentle Introduction to Programming Session 4: Arrays.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
1 Teaching Programming with Sudoku Bill Sanders for Axel T. Schreiner Killer Examples Workshop at OOPSLA’09.
1 What NOT to do I get sooooo Frustrated! Marking the SAME wrong answer hundreds of times! I will give a list of mistakes which I particularly hate marking.
Automatic methods for functional annotation of sequences Petri Törönen.
Monads Technion – Institute of Technology Software Design (236700) Author: Gal Lalouche - Technion 2015 © 1.
Physical Mapping of DNA Shanna Terry March 2, 2004.
CS10 Final Review by Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Glenn Sugdenmons Attribution-NonCommercial-ShareAlike.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
LDK R Logics for Data and Knowledge Representation ClassL (part 3): Reasoning with an ABox 1.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Data Structures Using Java1 Chapter 4 Linked Lists.
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Relational Databases.  In week 1 we looked at the concept of a key, the primary key is a column/attribute that uniquely identifies the rest of the data.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
Hashing Hashing is another method for sorting and searching data.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
PROGRAMMING LANGUAGES: PROLOG, CLOJURE, F# Jared Wheeler.
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
User Interface Design Patterns Part II Presented by: Mohammed CS2310 April 15, 2008.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Monster (“Mega”) Sudoku
Backtracking & Brute Force Optimization Intro2CS – weeks
Entity Relationship Diagram (ERD). Objectives Define terms related to entity relationship modeling, including entity, entity instance, attribute, relationship.
int [] scores = new int [10];
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Faceted Search for Hydrologic Data Discovery Alex Bedig Alva Couch Tufts University, Medford, MA.
Lecture 3: Uninformed Search
Problem Solving: Brute Force Approaches
Lists in Lisp and Scheme
Trees Lecture 12 CS2110 – Fall 2017.
Week 7 Part 2 Kyle Dewey.
Data Structures and Database Applications Binary Trees in C#
Problem Solving: Brute Force Approaches
int [] scores = new int [10];
Coding Concepts (Basics)
Lecture 12 CS203 1.
Spreadsheets, Modelling & Databases
Knowledge Representation
Data Structures & Algorithms
Unit III – Chapter 3 Path Testing.
Presentation transcript:

CS162 Week 2 Kyle Dewey

Overview Continuation of Scala Assignment 1 wrap-up Assignment 2a

Scala Continued

Traits Created with the trait reserved word Like a mixin in Ruby Think Java interfaces, but they can have methods defined on them More powerful than that, but not relevant to this course

object Used in much the same way as static is in Java Defines both a class and a single instance of that class (and only a single instance) Automated implementation of the Singleton design pattern Keeps everything consistently an object

equals, ==, and eq As with Java, if you want to compare value equality, you must extend equals Case classes automatically do this for you However, instead of saying x.equals(y), merely say x == y If you want reference equality, say: x eq y

Case Classes Behave just like classes, but a number of things are automatically generated for you Including hashCode, equals, and getters Typically used for pattern matching

Pattern Matching Used extensively in Scala Like a super-powerful if Used with the match reserved word, followed by a series of case s

null In general, null is an excellent wonderful/terrible feature Often poorly documented whether or not null is possible Checking for impossible cases Not checking for possible cases

Option A solution: encode null as part of a type For some type, say Object, if null is possible say we have a NullPossible Scala has this, known as Option In general, if null is possible, use Option

Tuples For when you want to return more than one thing Can be created by putting datums in parenthesis Can pattern match on them

Sequence Processing Functions AKA: Why while is rare and for isn’t for

Looping Scala has a while loop, but its use is highly discouraged (again, point loss) It’s not actually needed General functional programming style is recursion, but this is usually overkill

foreach Applies a given function to each element of a Seq

map Like foreach, in that it applies a given function to each element of a sequence However, it also returns a new sequence that holds the return values of each of the function calls

filter Takes a predicate, i.e. a function that returns true or false Applies the predicate to each item in a list A new list is returned that contains all the items for which the predicate was true

foldLeft Extremely flexible, but sometimes unwieldy Takes a base element Takes a function that takes a current result and a current list element The function will manipulate result with respect to the current element

flatMap Like map, but made especially for functions that return Seq s Will internally “flatten” all of the inner Seq s into a single Seq More on this later in the course

for Comprehensions Much like Python’s list comprehensions Internally translated into a series of foreach, flatMap, map, and filter operations

Assignment 1 Questions Level of challenge? Any problems worth going over? Pre/post order traversals? Run length encoding?

Assignment 2a: Logic Programming

Assignment Overview Goal: gain some familiarity with logic programming Part A: Write code to traverse an ontology Part B: Write a Sudoku solver

Ontologies Formal knowledge base Concepts and relationships between concepts Often representable as a giant, heavily annotated directed acyclic graph

The Gene Ontology Of great importance within Biology and Bioinformatics Database of biological processes, cellular components, and molecular function Allows scientists to quickly determine relevant information

Example

What to Write “A procedure named toisaroot, which makes a list showing the path from some given concept C to the root, which is always 'cellular component'.” For a given concept, there may be no path to the root, or multiple paths

isaroot Example

Another GO Search The GO has both is_a and part_of relationships This distinction may not always be important for gathering information of interest We may be interested in transitive relationships

What to Write “A procedure named subconcept to determine if a given concept C1 is a subconcept of some concept C2. This is true if at least one of the following holds:” C1 is a part_of C2 C1 is_a C2 The above two conditions hold transitively Another view: C1 is a child node of C2

subconcept Example

Part B: Sudoku Solvers Sudoku: 9x9 board consisting of 9 3x3 subboards Each row, column, and subboard must contain the digits 1-9 (no repeats possible, and all must be accounted for) Some numbers are already given Goal: fill in the rest

Example - Given

Example - Solution

Goal Write a predicate solve(Board) that solves a 9x9 board List of nine lists, each of which is a list of nine elements, where each element is either a number or an unknown (unbound variable)

Optimization Naive solution: try all possible combinations, and check constraints at the end Optimization: try one number, and ensure that constraints have not been violated For full credit, you must implement this optimization

Performance The solver will likely not perform well on hard boards, even with the optimization This will be addressed later on when we get into constraint logic programming Will likely offer a cleaner solution, too