Thursday, 21 February 2013

Computer Language and Algorithm

By Raul Bernardino

Introduction: The nature of the algorithm is how details of the algorithm are represented. Brookshear, J. Glenn, (2009) “It is important to emphasize the distinction between an algorithm and its representation this is analogous to the distinction between a story and a book”. Every story by nature is an abstract and concept and book is a physical representation of the story itself. The book can be translated in to several different languages and format however, the story will be remaining the same.

[1]The distinction between algorithm and representation become a problem when we are trying to communicate the algorithms. For example converts the temperature of Celsius (C) into Fahrenheit (F). It is sufficient for a meteorologist that is F should be (9/5) C + 32, however for a layperson will be arguing that is uncertainty. Therefore, the layperson needs more details information of the description. The layperson may question on why is F= (9/5) C+32 and where this 9/5 and 32 are coming from?

[2] The description should be explained that there are five different meteorologists; they are Celsius(C), Reaumur(R), Kevin(K), Rankine(RK), and Fahrenheit(F).  They had different approach of scale range of measurement of the temperature degrees. In the case of Celsius was using 5 in scale range, Reaumur’s (R) 4 and Fahrenheit’s 9 and plus 32. In the short the differences of those three individuals are C: R: F equals to 5:4:9. On the zero degree point of view C=0o, R=0o, and F=32o

Brookshear,
J. Glenn, (2009) “The representation of an algorithm requires form of language”. Computer science approaches the problems by using well define set of building block. By setting up the precise definition during the building a block can remove the uncertainty. In this case the algorithm requires details, specifics, and establishes level of uniform. The primitive also have its own syntax and semantic. Syntax refer to a symbolic while semantic refer to the meaning of the build block. If an algorithm is expressed at the details level, the certainty have a program that suitable for machine. However it is boring to the high level language. 

[3] A pseudo-code is and algorithm system notation in which ideas is expressed informally. This pseudo-code is using at the early stage of program development in which is consist of syntax and semantic. The goal is to develop algorithm consistent and concise notation for representing semantic structure. While a formal programming language is one selective programming language to program the algorithms for solution. The examples of a formal programming language are program language C, program language assembler, program language Turbo Pascal etc. 

As any form of language is a set of valid sentences in which, we can also break into two valid things: syntax and semantics. The term syntax refers to grammatical structure while the term semantics refers to the meaning of the vocabulary and symbols which is arranging within that structure. In some cases, we can see that is the grammatical or syntactically valid does not mean sensible or semantically valid too.

[4] John R. Anderson (1995) defines this syntax and semantic in his book “Cognitive psychology and its implications" as, ‘Semantics- Grammatical rules for assigning meaning to a sentence. Syntax- grammatical rules for specifying correct word order and inflectional structure in a sentence’.
However, the semantics are an individual’s own interpretation of the meaning of a "sentence" based on their prior knowledge. For example sentence "Baby milk drinks" does not have a syntactic meaning, but through semantics most people would interpret it as meaning “Baby drinks milk

Four people have to walk through the bridge with several conditions: Andrew needs one minute (1’) to cross the bridge, Blake needs two minutes (2’), Johnson needs four minutes (4’), and Kelly needs eight minutes (8’), total time need in this exercise is fifteen minutes (15’) for all of them to cross the bridge, maximum number of people to walk through together is two, and every trip must with lantern.

The solution as follows:
1.     Andrew and Johnson go first  with lantern and result of time used 4’
2.     Andrew go back with lantern needs 1’ and result of time used 5’
3.     Andrew and Blake go with lantern need 2’ and result of time used 7’
4.     Andrew go back with lantern and result of time used 8’
5.     Andrew and Kelly last go with lantern need 8’ and result of time used for last movement is15’
6.     end;

Within a time period of 15 minutes all of them are managed to get their destination. Above steps is a pseudo-code to prepare code writings into any computer languages.

References:
[1 ] J. Glenn Brookshear, (2009) Computer science: An Overview. 10th Edition, Boston: Pearson Addison Wesley, Ch 5, P.224
[2] Celsius, Fahrenheit, Kelvin, RĂ©aumur, and Rankine Temperature Conversion [Internet]. Available from:
 http://www.csgnetwork.com/tempconv.html (Accessed:  3 November 2010)
