Send
Close Add comments:
(status displays here)
Got it! This site "creationpie.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Divide and conquer or be conquered
1. Divide and conquer or be conquered
This page covers a fundamental problem solving strategy (in computer science and other areas) called divide and conquer.
Some background is needed before delving into selected Bible verses.
Divide and conquer problem solving techniques are used in many areas.
military operations
business operations
political operations
problem-solving in general
Divide and conquer problem solving techniques have been refined and carefully analyzed in the area of algorithmic problem solving in the field of computer science.
2. Maze demo
Here is a animation demo of a top-down maze generation process.
3. Divide and conquer: Top-down and bottom-up
4. Divide and conquer: Top-down and bottom-up
1 Start design at goal
2 Break design goal into parts
3 Break design parts into subparts
4 Break design subparts into more parts
5 Implement the parts with unit tests
6 Combine the parts up the tree - unit tests
7 Combine the parts up the tree - unit tests
8 To original goal is achieved - unit tests
A divide and conquer problem solving method starts with a goal.
The problem is broken down in a top-down or backward-chaining manner as part of the solution design.
The solution is implemented in a bottom-up or forward-chaining manner as part of the solution implementation.
At each point in the implementation, unit testing is added for each part and abstractions made as needed.
5. Problem solving: divide and conquer
A
divide and conquer problem solving method is a top-down method that breaks a problem into smaller parts, solves each smaller part, and combines the solution (in a bottom-up manner) to solve the original problem.
Identify
Define
Design top-down, backward-chaining
Implement bottom-up forward-chaining
Evaluate
6. Divide and conquer
Divide each difficulty into as many parts as is feasible and necessary to resolve it René Descartes (French philosopher, mathematician and statistician)
7. Computer science
Fallacy:
You should require beginning programming students to use top-down programming.
Problem solving in computer science is best done using
top-down programming.
top-down programming
goal-driven programming
backward-chaining logic
Why do many computer science programs require beginning students to do "
top-down programming"?
8. Top-down programming
Question to famous computer scientist
Tony Hoare (British computer scientist) . Why is it so hard to teach (or require) beginning programmers top-down programming?
9. Top-down programming
You cannot teach beginners top-down programming, because they don't know which end is up. Tony Hoare.
Problem-solving methodology:
Identify the problem.
Define the problem.
Design top-down solution (decomposition).
Implement bottom-up implementation (composition).
Evaluate the results.
Compare to Waterfall method,
SDLC (Systems Development Life Cycle), etc.
10. Top-down programming
Fallacy:
One should implement a computer program in a top-down manner.
The phrase "
top-down programming" is deceptive. Have you ever tried to write a program "
top-down"?
Do it once and you will see that it does not work very well.
The phrase "
top down programming" refers to a "
top-down program design" and then a "
bottom-up program implementation".
Many people try to do "
top down programming" by doing "
top-down coding".
Some teachers who have never really used the method will teach this fallacy to their students. How would you define a "
programmer"?
11. Top-down vs. bottom-up
1 What goal?
2 Wrong goal
3 Give up
4 Distracted
A top-down design insures one will get to the goal.
A bottom-up design may require extra work and may not get to the goal.
12. Fix-it decision tree
1 First decision
2 Second decision
3 True positive
4 True negative
5 False positive
6 False negative
7 Decision tree
13. Maze generation
1 Maze 1
2 Maze 2
3 Maze 3
4 Maze 4
5 Maze 5
6 Maze 6
7 Maze 7
8 Maze 8
9 Maze 9
10 Maze 10
11 Maze 11
12 Maze 12
13 Maze 13
14 Maze 14
15 Maze 15
Web site:
In-line SVG (formatter Lua)
Lua to SVG
JavaScript and SVG
JavaScript and SVG and D3
R
Julia
Python
Java
C#
14. Goal
A divide and conquer problem solving method starts with a goal, here labeled "
1". Assume that this problem is too complicated to be easily solved and is therefore broken into parts. Here, division by two is used.
A not-so-easy-to-read gray with red outline is used for the top-down design phase as designs often change and are not always as clear as one would like.
15. Split
The problem "
1" is split into two parts "
2" and "
3".
16. Split again
The problems "
2" and "
3" need split.
Problem "2" is split into problems "4" and "5".
Problem "3" is split into problems "5" and "7".
17. Split again and solve
Each of problems "
4", "
5", "
6" and "
7" are split into parts.
18. Design
During the top-down design, code is not written unless some prototype is needed to verify architecturally significant parts of the design.
Something is architecturally significant if not being able to do that part will cause the entire project to fail.
19. UML
20. Solve the leaves of the problem
The leaves of the problem are then solved.
In software engineering, unit tests are created for each leaf.
Those solutions will be worked back up the tree until the original goal is solved.
21. Continue up the tree
Continue composing the solutions bottom-up to solve nodes up the tree.
In software engineering, unit tests are created for each node.
22. Continue up the tree.
Continue composing the solutions bottom-up to solve nodes up the tree.
In software engineering, unit tests are created for each node.
23. Composition
The solutions to each of the problems at the leaves are then passed back up the tree and combined. This is called composition.
In software engineering, unit tests are created for each node.
If anything goes wrong during the process, adjustments need to be made.
24. Pattern
The pattern is as follows.
Design a solution, decomposing parts top-down into smaller subproblems (down the tree).
Implement the solution, composing parts bottom-up into solving subproblems (up the tree).
25. Top-down programming
Many teachers without real world experience will often teach top-down programming to students as if one should actually do programming that way - literally.
A better way is to first design (in the head, on paper, etc.) the solution top-down and then implement that solution bottom-up. Each part of the bottom-up process has associated unit test code to test that part of the implemented solution.
The entire process is called top-down programming but the actual coding process is best done bottom-up after the top-down design.
Whenever something does not work as expected during the bottom-up implementation, the design is revisited, top-down, and modified. Hopefully not too much work from the bottom needs to be changed or lost due to the changed design.
26. Phone tree
A traditional phone tree is based in this idea, though with, say, a split of more than two.
27. Tree structures
1 Top down
2 Backward chaining
3 Top down - flipped
4 Backward chaining - flipped
There are various names for a top-down backward-chaining divide and conquer problem solving strategy.
Topologically they are all the same since one can rotate and change the length of the branches as desired and it is the same tree.
28. Top down
Often, a top-down problem solving method diagram has the goal at the top. This is the way a tree is often drawn in computer science but is an upside down tree in the real world (root at the top, leaves at the bottom)
29. Flipped top down
The goal could be drawn at the bottom with the splits going upwards. This is still a top-down method.
To go down the river of a river flowing north, one goes south.
To go up the valley of a valley with lowest point in the north , one goes south.
It all depends on your point of view.
30. Backward chaining
A backward chaining method starts with a goal and works backward. Just like a top-down method.
Do you see any difference in what is actually done in using a divide and conquer problem solving method?
31. Flipped backward chaining
A backward chaining method can be flipped with the goal on the right. It is still backward chaining.
People whose languages, such as Arabic and Hebrew, are read right to left, may be more comfortable with a backward chaining method drawn this way.
32. Linear sequences
1 Top down
2 Backward chaining
3 Top down - flipped
4 Backward chaining - flipped
Not all
trees have two or more branches. Some problems are best split into just one other part. Such a sequence is called a serial sequence. A tree-structure is needed by many problems in computer science. Most people will only need to understand the linear sequence.
And that top-down or bottom-up sequence can be viewed in any direction.
This happens when a sequence of events in time need to be accomplished, each before the next one can start.
It is the same idea. Here are some visualizations - topologically all the same.
33. Top-down - root at the top
Remember that
top-down has to do with the
direction of the arrows from the root, not the physical location based on how the tree is drawn.
The diagrams depict the decomposition. The composition is in the opposite direction.
34. Top-down - root at the bottom
35. Backward-chaining - root at the right
36. Backward-chaining - root at the left
37. Summary
At all times, the goal and method remains the same. It is only how the diagram is drawn that is changed.
There are many ways to depict a divide and conquer problem solving method. These method work from the root down to the leaves and include the following.
top-down
backward-chaining
In a similar manner, a bottom-up or forward-chaining method starts with the leaves and works towards the root - or goal, regardless of how the diagram is drawn.
38. Divide and conquer or be conquered
A house divided cannot stand.
Luke 11:17 But he, knowing their thoughts, said unto them, Every kingdom divided against itself is brought to desolation; and a house divided against a house falleth. [kjv]
There are three primary ways that a "
division" can be accomplished between "
entities" in a divide (decompose) and conquer (composition) method.
Divide oneself.
Divide others.
Divide everyone (including, perhaps, oneself).
39. Divide oneself
This division can be expressed as "
indecision" as in "
questioning oneself".
Since not making a decision is a decision, indecision can often allow an opponent to do the division against self (or the group to which self belongs).
40. Divide others
Dividing others is a way to win against an opponent (i.e., the "
others").
41. Divide everyone
Dividing "
everyone" of concern, including "
oneself", is a way to weaken the "
everyone".
This is expressed by the Bible saying, "
A house divided cannot stand".
42. Examples
Let us look at some examples of the above ways of "
division".
43. Acts 23:2,7,10 Divide and conquer
Acts 23:2 And the high priest Ananias commanded them that stood by him to smite him on the mouth. [kjv]
23:7 And when he had so said, there arose a dissension between the Pharisees and the Sadducees: and the multitude was divided. [kjv]
23:10 And when there arose a great dissension, the chief captain, fearing lest Paul should have been pulled in pieces of them, commanded the soldiers to go down, and to take him by force from among them, and to bring him into the castle. [kjv]
In Acts 23, the high priest Ananias had in mind to
divide Paul, taking the offense and ordered him to be smitten.
Paul uses a clever
divide and conquer strategy to get out of the situation. The civil authority, fearing Paul may himself be literally
divided, takes action.
44. Acts 23:2
KJV: And the high priest Ananias commanded them that stood by him to smite him on the mouth.
Greek: ο δε αρχιερευς ανανιας επεταξεν τοις παρεστωσιν αυτω τυπτειν αυτου το στομα
45. Acts 23:2-5
46. Acts 23:3
KJV: Then said Paul unto him, God shall smite thee, thou whited wall: for sittest thou to judge me after the law, and commandest me to be smitten contrary to the law?
Greek: τοτε ο παυλος προς αυτον ειπεν τυπτειν σε μελλει ο θεος τοιχε κεκονιαμενε και συ καθη κρινων με κατα τον νομον και παρανομων κελευεις με τυπτεσθαι
47. Acts 23:4
KJV: And they that stood by said, Revilest thou God's high priest?
Greek: οι δε παρεστωτες ειπον ειπαν τον αρχιερεα του θεου λοιδορεις
48. Acts 23:5
KJV: Then said Paul, I wist not, brethren, that he was the high priest: for it is written, Thou shalt not speak evil of the ruler of thy people.
Greek: εφη τε ο παυλος ουκ ηδειν αδελφοι οτι εστιν αρχιερευς γεγραπται γαρ οτι αρχοντα του λαου σου ουκ ερεις κακως
49. Acts 23:6 Strategy
Acts 23:6 But when Paul perceived that the one part were Sadducees, and the other Pharisees, he cried out in the council, Men and brethren, I am a Pharisee, the son of a Pharisee: of the hope and resurrection of the dead I am called in question. [kjv]
γνους δε ο παυλος οτι το εν μερος εστιν σαδδουκαιων το δε ετερον φαρισαιων εκραζεν εν τω συνεδριω ανδρες αδελφοι εγω φαρισαιος ειμι υιος φαρισαιων περι ελπιδος και αναστασεως νεκρων κρινομαι [gnt]
Paul, on the defensive, attempts to divide and conquer his adversaries.
50. Acts 23:6
KJV: But when Paul perceived that the one part were Sadducees, and the other Pharisees, he cried out in the council, Men and brethren, I am a Pharisee, the son of a Pharisee: of the hope and resurrection of the dead I am called in question.
Greek: γνους δε ο παυλος οτι το εν μερος εστιν σαδδουκαιων το δε ετερον φαρισαιων εκραξεν εκραζεν εν τω συνεδριω ανδρες αδελφοι εγω φαρισαιος ειμι υιος φαρισαιου φαρισαιων περι ελπιδος και αναστασεως νεκρωνεγω κρινομαι
51. Acts 23:7-9 Division
52. Acts 23:7
KJV: And when he had so said, there arose a dissension between the Pharisees and the Sadducees: and the multitude was divided.
Greek: τουτο δε αυτου λαλησαντος λαλουντος εγενετο στασις των φαρισαιων και των σαδδουκαιων και εσχισθη το πληθος
53. Acts 23:8
KJV: For the Sadducees say that there is no resurrection, neither angel, nor spirit: but the Pharisees confess both.
Greek: σαδδουκαιοι μεν γαρ λεγουσιν μη ειναι αναστασιν μηδε μητε αγγελον μητε πνευμα φαρισαιοι δε ομολογουσιν τα αμφοτερα
54. Acts 23:9
KJV: And there arose a great cry: and the scribes that were of the Pharisees' part arose, and strove, saying, We find no evil in this man: but if a spirit or an angel hath spoken to him, let us not fight against God.
Greek: εγενετο δε κραυγη μεγαλη και ανασταντες οι γραμματεις τινες των γραμματεων του μερους των φαρισαιων διεμαχοντο λεγοντες ουδεν κακον ευρισκομεν εν τω ανθρωπω τουτω ει δε πνευμα ελαλησεν αυτω η αγγελος μη θεομαχωμεν
55. Acts 23:10
Acts 23:10 And when there arose a great dissension, the chief captain, fearing lest Paul should have been pulled in pieces of them, commanded the soldiers to go down, and to take him by force from among them, and to bring him into the castle. [kjv]
πολλης δε γινομενης στασεως φοβηθεις ο χιλιαρχος μη διασπασθη ο παυλος υπ αυτων εκελευσεν το στρατευμα καταβαν αρπασαι αυτον εκ μεσου αυτων αγειν εις την παρεμβολην [gnt]
Apparently the division is very noticeable.
Now the chief captain fears that Paul may be literally divided (and conquered) by being pulled into pieces.
56. Acts 23:10
KJV: And when there arose a great dissension, the chief captain, fearing lest Paul should have been pulled in pieces of them, commanded the soldiers to go down, and to take him by force from among them, and to bring him into the castle.
Greek: πολλης δε γενομενης γινομενης στασεωςευλαβηθεις φοβηθεις ο χιλιαρχος μη διασπασθη ο παυλος υπ αυτων εκελευσεν το στρατευμα καταβαν αρπασαι αυτον εκ μεσου αυτων αγειν τε εις την παρεμβολην
57. Acts 23:11 Rome
Acts 23:11 And the night following the Lord stood by him, and said, Be of good cheer, Paul: for as thou hast testified of me in Jerusalem, so must thou bear witness also at Rome. [kjv]
During this respite, Paul finds that he will bear witness for the Lord in Rome.
So by a clever divide and conquer strategy, Paul avoided being divided and conquered.
58. Acts 23:11
KJV: And the night following the Lord stood by him, and said, Be of good cheer, Paul: for as thou hast testified of me in Jerusalem, so must thou bear witness also at Rome.
Greek: τη δε επιουση νυκτι επιστας αυτω ο κυριος ειπεν θαρσει παυλε ως γαρ διεμαρτυρω τα περι εμου εις ιερουσαλημ ουτως σε δει και εις ρωμην μαρτυρησαι
59. House divided
Matthew 12:25 And Jesus knew their thoughts, and said unto them, Every kingdom divided against itself is brought to desolation; and every city or house divided against itself shall not stand: [kjv]
ειδως δε τας ενθυμησεις αυτων ειπεν αυτοις πασα βασιλεια μερισθεισα καθ εαυτης ερημουται και πασα πολις η οικια μερισθεισα καθ εαυτης ου σταθησεται [gnt]
Sometimes the word "
house" can refer to more than just a simple family "
house" as in a kingdom divided or a house divided.
60. A house divided
Abraham Lincolns "
House divided" speech was given in 1858 after accepting the Illinois Republican Party nomination for senator of the United States. The speech started as follows.
A house divided against itself, cannot stand. I believe this government cannot endure permanently half slave and half free. I do not expect the Union to be dissolved - do not expect the house to fall - but I do expect it will cease to be divided. It will become all one thing or all the other. Abraham Lincoln (16th U.S. President)
The "
house divided against itself cannot stand" is from Mark 3:25 of the Bible.
61. A piece of the sword of truth
Matthew 10:34 Think not that I am come to send peace on earth: I came not to send peace, but a sword. [kjv]
μη νομισητε οτι ηλθον βαλειν ειρηνην επι την γην ουκ ηλθον βαλειν ειρηνην αλλα μαχαιραν [gnt]
… pacem … pacem … gladium [v]
Are people (believers and non-believers) ever offended by the word of God?
Did Jesus come to bring
"peace" or to bring a "
sword"? The Latin word
"gladium" ≈ "sword" and is the source of the English word "
gladiator".
As with any saying, there can be more than one meaning and all meanings could be true (in some sense, figurative, literal, etc.).
62. End of page