I have two 4-digit arrays, both arrays consist of different numbers in themselves, like Array1:1234, Array2: 4567. Firstly, I should check if any digit of these two arrays are the same Secondly, if there is a same digit, I should check if there are any other same digits apart from last one.
How do I show this in flowchart?
CodePudding user response:
This is what a flowchart would look like using ASCII art. You may wish to use a graphical program to create a prettier picture.
.-------- .--------
/ Array1 / / Array2 /
--------' --------'
| |
----> <----
|
v
/ \
/ \ --------------
/ \ No | Find numbers | .------.
Same? ----> common to |->( Done. )
\ / | both arrays. | `------'
\ / --------------
\ /
| Yes
.-----v-----.
( Done. )
`-----------'
To represent the actual algorithm, the flow chart allows iteration by drawing a line to loop onto an earlier component in the diagram. You would use a decision box to test if the loop invariant is true and or test the stopping condition. The decision box would then either continue the loop or move to a different path of logic.
For example, to check if an array has the number 0:
.-------
/ Array /
-------'
|
---v-------
| Start at |
| beginning |
| of array |
-----------
| -----------------
<-------| Increment index |<---------------
| ----------------- |
v |
/ \ / \ |
/ \ ------------------ / \ |
/ At \ No | Compare number | / \ No |
end? ----> at current array |--> Same? ----
\ / | index with 0. | \ /
\ / ------------------ \ /
\ / \ /
| Yes | Yes
.--v-------. .--v---.
( Not found. ) ( Found. )
`----------' `------'
CodePudding user response:
This question touches a sensitive area of software development in general.
One school of thought pretends, it is beneficial to first plan out thoroughly before implementing something.
The other school of thought does not agree. They usually prefer "rapid prototyping" over painting flow charts. And with some very good and valid reasons:
Every step in software development needs a verification step (quality gate principle). How do you verify a flowchart for being correct?
Someone just invented a new programming language, the flowchart language. Just because it is graphical, it does not avoid the typical problems of programming languages: Hard to proof correctness, while execution (testing) often creates sufficient trust in the solution.
So, as for the question, since I am rather of camp (2), not so much of camp (1), my advice is: Implement your idea first, and then if someone absolutely wants it, create the flowchart from your solution. Or even better use a tool, which transforms your implementation into a flowchart (avoids transcription bugs).