SlideShare a Scribd company logo
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Letters & Numbers: A Vehicle to Illustrate
Mathematical & Computing Fundamentals
Lighthouse Delta 2013
Steve Sugden, QUT
Phil Stocks, Bond University
28/11/2013
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
SBS Letters & Numbers
Letters & Numbers is a popular game show on SBS
Fairly new to Australia, but not to Europe
Based on the French des Chi¤res et des Lettres (similar to UK
Countdown)
According to Wikipedia "the oldest TV programme still
broadcast on French Television and one of the longest-running
game shows in the world."
Hosted by Richard Morecroft, David Astle (cryptic crossword
writer) & Lily Serna (UTS maths HDR student)
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Anagrams
In the 1990s at Bond I taught the Data Structures subject
about 15 times (MODULA-2, Oberon-2, Delphi)
One of the topics I included was bag - a generalization of set
where elements can occur more than once
Implement by an array of cardinals (frequencies)
Index type of array maps to the set of possible bag elements
For example, a bag of characters (letters) can be used to
check for anagrams or sub-words of a given string
Newspaper anagram-type games are common: The
Australian: "Circuit Breaker", Courier-Mail: "Jumble", GC
Bulletin: "Focus", etc.
Just what is needed for the Letters part of L & N
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Letters game in Excel/VBA
I have a strong preference for the Wirth family of languages,
but these are out of vogue nowadays
Not a huge fan of VB, but given my extensive work with
Excel, it made sense for me to get up to speed with VBA
Was not a very di¢ cult task to implement the bag abstraction
in VBA using a frequency array
The code simply computes the bag of the entered word, and
checks every word in the dictionary, looking for sub-bags
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Example
Bag for the "word" RETAIONBE:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
1 1 0 0 2 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0
Some words whose bags are sub-bags of this are BARITONE,
REOBTAIN (the bags for these are equal, i.e., the words are
anagrams):
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Numbers game
Given six numbers (operands) and a target number, we seek
an expression which evaluates to the target, and includes at
least two of the six inputs (operands) plus any number of
instances of +, , , /
Operands can be used without replacement (once only) but
operator use is unrestricted
Parentheses may be inserted wherever required
Example: Make the target 547 from a subset of the numbers
4, 7, 8, 10, 50, 75
Solution: 547 = (10 50) + (4 10) + 7?
Is this correct?
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
A more interesting challenge
Solving the "numbers" part of the game on a computer is
more challenging
Arithmetic expressions are not linear like strings
They are trees with a recursive structure
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Binary tree
A binary tree is usually de…ned in a recursive fashion
Tree ::= empty j (LTree, Root, RTree)
In other words, a binary tree is either empty (nothing at all) or
it consists of a sequence of three objects: the left (sub-)tree,
the root node, the right (sub-)tree
This is a typical BNF (Backus-Naur) recursive syntax
de…nition, and may be compared mathematically to a
recurrence relation
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Arithmetic expression tree
"No-one, I think, is in my tree - I mean it must be high or low"
(John Lennon, Strawberry Fields Forever, 1967)
Binary tree associated with an arithmetic expression (AE)
internal nodes: operators
external nodes: operands
Example: AE tree for (2 (8 1) + (3 4))
+
××
−2
8 1
3 4
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
In-order tree traversal
PROCEDURE Traverse(t : Tree);
// This mode of traversal generates a normal (in-…x) AE.
// Parens necessary to avoid ambiguity: (2 (8 1) + (3 4))
BEGIN
IF t is not empty THEN
Traverse left subtree of t
Process root node of t
Traverse right subtree of t
END
END Traverse;
3
1
2
5
6
7 9
8
4
+
××
−2
8 1
3 4
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Post-order tree traversal
PROCEDURE Traverse(t : Tree);
// This mode of traversal generates a post…x AE
// Parens unnecessary: 281 34 + (HP calculators)
BEGIN
IF t is not empty THEN
Traverse left subtree of t
Traverse right subtree of t
Process root node of t
END
END Traverse;
2
1
5
3
9
6 7
8
4
+
××
−2
8 1
3 4
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Operands & rules
Operands may be used only as frequently as they appear
All intermediate results must be positive integers
On the SBS program, operands are split into large and small,
but this does not a¤ect our approach
Operands do not exceed 100 and target is more than 100
this means that at least two operands must be used
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Reaching the target
Target may be impossible to reach
Some targets may be reached in many ways
# possible expressions is huge (see later)
Intermediate results could over‡ow or div zero might occur
code to generate trees must check for these
Many trees are equivalent (they generate the same target)
Other equivalences –commutative & associative operators
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Catalan number
For n operands we have exactly n 1 operators
Tree has n operand nodes (interior nodes) plus n 1
operators (leaf nodes), giving 2n 1 nodes in total
Start with “interior tree” generated by the n 1 interior
operator nodes
The number of these is given by the Catalan number
Cn 1 =
(2n 2)!
(n 1)!n!
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
# operators
There are four possible operators and these may be chosen
n 1 times with replacement
Thus, the number of choices here is 4n 1
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
# operands
Now graft n operand nodes onto this tree
Since order matters and operands can only be used once, the
number of ways of doing this is the number of permutations
of n objects chosen from 6
This is
6!
(6 n)!
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
The number of trees
The multiplication rule now gives us the total number of trees
with n operands, denoted Tn
Tn =
(2n 2)!
(n 1)!n!
4n 1 6!
(6 n)!
This expression ignores the possibilities of semantically
equivalent trees
Also ignores unsuitable trees such as those which generate
division by 0 or improper …nal or intermediate results
Examples: “5 7” or “25/4” or “10/(3 3)”
Code checks for these and only builds proper trees
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
# possible expression trees
Simplifying the quotient Tn/Tn 1 yields a useful recurrence
Thus, the number of trees may also be expressed recursively
as T1 = 6 and
Tn =
8 (2n 3) (7 n)
n
Tn 1 if 2 n 6
n Tn
1 6
2 120
3 3, 840
4 115, 200
5 2, 580, 480
6 30, 965, 760
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Algorithm
How to generate a forest this large?
We need to generate all possible expression trees with n
operand nodes and n 1 operator nodes (total 2n 1 nodes)
for 2 n 6
Tree with just one node (one for each of the original 6
operands) give us initial nursery
At any stage, to get all trees with m operand nodes, we graft
together all possible combinations of trees with operand node
counts adding up to m
Need to keep track of which operands have already been used
(cannot use an operand twice)
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Create trees by grafting old ones
We need to partition the nodeset into 2 parts
For example, to get all trees with 6 operand nodes we graft:
All trees with 1 node to all with 5 nodes, and
All trees with 2 nodes to all with 4 nodes, and
All trees with 3 nodes to all with 3 nodes
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Lily vs machine
L&N Episode; time 3:15
Contestant gets 1 o¤ target
Lily …nds exact answer using 5 operands
Excel model …nds exact answer 2 or 3 sec using 4 operands
ditto for Delphi model, which takes about 100 milliseconds
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Delphi version of number game
This was created as the Excel version is slow
It uses the same algorithm but coded into Object Pascal
It runs about 100 times as fast
Much better for the harder problems
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Letters and Numbers as a student assignment
In Bond University’s (now defunct) Bachelor of IT, there was
just one mathematics unit, known as Analytical Toolkit
It consists of a typical set of introductory discrete
mathematics topics, ending with a few weeks of very basic
introduction to probability and statistics
At Bond, Sem 1 of 2012, we set an assignment for the
students based on L & N
Mathematical background of a typical student is very poor
Also, most students had no programming experience
How could we present enough background material for the
students …rstly to understand the problem, and secondly to
implement some kind of a solution?
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
A reduction of problem scope
We:
reduced the scope of the problem by relaxing the Numbers
Game to 3 operands instead of 6,
cast the problem into an environment where at least some of
the solution logic may be expressed without having to write
code, and
supplied the class with some skeleton code which outlines an
overall solution strategy
These were achieved by putting a reduced version of the
problem into Microsoft Excel 2010 with VBA code and Excel
formulae and tables
For the Letters part of the problem the class was supplied
with public domain word lists, again in Excel
A session on elementary VBA was taught
Based on student feedback, this exercise was a success
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Student feedback on the assignment
Although the class was small and the number of responses
even smaller, feedback was uniformly positive
"Very interesting assignment for applying algorithms to solve
problems"
"Found it to be quite fun and enjoyable however due to my
programming background it was easy."
"Although there was a steep learning curve I found this
assignment very interesting"
History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion
Conclusion
The games from Letters & Numbers are shown to be useful
vehicles for showcasing fundamentals of computation and
mathematics
A wide variety of typical CS & Discrete Mathematics concepts
in a degree program apply to the numbers game, making it a
useful teaching vehicle with wide application
Requirements for solving the Numbers Game strongly a¢ rm
why Mathematics is important in a CS or IT degree
We need more maths ambassadors/evangelists to early grades,
where lifelong attitudes to maths are usually formed
We need more people like ***Lily Serna***, an excellent role
model for young girls in particular