[3]  J. Glenn Brookshear, (2009) Computer science: An Overview. 10th Edition, Boston: Pearson Addison Wesley, Ch 5, P.228

[4] Syntax Vs. Semantics [Internet]. Available from: http://users.ecs.soton.ac.uk/harnad/Hypermail/Explaining.Mind96/0238.html (Accessed:  3 November 2010)




2 comments:

  1. Additional algorithm as follows:
    Dino‘s consensus algorithm which is have adjusted with colleagues comment and inputs to choose between three types of ice-cream from 10 people.
    1. Count <- 10 “counter for a group of person”
    2. Select<- string
    3. Ice-cream_option_ A <- 0; ice-cream_option_B <-0; ice-cream_option_C <-0 “counters are for ice-cream options
    4. While count > 0 do
    5. ( If select = ‘A’ then “ for ice-cream_option_ A”
    6. (ice-cream_option_ A <- ice-cream_option_ A +1;
    7. Else If select =’B’ then “ice-cream_option_B”
    8. (ice-cream_option_B <- ice-cream_option_B +1;
    9. ) end if select B
    10. Else if select =’C’ “ice-cream_option_C”
    11. ( ice-cream_option_C <- ice-cream_option_C +1;
    12. ) end else select C
    13. ) end if select A
    14. Count<-count - 1;
    15. ) end while
    16. Print option A is from ice-cream_option_A
    17. Print option B is from ice-cream_option_B
    18. Print option C is from icecream_option_C
    Compare with John’s algorithm of consensus
    Consensus Algorithm
    ‘1. counter <--- 1
    2. consensus <--- false
    3. while counter < 10 and consensus = false do
    4. (if counter=1
    5. then (read 10 choices into choiceList )
    6. else (
    7. repeat for each person
    8. (print the most desirable flavor from choiceList
    9. read updated choice into choiceList) end repeat
    10. ) end if
    11. if all entries in choiceList are the same
    12. then (consensus <--- true)
    13. counter <--- counter + 1
    14. ) end while
    15. print the most desirable flavor from choiceList’

    After discussed it John, and other in the class, I found that John‘s algorithm is efficient, however it is trying hard to have a consensus in the first place. After the consensus the rest will update for different choice. Compare to mine, it has three additional lines however it will flexible or free of choosing. Maybe at the end only one choice, this is reaching a consensus.

    Bibliography
    •Brookshear J.G. (2009) Computer Science: An Overview, (10th Ed). Boston: Pearson Education Inc, Ch 5. p. 228

    ReplyDelete
  2. Moreover, an algorithm in "A computer program can be viewed as an elaborate algorithm. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem"
    For example go to the office algorithm

    Alternative 1 walk
    1. get out from house
    2. lock the door
    3. walk 4 mile
    4. walk into the office

    Alternative 2 use bicycle:
    1. get out from house
    2. lock the door
    3. take bicycle
    4. unlock bicycle
    5. ride bicycle 4 mile
    6. park bicycle
    7. lock bicycle
    8. walk into the office

    Alternative 3 use taxi:
    1. get out from house
    2. lock the door
    3. take a taxi for 4 mile
    4. Pay taxi
    5. get out from taxi
    6. walk short distance (20 meter)
    7. Walk into the office

    Alternative 4 use bus or other public transportation:
    1. get out from house
    2. lock the door
    3. walk short distance to get public transportation or bus
    4. get in to the bus for 3.5 mile
    5. Pay the bus
    6. get out from the bus
    7. walk short distance (30 meter)
    8. walk into the office

    There are four alternatives algorithm to reach the office; all algorithm is right to use and it depends on needs and circumstances. If I need to be in the office earlier/quicker, I have to use tax,i however it is expensive. If I need a cheapest one, no matter with the time, I will choose first alternative and so on.

    Reference:
    algorithm [online]. Available from: http://whatis.techtarget.com/definition/algorithm (Accessed: 26 March 2013)

    ReplyDelete