Year 1 CS

CS Blog Post – Pseudocode

In this week, we began our learning about programing. Generally, we tried to solve simple arithmetic and logical problems by writing pseudocode. It’s much brief than compelling language as we needn’t to load and store data repeatedly. But it’s still very basic and direct, lack of many complex method compared to high-level language. In real life application, pseudocode is just like an outline for an article, make the programmer more clear about each part and explain the function in simple words.

Decision-Making process

Decision-Making process is a model that used to solve a problem in computing thinking. It’s useful skill to program efficiently. It can be classified into 4 stages – identification, development, selection and implementation. During the identification stage, we need to identify, understand and formulate the problem. It means we need to convert the problem in nature language into arithmetic version -identify the variable, original value, and expected value. Then, in the development stage, we come up with different methods that can input the original value and output expected value. Finally, in the implementation stage, we will choose the most efficient method.

Retrieved from ETERNAL SUNSHINE OF THE IS MIND

Properties of Algorithm

In definition, algorithm is a set of step-by-step clear instructions to solve a problem in a reasonable amount of time for all general cases. A computer carries many detailed algorithm in order to satisfy diverse functions within in computer. ‘All general cases’ means that whatever the value it’s include exception error, the program using the algorithm can output the correct value (or error notification). So many programs testify the whole program or each part by inputing different values.

Retrieved from What is an Algorithm?

There are several basic properties of good algorithm. The first one is finiteness. A algorithm must have a number of finite instructions to solve the problem. The next is definiteness. A algorithm must have very clear and specific instructions to tell the computer what to do. Then, an algorithm need to have initial quantities that input to the program and quantities of output which relate to the input. Finally, effectiveness is also important as the time of process must be finite.

Expressions for Algorithm

There are different ways to describe the same algorithm. In our learning, there are generally four ways to represent it – natural language, flow chart, pseudocode and programming language. Natural language is using human language that we speak like English, Chinese and so on to describe the algorithm in complete sentences. Usually the description is quite verbose and ambiguous to express the method definitely. The flow chart is a kind of formalized graphic representation to show each step(with its attribution in different shapes) and the sequence. Then, pseudocode is an artificial language that combine nature language and program language together, more brief and efficient than natural language description. Finally, programming language is an artificial language that can directly communicate with the computer and create programs as the computer can convert it into assembly language and finally into machine code.

Retrieved from The pseudocode editor

Pseudocode approved notations and best practices

There are several notations for pseudocode in order to become readable for others. Some of them are just as same as the function in programming language but more simple.

Input A – the user inputs some data (any type) into a variable called A.

Output – the program output the data of a variable called A.

While (expression) – end while – a loop that if the expression is true, the program will execute the statement between while and end while repeatedly. For do – while(expression), it will check the expression to know if continue the next time after statements between do and while have been executed.

For – a counting loop, there is a initial variable (usually 0 or 1) in the for loop, then each time the variable will + 1 and there is an expression used to check if the it reach the limitation. So that programer can regulate the time for the loop.

If (expression) – else if(expression) – else – the program will check whether the expression is true after if, if true, do the statement behind and end. If not, check the expression in else if in sequence. If all statements are false, the program will follow the statement after else.

Pseudocode+Notations+I.jpg
Retrieved from problem analysis and solution representation

About IB approved pseudocode, I still can’t access to the address as I don’t have an account in IBO, so…..

Pseudocode examples/exercises

Rewrite:

A = 1
while A =< 2
           output “This will be printed twice.”
end while
C = 1
while C < 5
           output “This message will be printed four times.”
end while

Example 1:

input A, B
output A*B

Example 2:

input A
if A != 5 OR A != 6
          output “incorrect.”
          input A
end if

Example 3:

output “Enter a number.”
input A
if A > 0 AND A < 10
          output “blue”
else if A > 10 AND A < 20
         output “red”
else if A > 20 AND A < 30
        output “green”
else
        output “not a correct color option”
end if

Example 4:

A = 0
while A <= 100
           output A
           A = A + 5
end while

Example 5:

A  = 0
Output “enter a number”
input B
while A <= B
         output A
         A = A + 2
end while

Example 6:

output “enter five number”.
input A, B, C, D, E
L = A
S = A
if B > L
     L = A
else if B < S
     S = B
end if
if B > L
     L = B
else if B < S
     S = B
end if
if C > L
     L = C
else if C < S
     S = C
end if
if D > L
     L = D
else if D < S
     S = D
end if
if E > L
     L = E
else if E < S
     S = E
end if
output (A+B+C+D+E)/5
output L S

Example 7:

output “enter a number”
input A
if A % 2 = 0
    output “even”
else
    output “odd”
end if

Centrally Controlled Systems, Distributed Systems, Autonomous Agent (for HL)

For centrally controlled systems, it a dedicated computer system that can control all parts of the computer and do the calculation, makes sure every components function well. All computing done at a central location by terminals. The computer itself may control all the peripherals directly or via terminal. The advantage for this system is lower operational costs, greater security and less administrative overhead and backup complexity. But Clients need to be able to connect efficiently and effectively to it.

For distributed system, it is a system that components located on networks computer and work together through passing messages, each component will take its own calculation and interact with the whole system. Even without the connection to the central system the function, the individual part can do its own job. They are easy to expand, adding or changing new parts. However, they are usually costly and require for additional hardwares. Backup of the system requires more bandwidth or resources at each site leads to higher complexity for the whole system.

centralized_example.png

distributed_example.png
Retrieved from Intro to Distributed Version Control

In definition, autonomous agent is an object with a intelligent program that enable it to make its own decision. Generally it have three properties – limited ability to perceive its environment, process the environment and calculate an action, result a force, and no global plan/leader. For vehicles, there are three stages to perform how it makes decision – action – selection, steering – force, and low motion.

Personal Experience

This week, we discussed properties and expressions of algorithm and show our understanding by writing pseudocode. For HL topic, we learned autonomous agent. During the class, we also watched a model with several control systems and sensors to have a review for previous HL topic content.

Compared to writing assembly language, I feel much better for writing pseudocode as I have practiced writing it and high-level language before. It’s just fine for me to come up with the idea about how to deal with the question, but I need to pay attention to the details to avoid careless mistakes.

In the future, the basic knowledge of pseudocode will help me write the real program and get a clear idea before using the high-level programing language. In IB exam, most questions need to be done by pseudocode, so I still have lots of pseudocode practices in next two years.

That’s all for this week, I feel better for this topic than previous class and I am much interested in it. I think I will be more active in the class next week.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s