More Related Content

What's hot

Preparation Data Structures 10 trees
Preparation Data Structures 10 treesPreparation Data Structures 10 trees
Preparation Data Structures 10 trees
Andres Mendez-Vazquez
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
Preparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representationPreparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representation
Andres Mendez-Vazquez
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
Intro C# Book
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
Saurabh Mishra
 
Binary Mathematics Sample Lesson
Binary Mathematics Sample LessonBinary Mathematics Sample Lesson
Binary Mathematics Sample Lesson
Joji Thompson
 
NTCIR11-Math2-PattaniyilN_slides
NTCIR11-Math2-PattaniyilN_slidesNTCIR11-Math2-PattaniyilN_slides
NTCIR11-Math2-PattaniyilN_slides
Nidhin Pattaniyil
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
Intro C# Book
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
Dwight Sabio
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
Anusruti Mitra
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
teach4uin
 
Digital Basics
Digital BasicsDigital Basics
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
sansaristic
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
Data Structure
Data StructureData Structure
Data Structure
Karthikeyan A K
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
Zaid Shabbir
 

What's hot (20)

Preparation Data Structures 10 trees
Preparation Data Structures 10 treesPreparation Data Structures 10 trees
Preparation Data Structures 10 trees
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Preparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representationPreparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representation
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary Mathematics Sample Lesson
Binary Mathematics Sample LessonBinary Mathematics Sample Lesson
Binary Mathematics Sample Lesson
 
NTCIR11-Math2-PattaniyilN_slides
NTCIR11-Math2-PattaniyilN_slidesNTCIR11-Math2-PattaniyilN_slides
NTCIR11-Math2-PattaniyilN_slides
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Lecture7 data structure(tree)
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
Digital Basics
Digital BasicsDigital Basics
Digital Basics
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Data Structure
Data StructureData Structure
Data Structure
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 

Viewers also liked

Bizdata.mn bulletin 2006-aug
Bizdata.mn bulletin 2006-augBizdata.mn bulletin 2006-aug
Bizdata.mn bulletin 2006-aug
Naranchimeg Batjargal
 
Ditek TSS1 Data Sheet
Ditek TSS1 Data SheetDitek TSS1 Data Sheet
Ditek TSS1 Data Sheet
JMAC Supply
 
Facebook Unfriend Study
Facebook Unfriend StudyFacebook Unfriend Study
Facebook Unfriend Study
Wappow
 
Reisebericht Feder - April/Mai 2014 PL
Reisebericht Feder - April/Mai 2014 PLReisebericht Feder - April/Mai 2014 PL
Reisebericht Feder - April/Mai 2014 PL
Louisa Netzwerk
 
Trademag only tech_merch_лапшова+credentials_2_wpm
Trademag  only tech_merch_лапшова+credentials_2_wpmTrademag  only tech_merch_лапшова+credentials_2_wpm
Trademag only tech_merch_лапшова+credentials_2_wpmTrademag
 
Nimax айдентика
Nimax айдентикаNimax айдентика
Nimax айдентикаMSG agency
 
LOL&POP карамель ручной работы
LOL&POP карамель ручной работыLOL&POP карамель ручной работы
LOL&POP карамель ручной работы
Alona Tokar
 
Paradigma conductual maritza
Paradigma conductual maritzaParadigma conductual maritza
Paradigma conductual maritza
Ytza Sole
 
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTANUNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
Muhammad Adeel Khan
 
Subversion Schulung
Subversion SchulungSubversion Schulung
Subversion Schulung
Jörn Dinkla
 
The 'H' Brothers
The 'H' BrothersThe 'H' Brothers
The 'H' Brothers
Amie Neubecker
 
Heranwachsen mit dem Social Web
Heranwachsen mit dem Social WebHeranwachsen mit dem Social Web
Heranwachsen mit dem Social Web
Jan Schmidt
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
Kislay Bhardwaj L|PT,ECSA,C|EH
 
Sales — a manual for beginners and advanced
Sales — a manual for beginners and advancedSales — a manual for beginners and advanced
Sales — a manual for beginners and advanced
IKRA Creative agency
 
Flowcharts (1)
Flowcharts (1)Flowcharts (1)
Flowcharts (1)
Emmanuel Alimpolos
 
Scope proposal-ecommerce-website
Scope proposal-ecommerce-websiteScope proposal-ecommerce-website
Scope proposal-ecommerce-website
maxtra
 
Motorización de buques (2011)
Motorización de buques (2011)Motorización de buques (2011)
Motorización de buques (2011)
Tandanor SACIyN
 

Viewers also liked (20)

Diæt og Motivation
Diæt og MotivationDiæt og Motivation
Diæt og Motivation
 
Bizdata.mn bulletin 2006-aug
Bizdata.mn bulletin 2006-augBizdata.mn bulletin 2006-aug
Bizdata.mn bulletin 2006-aug
 
Ditek TSS1 Data Sheet
Ditek TSS1 Data SheetDitek TSS1 Data Sheet
Ditek TSS1 Data Sheet
 
Facebook Unfriend Study
Facebook Unfriend StudyFacebook Unfriend Study
Facebook Unfriend Study
 
Testo 890
Testo 890 Testo 890
Testo 890
 
Reisebericht Feder - April/Mai 2014 PL
Reisebericht Feder - April/Mai 2014 PLReisebericht Feder - April/Mai 2014 PL
Reisebericht Feder - April/Mai 2014 PL
 
Trademag only tech_merch_лапшова+credentials_2_wpm
Trademag  only tech_merch_лапшова+credentials_2_wpmTrademag  only tech_merch_лапшова+credentials_2_wpm
Trademag only tech_merch_лапшова+credentials_2_wpm
 
Nimax айдентика
Nimax айдентикаNimax айдентика
Nimax айдентика
 
LOL&POP карамель ручной работы
LOL&POP карамель ручной работыLOL&POP карамель ручной работы
LOL&POP карамель ручной работы
 
Paradigma conductual maritza
Paradigma conductual maritzaParadigma conductual maritza
Paradigma conductual maritza
 
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTANUNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
UNIVER PNEUMATIC Cylinder-UNIVER PAKISTAN
 
Subversion Schulung
Subversion SchulungSubversion Schulung
Subversion Schulung
 
Akos Moravanszky, Poza znakami
Akos Moravanszky, Poza znakamiAkos Moravanszky, Poza znakami
Akos Moravanszky, Poza znakami
 
The 'H' Brothers
The 'H' BrothersThe 'H' Brothers
The 'H' Brothers
 
Heranwachsen mit dem Social Web
Heranwachsen mit dem Social WebHeranwachsen mit dem Social Web
Heranwachsen mit dem Social Web
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
 
Sales — a manual for beginners and advanced
Sales — a manual for beginners and advancedSales — a manual for beginners and advanced
Sales — a manual for beginners and advanced
 
Flowcharts (1)
Flowcharts (1)Flowcharts (1)
Flowcharts (1)
 
Scope proposal-ecommerce-website
Scope proposal-ecommerce-websiteScope proposal-ecommerce-website
Scope proposal-ecommerce-website
 
Motorización de buques (2011)
Motorización de buques (2011)Motorización de buques (2011)
Motorización de buques (2011)
 

Similar to L&NDeltaTalk

Q
QQ
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
Programming Exam Help
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
hccit
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
Programming Exam Help
 
Winter 10 Undecidability.pptx
Winter 10 Undecidability.pptxWinter 10 Undecidability.pptx
Winter 10 Undecidability.pptx
HarisPrince
 
lecture 9
lecture 9lecture 9
lecture 9
sajinsc
 
Assignment 2 (1) (1).docx
Assignment 2 (1) (1).docxAssignment 2 (1) (1).docx
Assignment 2 (1) (1).docx
pinstechwork
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
Bipul Roy Bpl
 
ID3 Algorithm
ID3 AlgorithmID3 Algorithm
ID3 Algorithm
CherifRehouma
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
W 9 numbering systemW 9 numbering system
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
Sandeep Jindal
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
Tariq Rashid
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
vafopoulos
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
Land Surveyors United Community
 

Similar to L&NDeltaTalk (20)

Q
QQ
Q
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Winter 10 Undecidability.pptx
Winter 10 Undecidability.pptxWinter 10 Undecidability.pptx
Winter 10 Undecidability.pptx
 
lecture 9
lecture 9lecture 9
lecture 9
 
Assignment 2 (1) (1).docx
Assignment 2 (1) (1).docxAssignment 2 (1) (1).docx
Assignment 2 (1) (1).docx
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
ID3 Algorithm
ID3 AlgorithmID3 Algorithm
ID3 Algorithm
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
 

L&NDeltaTalk

  • 1. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Letters & Numbers: A Vehicle to Illustrate Mathematical & Computing Fundamentals Lighthouse Delta 2013 Steve Sugden, QUT Phil Stocks, Bond University 28/11/2013
  • 2. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion SBS Letters & Numbers Letters & Numbers is a popular game show on SBS Fairly new to Australia, but not to Europe Based on the French des Chi¤res et des Lettres (similar to UK Countdown) According to Wikipedia "the oldest TV programme still broadcast on French Television and one of the longest-running game shows in the world." Hosted by Richard Morecroft, David Astle (cryptic crossword writer) & Lily Serna (UTS maths HDR student)
  • 3. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Anagrams In the 1990s at Bond I taught the Data Structures subject about 15 times (MODULA-2, Oberon-2, Delphi) One of the topics I included was bag - a generalization of set where elements can occur more than once Implement by an array of cardinals (frequencies) Index type of array maps to the set of possible bag elements For example, a bag of characters (letters) can be used to check for anagrams or sub-words of a given string Newspaper anagram-type games are common: The Australian: "Circuit Breaker", Courier-Mail: "Jumble", GC Bulletin: "Focus", etc. Just what is needed for the Letters part of L & N
  • 4. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Letters game in Excel/VBA I have a strong preference for the Wirth family of languages, but these are out of vogue nowadays Not a huge fan of VB, but given my extensive work with Excel, it made sense for me to get up to speed with VBA Was not a very di¢ cult task to implement the bag abstraction in VBA using a frequency array The code simply computes the bag of the entered word, and checks every word in the dictionary, looking for sub-bags
  • 5. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Example Bag for the "word" RETAIONBE: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 1 0 0 2 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 Some words whose bags are sub-bags of this are BARITONE, REOBTAIN (the bags for these are equal, i.e., the words are anagrams): A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0
  • 6. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Numbers game Given six numbers (operands) and a target number, we seek an expression which evaluates to the target, and includes at least two of the six inputs (operands) plus any number of instances of +, , , / Operands can be used without replacement (once only) but operator use is unrestricted Parentheses may be inserted wherever required Example: Make the target 547 from a subset of the numbers 4, 7, 8, 10, 50, 75 Solution: 547 = (10 50) + (4 10) + 7? Is this correct?
  • 7. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion A more interesting challenge Solving the "numbers" part of the game on a computer is more challenging Arithmetic expressions are not linear like strings They are trees with a recursive structure
  • 8. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Binary tree A binary tree is usually de…ned in a recursive fashion Tree ::= empty j (LTree, Root, RTree) In other words, a binary tree is either empty (nothing at all) or it consists of a sequence of three objects: the left (sub-)tree, the root node, the right (sub-)tree This is a typical BNF (Backus-Naur) recursive syntax de…nition, and may be compared mathematically to a recurrence relation
  • 9. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Arithmetic expression tree "No-one, I think, is in my tree - I mean it must be high or low" (John Lennon, Strawberry Fields Forever, 1967) Binary tree associated with an arithmetic expression (AE) internal nodes: operators external nodes: operands Example: AE tree for (2 (8 1) + (3 4)) + ×× −2 8 1 3 4
  • 10. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion In-order tree traversal PROCEDURE Traverse(t : Tree); // This mode of traversal generates a normal (in-…x) AE. // Parens necessary to avoid ambiguity: (2 (8 1) + (3 4)) BEGIN IF t is not empty THEN Traverse left subtree of t Process root node of t Traverse right subtree of t END END Traverse; 3 1 2 5 6 7 9 8 4 + ×× −2 8 1 3 4
  • 11. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Post-order tree traversal PROCEDURE Traverse(t : Tree); // This mode of traversal generates a post…x AE // Parens unnecessary: 281 34 + (HP calculators) BEGIN IF t is not empty THEN Traverse left subtree of t Traverse right subtree of t Process root node of t END END Traverse; 2 1 5 3 9 6 7 8 4 + ×× −2 8 1 3 4
  • 12. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Operands & rules Operands may be used only as frequently as they appear All intermediate results must be positive integers On the SBS program, operands are split into large and small, but this does not a¤ect our approach Operands do not exceed 100 and target is more than 100 this means that at least two operands must be used
  • 13. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Reaching the target Target may be impossible to reach Some targets may be reached in many ways # possible expressions is huge (see later) Intermediate results could over‡ow or div zero might occur code to generate trees must check for these Many trees are equivalent (they generate the same target) Other equivalences –commutative & associative operators
  • 14. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Catalan number For n operands we have exactly n 1 operators Tree has n operand nodes (interior nodes) plus n 1 operators (leaf nodes), giving 2n 1 nodes in total Start with “interior tree” generated by the n 1 interior operator nodes The number of these is given by the Catalan number Cn 1 = (2n 2)! (n 1)!n!
  • 15. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion # operators There are four possible operators and these may be chosen n 1 times with replacement Thus, the number of choices here is 4n 1
  • 16. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion # operands Now graft n operand nodes onto this tree Since order matters and operands can only be used once, the number of ways of doing this is the number of permutations of n objects chosen from 6 This is 6! (6 n)!
  • 17. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion The number of trees The multiplication rule now gives us the total number of trees with n operands, denoted Tn Tn = (2n 2)! (n 1)!n! 4n 1 6! (6 n)! This expression ignores the possibilities of semantically equivalent trees Also ignores unsuitable trees such as those which generate division by 0 or improper …nal or intermediate results Examples: “5 7” or “25/4” or “10/(3 3)” Code checks for these and only builds proper trees
  • 18. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion # possible expression trees Simplifying the quotient Tn/Tn 1 yields a useful recurrence Thus, the number of trees may also be expressed recursively as T1 = 6 and Tn = 8 (2n 3) (7 n) n Tn 1 if 2 n 6 n Tn 1 6 2 120 3 3, 840 4 115, 200 5 2, 580, 480 6 30, 965, 760
  • 19. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Algorithm How to generate a forest this large? We need to generate all possible expression trees with n operand nodes and n 1 operator nodes (total 2n 1 nodes) for 2 n 6 Tree with just one node (one for each of the original 6 operands) give us initial nursery At any stage, to get all trees with m operand nodes, we graft together all possible combinations of trees with operand node counts adding up to m Need to keep track of which operands have already been used (cannot use an operand twice)
  • 20. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Create trees by grafting old ones We need to partition the nodeset into 2 parts For example, to get all trees with 6 operand nodes we graft: All trees with 1 node to all with 5 nodes, and All trees with 2 nodes to all with 4 nodes, and All trees with 3 nodes to all with 3 nodes
  • 21. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Lily vs machine L&N Episode; time 3:15 Contestant gets 1 o¤ target Lily …nds exact answer using 5 operands Excel model …nds exact answer 2 or 3 sec using 4 operands ditto for Delphi model, which takes about 100 milliseconds
  • 22. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Delphi version of number game This was created as the Excel version is slow It uses the same algorithm but coded into Object Pascal It runs about 100 times as fast Much better for the harder problems
  • 23. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Letters and Numbers as a student assignment In Bond University’s (now defunct) Bachelor of IT, there was just one mathematics unit, known as Analytical Toolkit It consists of a typical set of introductory discrete mathematics topics, ending with a few weeks of very basic introduction to probability and statistics At Bond, Sem 1 of 2012, we set an assignment for the students based on L & N Mathematical background of a typical student is very poor Also, most students had no programming experience How could we present enough background material for the students …rstly to understand the problem, and secondly to implement some kind of a solution?
  • 24. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion A reduction of problem scope We: reduced the scope of the problem by relaxing the Numbers Game to 3 operands instead of 6, cast the problem into an environment where at least some of the solution logic may be expressed without having to write code, and supplied the class with some skeleton code which outlines an overall solution strategy These were achieved by putting a reduced version of the problem into Microsoft Excel 2010 with VBA code and Excel formulae and tables For the Letters part of the problem the class was supplied with public domain word lists, again in Excel A session on elementary VBA was taught Based on student feedback, this exercise was a success
  • 25. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Student feedback on the assignment Although the class was small and the number of responses even smaller, feedback was uniformly positive "Very interesting assignment for applying algorithms to solve problems" "Found it to be quite fun and enjoyable however due to my programming background it was easy." "Although there was a steep learning curve I found this assignment very interesting"
  • 26. History Numbers game How many trees? Algorithm Lily vs machine L&N assignment Conclusion Conclusion The games from Letters & Numbers are shown to be useful vehicles for showcasing fundamentals of computation and mathematics A wide variety of typical CS & Discrete Mathematics concepts in a degree program apply to the numbers game, making it a useful teaching vehicle with wide application Requirements for solving the Numbers Game strongly a¢ rm why Mathematics is important in a CS or IT degree We need more maths ambassadors/evangelists to early grades, where lifelong attitudes to maths are usually formed We need more people like ***Lily Serna***, an excellent role model for young girls in particular