Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
306 views
An Introduction To Algorithm and Programming For IT Passport Exam
An-Introduction-to-Algorithm-and-Programming-for-IT-Passport-Exam
Uploaded by
Aileen Radam Pagaduan Doo-Buy
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save An-Introduction-to-Algorithm-and-Programming-for-I... For Later
Download
Save
Save An-Introduction-to-Algorithm-and-Programming-for-I... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
306 views
An Introduction To Algorithm and Programming For IT Passport Exam
An-Introduction-to-Algorithm-and-Programming-for-IT-Passport-Exam
Uploaded by
Aileen Radam Pagaduan Doo-Buy
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save An-Introduction-to-Algorithm-and-Programming-for-I... For Later
Carousel Previous
Carousel Next
Save
Save An-Introduction-to-Algorithm-and-Programming-for-I... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 48
Search
Fullscreen
An Introduction to Algorithm and Programming for IT Passport ExamContents 41. Algorithm 41 Algorithms... 1.2 Algorithm examples . 43 Algorithm example - Search . 4.4 Algorithm example - Sort. 2. Programming... 2.1 Whatis programming? ..... 2.2 Whatis a pseudo programming language?.. 3, Pseudo Programming Language... 3.1. Pseudo programming language terms ... 3.2. Programming - Data type, variable, and array .. 3.3 Programming - Assignment... 3.4. Programming - Function and procedure... 35. Programming - Selection process - if 3.6. Programming - iteration process = For... 3.7. Programming - Iteration process - while = 4, Exercises. 4.4 Algorithm questions. 4.2 Programming questions... {43 Programming questions - Trial questions In P exam format Appendix. Specffication of Pseudo Programming Language ...1. Algorithm 11 Algorithms (1) What is an algorithm? A set of processing steps to achieve a specific goal is called an algorithm. In more detailed terms, a set of processing steps that is able to obtain the correct result or to perform the : intended action with complete reliability is called an algorithm, and a set of processing steps where it is not known if the correct result will be obtained or if the intended action will be performed are not known as algorithms. A set of processing steps that do not complete no matter how much time elapses are also not called algorithms. While algorithms are a set of processing steps to obtain the correct result with complete reliability, they could also be called procedures for solving problems. For example, let’s consider the actions taken when withdrawing money from a bank’s ATM. The problem here is “getting money.” In order to solve this problem, actions including “insert cash card” and “enter PIN” are required. If the actions here were to be numbered, they would be as below: [1] To withdraw money from the ATM, select “Withdrawal” from the ATM menu. [2] Insert your cash card. [3] Enter your PIN, [4] Enter the amount to withdraw. [5] Money comes out of the ATM (take it),Money can be withdrawn as long as these actions are performed in this order, and so this procedure can be called the algorithm for withdrawing money from a bank’s ATM. In this example, if [I] and [2] are performed in the reverse order, some machines will not let the card be inserted, and if [2] and [3] are performed in the reverse order, the ATM will not respond when the PIN is entered. It is only possible to get money by performing the operations in the set order [1], [2], [3]. [4], then [5}. [As such, algorithms are procedures with the essential processes arranged in the correct order. The same is true when calculation and other such processing is performed with a computer, and algorithms are procedures that specify in the correct order what kind of data is to be used and in what order calculation is to be performed. (2) The basic structure of an algorithm Tasks performed by humans include sequences, where multiple processes are performed in order, selections, where a process is selected from several options and performed, and iterations, where the same process is performed repeatedly. This is the same when a computer performs the work. Sequence, selection, and iteration are called the basic structure of an algorithm. Sequence — | * Selection + Iteration (sequence) | (branch on condition) (repeat on condition) l No << ‘crass Yes condition, Tice? Process 1 | [ Process? = Process J =) a (3) Expressing algorithms 4, Flowchart First, let’s get an understanding of the meaning of the symbols in a flowchart that representsan algorithm. When considering the details of an algorithm given witha flowchart or other such method of expression, itis important to apply a sample data to it and consider how the processing proceeds. Processes are represented with symbols, and these symbols are normally connected in the direction of top to bottom with lines in order of execution. The symbols are called flowchart symbols, and their shape and notation are predetermined by standards.Flowchart symbols] Symbol | Name Description [This represents data assignment, an operation, a group Process of operations, etc. | Deiails of the process are noted in the symbol. [This has a single entrance and several exits. < (Only one exit ean be chosen, according toa Decision | onditional expression, [The conditional expression is noted in the symbol. ‘These represent the start and end of an iteration (loop). (J | Loop start ‘The process enclosed in these symbols is the content lof the iteration. (7D | Loop end |The condition for ending the iteration is noted in one lof the symbols. 2, Pseudo programming language This is a programming language defined by IPA for the Information-Technology Engineers Examination. It allows an algorithm to be represented in a way similar to an actual programming language, but the created program cannot be executed, The pseudo programming language is explained from Chapter 2. 1.2 Algorithm examples We have looked at the algorithm to withdraw money from an ATM, but there are also ‘many other examples. These examples could include the actions taken from getting up in the moming to going to work or school, or the procedure that results in a purchase of a coffee from a vending machine. While algorithms like these do exist for the actions we take in daily life, when it comes to getting computers to perform processing, it can be sai that the thing they are best at doing is calculation. In processes that aggregate large volumes of data to calculate the latest result or predict how weather will change based on past results, although it is not possible to see from the results alone, the computer internally follows a set algorithm and executes a massive amount of calculation processing at ultra-high speed. The IT Passport examinations that you have taken so far have also included a few Guestions involving algorithms. Most of these questions involving algorithms were extremely simple and involved calculating the total of values and comparing data to determine which was larger and smaller. An algorithm is a procedure for having processing performed by a computer, Next, we will learn the approach in the typical algorithms for searching, where target data is searched for, and sorting, where data is arranged into a different order.1.3 Algorithm example - Search © Search algorithm A search is a process that searches for target data. It performs a comparison to check whether the subject data of the search is the target data, so searching is referred to as “comparing.” (1) Linear search (sequential search) Data is arranged into a series, and a search is performed in order from the start. If the subject data of the search includes 100 items of data, the target data can be found with only one comparison if the first item of data is the target data. But if the target data does not exist, 100 comparisons have to be performed. Target data Arrangement of subject data of the search Not equal 34 Ne eal 20 30 ‘Comparison from start Not equal |~_25 Figure 1.3 (1) Linear search (2) Binary search ‘This sorts the subject data of the search in advance. It compares the target data with the data in the middle of the search range, and continues the search after narrowing the search range down to the range before or after the middle data. Tstiime 2nd time — a 2 |(Middle) [eIowiaaey 3 : ‘Search key 2=13) Key 2° Key2- Present in the first half _Presentin the End search second halt Figure 1.3 (2) Binary search\.4 Algorithm example - Sort » Sorting algorithms Sorting refers to changing the arrangement of data. (1) Bubble sort (exchange method) This compares adjacent data items, and reverses their order if they are in the opposite order of magnitude. If data isto be sorted into smallest first (ascending order), it compares data items adjacent ‘0 each other starting on the left, and reverses their order if the value on the left is greater than the value on the right. By continuing this, the largest item of data will end up on the right. Next, with the exception of the item of data fixed as the largest, it repeats the same operation, and when there is only one item of data remaining, sorting is complete (Figure 14). ‘There is also a method to compare data from the right and fix the smallest item of data first,
Number of <2ndtime> Number <3rd time> Number of _gomparisons: 4 of comparisons: 3. comparisons: 2 | Bilehelsdey (Repels2)}s ieial. s [ee ea a ee ee EE es He aes eae Se Ear al ca) 413-32 41 3 oOo Fix Fix Fix yy 4 lee 2 Ed Fix Fix <4th time> Number Fix of comparisons: | Reversed after comparison Notreversed after comparison Figure 1.4 Sorting with the bubble sort (exchange method) (2) Quick sort his is an improved version of the exchange method. It sorts data by repeatedly extracting thei) “he middle and splitting the data into a group with a larger value and a group with cr ile than the extracted value. (.. Seleciion sort (selection method) This selects the smallest data item, and switches its position with the data at the start. With the exception of the item of data fixed as the smallest, it repeats the same operation to sort the data. There is also a method that selects the largest item of data and switches its location with the item of data at the end.2. Programming 2.1 What is programming? (1) From an algorithm to a program An algorithm is a set of instructions for a computer, so after an algorithm is ereated, a program is created based on this set of instructions. Problem to) Create [Create solve algorithm program |]. Test Execution) (2) Programming Algorithms are described by using a programming language to create a program. This task involves taking an algorithm in the form of a flowehart or another form that a human can understand, and rewriting it intoa program that a computer can execute. Iti also known as coding, It also includes work to execute the program created in order to check it (unit test). (3) Expressing algorithms Concerning how algorithms are represented, it is known that all algorithms can be represented by combining the three basic processes (sequence, selection, iteration) below (Dijkstra, The Structure Theorem). Format | Sequence Selection Iteration - ——— Frocess 1 Process name Flow I
Condition chart | (Process 2 Ye ae [Process 1 || Process 2 t Process 3 t Process name T T ‘The three basic processes that form an algorithm ‘Sequence represents the connection between a series of processes. Selection (if) provides branching function based on the condition. Iteration (for, while) executes the process repeatedly while the condition is fulfilled. How to write in pseudo programming language is described in detail below.2.2 What is a pseudo programming language? (1) Expression of algorithms in flowcharts and pseudo programming languages Algorithms have often been represented with flowcharts in the IT Passport examinations so far, but as a result of the examination system reform, questions on algorithms will use @ pseudo programming language for expression. While a flowchart represents the details of @ process by using symbols, a pseudo programming language does so by using the words “if” for a selection and “for”, “while”, and “do” for an iteration. These words are equivalent to instructions in a program. (2) Pseudo programming languages While flowcharts are a typical way of representing an algorithm, a pseudo programming language enables an algorithm to be represented in a way that is close to an actual programming language. The pseudo programming language that is used in this text is a programming language defined by IPA for the Information-Technology Engineers Examination. It allows an algorithm to be represented in a way like an actual programming language, but the created program cannot be executed, ‘The pseudo programming language itself uses a method of expression that is similar to the programming languages Python and C, and algorithms written in this pseudo programming language can be easily switched into Python or C. Please note that no detailed explanation of specific programming languages is provided here because they are not in the scope of the IT Passport examinations. The pseudo programming language used in the IT Passport examinations has few rules, 0 let’s get an understanding of the basics. =10-3. Pseudo Programming Language This chapter provides an explanation of the meaning of basic terms, and expressions in the pseudo programming language. Afier gaining an understanding of these, you will learn how to read programs written in the pseudo programming language. You will also gain practical question solving abilities by solving the practice questions in Chapter 4 and the sample questions released by IPA. When learning, the important thing is to keep thinking for yourself about the matter in hand until you fully understand it. This may seem annoying sometimes, but you must keep in mind your goal and lear one step ata time. ‘The specifications for the pseudo programming language for the IT Passport exams as released by IPA can be found in [Appendix. Specification of Pseudo Programming Language]. This chapter provides an explanation and supplementary information for each item of content in the specification, While you can refer to the pseudo programming language specifications in the appendix during an examination as necessary, it is better to concentrate on solving questions, so itis important to thorough understanding of the pseudo programming language beforehand. 3.1 Pseudo programming language terms Here, an explanation of the terms used in the pseudo programming language. Please refer to the following chapters and the appendix at the end concerning specific grammar for the pseudo programming language. Tem Description ‘An explanation or memo left for human use concerning a process, ora hint for solving a question. Comment Input refers to giving data to a program for processing. Input and | Output refers to the passing of data from a program 10 a output peripheral device, ete. Collectively, they are referred to as input/output Program Display =Term Description A symbol used when describing expressions and conditional expressions to indicate the operation details. Addition + Subtraction - Multiplication x Division + Remainder mod Ex: 7 mod 3 is 1 Operator Grouping in an expression for prioritized calculation () Ex: (3 + 2) x4 Magnitude relationship < > > < Ex:A 2 B (Ais equal to or greaterthan B) # Ex: A # B (Aand B are not equal) Logical operations _and (logical product) or (logical sum) Represents the kind of data, also called a data type. The kind of data that can be stored is determined by the type. + Integer type: Numerical data with no values after the decimal point Type + Real type: Numerical data with values after the decimal point + Boolean type: Either of the values true or false + Character type: A single character of data Ex: “A”, “@” + String type: Data that is composed of multiple characters _Ex: “program” Data storage that holds a value that changes during processing, stores intermediate results, indicates the number of iterations, etc. Declaration is made by specifying a name (variable name) and type. {My name is sum. Variable integer: sum eae | Value Variable Represents a fixed value. Numeric values are written in the same way as everyday Constant | BUmbers, with 2, -5,... for integers and 1.5, -0.75, .. for eal numbers. Character types and string types are enclosed in quotation marks, in the form “algorithn”. ‘A description that connects variables and constants with operators. Expression | Example: (x + @.2) + y pres Some expressions have only one variable or constant, rather than multiple combinations. Specifies the conditions for processes that are only executed when specific conditions are fulfilled. Conditional | Complex conditions can also be specified by linking the conditions with “and” expression | and“or”. Example: T is equal to or greater than 100 Example: @ < T and T 100 -12-‘Term DESuin Assignment Refers to storing a numerical value or character in a variable. A variable that stores a value can also be assigned to another variable. Ex:x <5 The value of the variable x is set to S Ex:x
These are operators that are used when describing relationships such as the magnitude relationship between two numbers or variables, or whether they are equal or not equal. < means [< or =] and 2 means [ > ot | and so includes cases where the values are equal. (Ex. 1) Ina conditional expression, ¢ # a (cand a are not equal) (Ex. 2) Ina conditional expression, p < q (pis smalier than q) Logical operator - Logical product _and This is an operator for logical operations that is used in the specification of a conditional expression if you want to say, “When both of two conditions are true, treat the conditions as awhole as true”. (Ex.) (a $ 18) and (a = k) (a is equal to or less than 10, and a and k are equal) ‘true when: a=7 and k= 7, a= 10andk = 10,a=3 and k=3, etc. false when: a= 1] andk =11,a=3 and k Logical operator - Logical sum or This is an operator for logical operations that is used in the specific n of a conditional expression if'you want to say “At least one of two conditions is true, treat the conditions as awhole as true”. Here, the conditions as a whole are true also when both conditions are true. (Ex.) (@ £ 18) or (a = k) (ais equal to or less than 10, or a.and k are equal) true when: a=7 and k= 10, a= 12 and k= 12, ete. false when: a= 11 andk =12 (Additional information) Comments /* comment */ //_comment Comments are added to programs in order to make the content of processes, algorithms, and points for attention easy to understand when viewed later on. In the pseudo programming language for examinations, text that is enclosed with /* and */ and after // (up to the end of the line) is treated as comments and does not impact execution, Note that in examination questions, comments that provide too much of a hint are sometimes omitted. (Ex.) /* Calculate as a realnumber */ // Calculate as a real number -417-(3) Use of parentheses (_) in complex expressions In cases where arithmetic operators are mixed together, they are calculated in the order of highest priority first, but parentheses (_) are often used to avoid confusion. (Ex) Condition a < b or ¢ > 100 and d= 1 ‘The <, >, and = that indicate a relationship have a higher priority than the logical operations “and” and “or,” so first we have connections of [a < b],[¢ > 100], and[d = 1} Next, as for the logical operation, logical product and has higher priority than the logical sum or, so after investigating whether the conditional expression [¢ > 108 and d = 1Jis trie or false, the result of or with the truth of the condition [a < b] is investigated. As shown here, complex conditional expressions make it easy for both people who make programs and who read programs to misinterpret them, so parentheses (_) are often used to describe expressions, such as (a ¢ b) or (c > 100 and d = 1), 3.4 Programming - Function and procedure While functions and procedures are similar, the way they work and how they are used differ. Both of them receive data from the program that called them (in some eases there is no data) and execute a series of processes, but they handle the result differently. A function returns the result of a process to the program that called it, so the program that called the function can use the value of the process result in its own program A procedure, however, normally ends when it provides the result of a process. The program that calls a procedure does not know what the result of the proves We will take a look at specific examples of how to use them later. Function Procedure, Olrettype? tunc-name(type: argi, ...) © proc-name(type: argt, ...) return ret-val output Data | Data called argament(s) Function called argument(s) Process Process: |¢_____. a result COatput called the retum value Provide the result as output (No output is provided in some cases) -18-At the start of a program, the name of a function or procedure is first declared. The arguments that are the data to be processed are specified in parentheses (_) after the name, For a function, the type of the retum value that is the data of the process result is first specified before the name (the grey shaded part in the box above). In other words, you can tell a function and a procedure apart by whether there is a type of return value (the grey shaded part). (Ex.1) Oreal: divide(real: n, real: d) real: q qened return q You can see “real:” immediately after the O, so this shows that it is a function that returns the result as a real type. The name of the function is divide and it receives two items of real number data with arguments called n and , and calculates the quotient of n = das q. To retum the result, the value to be returned (variable, constant, expression) is specified ina return statement Let's take a look at how it is used by the program that calls the function. For example: If the function divide is called from the assignment statement q <- divide(3, 4), the function receives n as 3 and d as 4 and returns the value of 3+4, 0.75, so the program that called the function can use divide(3, 4) as the value 0.75. So, in the expression above, the value 0.75 is assigned to q. (Ex. 2) Odivide(real: n, real: d) real: q qened output q There is no specification of the type of return value immediately after the ©, so you ean see this is a procedure. The name of the procedure is divide and it receives two items of real number data with arguments called n and d. The content of the process is the same as (Ex. 1), but the result of the process is displayed by the output statement and the procedure ends. The result of the process is not retumed to the program that called the procedure. An example of how the procedure is called is divide(7, 8) and this is simply a statement that calls the procedure. -19-3.5. Programming - Selection process - if if (condition-i) oii process-i we else ae process-e Process-i | | process-e endif , J Flowchart for a selection process with one conditional expression In this if statement, it i possible to omit the description of else and provess-e, and to describe only the process to be executed when the condition-iis trac. ————_——$———— maior)
process: 5 endif | process = Flowchart with else and process-e omitted if (condition) Hos process) ee elseif (condition-e-1) < ee nue at process-si-1 Goce ab > elseif (condition-ei-2) process-i ae else [orocess-1 Se process-e process-ei-2 ||process-] endif ,_—_) ey Flowchart with multiple conditional expressions The conditfons are evaluated from the top down in order, and the process corresponding to the first condition that evaluates to true is executed. Once a condition evaluates to true, subsequent conditions are not evaluated, therefore the comespon 1g processes are not executed. If none of the condition evaluates to true, process-e is executed. Each process is sometimes composed of multiple statements. There are sometimes multiple elseif and process pairs. Only one pair of else and process-e is described and omitted in some cases. 420(Question example 1) The procedure judge receives the integer arguments A and B, compares their: magnitude, and outputs the result as follows: If Ais equal to or greater than 8, outputs the message “The value of data A is equal to or greater than data B”. If Ais less than B, outputs the message “The value of data A is less than data B”. [Program] © judge(integer: A, integer: 8) /* Declaration of the procedure judge (arguments are integers A and 8) */ if (A 2 B) € conditional expression output "The value of data A is equal to or greater than data" — € process else output “The value of data A is less than data B" € process endif (Question example 2) The procedure judgePoints receives the inieger argument points, and outputs the message as follows: If points is equal to or greater than 80, outputs the message “Rank A”. If points is equal to or greater than 60 but less than 80, outputs the message “Rank B” If points is equal to or greater than 40 but less than 60, outputs the message “Rank C” If points is less than 40, outputs the message “Rank D” [Program] © judgePoints(integer: points) // Declaration of the procedure judgePoints if (points > 86) © conditional expression output "Rank A" € process elseif (points 2 68) € conditional expression output “Rank 6” € process elseif (points 2 48) € conditional expression output "Rank c” € process else output "Rank b” € process endif -24-3.6 Programming - Iteration process - for “for” iteration process: athe a for (sequence) ae process i endfor ——=—— Process name Tn the cele pei in the seenorice, Flowchart for an iteration process (for) execute the process repeatedly. for statements are often used in cases such as when a process is to simply be repeated a set number of time. Note that there is no explanation of how to write a sequence in the pseudo programming language notations, so in the IT Passport examinations, itis likely that it will take the form of a control description to increase or decrease a specific variable such as “increase variable from value to value by(step) value” as in the programs released as sample questions. (Question example) The function calcsum receives a positive integer with the integer type argument num, calculates the total of the values from 1 to the value of num, puts it into sum, and retums it as the return value. The program uses the integers i and sun as variables, makes 1 the initial value of 4, calculates the total by adding | up to num, and puts it in sum. [Program] O integer: calcSum(integer: num) // declaration of the function calcSum integer: i, sum // decleration of the variables i and sum sum <— @ // Initialize sum for (increase i from 1 to num by 1) // when i exceeds num, exit the loop sum < sum +i // add the value of 4 to sum < process endfor return sum // return the value of sum as the return value (Note) The description of the sequence in the For statement contains a “Process to add | to the value of 1”, so it is fine to iterate only the “Process to add the value of i to sum” in order to simplify the program. -22-3.7 Programming - Iteration process - while There are two types of iteration processes that use while, as shown below. “while” iteration process: “do-while” iteration process: while (condition) do process process endwhile while (condition) While the condition is true, while the condition is true, execute the process repeatedly. execute the process repeatedly. The difference between the two is the grey shaded part in the explanation above, “while” tests in advance whether iteration is to be executed (the process may not be executed at all in some cases). “do - while” unconditionally implements the process the first time, and then tests whether to iterate it, The correspondence with the flowchart is as below. ——+—__. | Process name —- Conditional expression pea ee Process Process ——— i Process name Conon exresion se Proce Flowchart for pre-test iteration process (while) Flowchart for post-iest iteration process (do-while) (Question example using while) ‘The procedure calcSum calculates the total of integers | to 100. ‘The program uses the integers i and sum as variables, makes 1 the calculates the total, and puts it in sun, ial value of 4, [Program] © calcSun() /* Declare the procedure calcsum(no arguments) */ integer: i +1 /* Declare and initialize i for addition */ integer: sum < @ /* Declare and initialize sum for calculating the total */ while (i < 100) /* Ifthe value of i is equal to or less than 100, continue to execute the process */ | sum <— ‘sum +i /* Add the value of itosun */ fieied /* Add 1 to the value of i */ endwhiie =e = Process -23-(Question example using do-while) The function calcSum receives a positive integer with the integer type argument num, calculates the total of the values from 1 to the value of num, puts it into Sum, and returns it as the retum value, The program uses the integers i and sum as variables, make 1 the initial value of i, calculates the total by adding | up to num, and puts it in sum. [Program] O integer: calcsum(integer: num) /* Dedare the function calcSum */ integer: i, sum /* Declare variables 1 and sum */ i<_d /* Initialize 4 to 1 */ sum <— /* Initialize sum to @ */ sum + i /* Add the value of i to sum i412 /* Add 1 tothe value of i */ Process is num) /* ifthe value of i is equal toor less than num, continue to execute the process */ return sum /* Return the value of sum asthe return value */ [Program indentation] The processes specified in the if, for, and while statements are made easier to read by shifting the starting position of description to the right. This is called indentation, The number of characters in an indentation is not set in the pscudo programming language, but in this text, indentations are two characters. When writing a program in the pseudo programming language yourself, be sure to use a two-character indentation. -24-4. Exercises This chapter explains the algorithm questions and programming questions in the IT Passport examinations. When tackling an algorithm question, be sure to pay special attention to selection and iteration processes in flowcharts to get an understanding of the overall process. When tackling a programming question, first consider the declaration and details of processing for each line of a program, and identify the main points to build an understanding of the overall process. And when you have arrived at an answer yourself, be sure to read the explanation and other information, 4.4 Algorithm questions Exercise A1: Understanding of algorithm a Q) @) @ (5) (6) @ (8) (9) ‘What are the three basic structures that are used in the consideration of an algorithm? Processes are represented with and these are connected in the direction of |_8_] ith [D_] in order of execution. [ZE_] programming languages can express programs in a way that is similar to [F_] programming languages, but the execution of the created program is not possible. ‘The [_G_] indicates the kind of data. In numerical data, [_H_] values have no digits after the decimal point, and [T_] values may have digits after the decimal point. Boolean type values indicate one or other of[_J_] or[_K_]} What is data with a value that changes during the processing called? A description that combines variables, values, and operators is an and a[_M_] specifies the conditions for processes that are only executed when specitie conditions are fulfilled. Storing numerical values or characters in a variable or data is called[_N_]. A[LO_]and [P_] receives data that is required for a process as an argument and executes the process. Then, a[_O _] outputs the result of the process ona device, and a ([P J retumns the result as a retum value. What is the method to arrange data into a series, and search it in order from the start called? What is the sorting method that compares adjacent data items, and reverses their order if they are in the opposite order of magnitude called? (10) Whatis the description of algorithms using 2 programming language to create a program called? -25-Answers for Exercise A1 (1) sequence selection iteration Q) A: symbols 8: top C: bottom D: lines (3) E:pseudo Factual (4) G: (data) type H: integer (type) _: real (type) J, K: true, false (either order OK) (5) a variable (6) L: expression M: conditional expression (7) 0: procedure P: function : assignment (8) linear search (sequential search) (9) bubble sort (exchange method) (10) programming (coding) Exercise A2: Knowledge of algorithm QA2. Algorithms are important when using a computer. Which of the following is the appropriate explanation of an algorithm? a) Software that converts a program into machine language that can be directly executed by acomputer. b)_A.set of processing steps for a computer to achieve a specific goal. ©) A collective term for artificial languages for giving instructions for a series of operations to a computer. 4) Theuse of acomputer to design buildings, industrial products, and other such things. Answer for Exercise A2 The correct answer is b) Programming is a process to describe the algorithm by usinga programming language. You have a process that you want to execute on a computer, so you create a program. Just as you think of a set of steps or a plan before cooking or cleaning, you consider a set of steps to achieve your goal before creating a program. This is an algorithm. If you have an algorithm, you can do programming without any confusion. a) This is an explanation of a compiler. is is an explanation of a programming language. s an explanation of CAD (Computer Aided Design), -26-Exercise A3: Flowchart - Selection process QA3. The flowchart below shows the steps for order processing in a ticket sales system, Which of the following is the correct combination of expressions to be entered in blanks in the flowchart? Here, the number of tickets in stock is T, the order quantity is O, the price for one ticket is P, and the total ticket price per order is. TAT-o s-0 a) |OsT|P+sxo b) |OsT|S~Pxo ©) |O>T|P~sxo d)|O>T|S~Pxo Explanation of Exercise A3- Levs consider it from blank A. You can find a hint in what it does after branching, {Fit branches to Yes, the next process is T T~ 0. It subtracts the order quantity O from the number of tickets in stock T, so you can see that itis processing an order. IFit branches to No, the next process is S— 0 The total ticket prive per order S is 0, so this order was unsuccessful. This means that blank A is a conditional expression that tests whether a ticket order is accepted or not. Looking at the options, we can see that itis comparing the order quantity © and the number of tickets in stock T. It is obvious that not all orders can be accepted if the order quantity is greater than the number of tickets in stock, but the description of the question does not make it clear if the order will be partially accepted. However, ifit branches ‘o Yes, it subtracts the order quantity from the number of tickets in stock, so you can see that an order is only accepted if © is equal to or less than T. The expression for this is O
ME) bonusPoints < sales x @.1¢ elseif (sales > MN) CA is sales) /* Procedure declaration */ bonusPoints < sales elseif (__B_)) bonusPoints < sales x else bonusPoints < sales x 0.005 endif ‘output integer part of bonusPoints [oa B a) sales > 10@0 * b) | @.e2 sales > 2000 c) | 0.03 sales 2 1000 d) | 0.03 sales 2 2000 Explanation of Exercise P1 First, let's change 10%, 3%, 1%, and 0.5% to fractions, 10% becomes 0. 10 as 10+100=0.1, 3% becomes 0.03, 1% becomes 0.01, and 0.5% becomes 0.005. ‘The argument sales contains the purchase amount, so bonusPoints = sales x 0.10 is the point calculation for purchase amounts of $5,000 or more. 500 is assigned to bonusPoints. Next, amounts of less than $5,000 that do not fall under this category are calculated with the next elseif’s. else is the process that is executed when if or elseif’s are not applicable. It executes bonusPoints < sales * 0.005, so it is the calculation for purchase amounts of less than $1,000. So, whatis lacking is the caleulation for 3% and 1%, let's consider which one to execute first. ‘The first elseif conditional expression that contains blank A is (sales > [MM. 1 ‘means equal to or more than the shaded purchase amount. An amount of $5,000 or more has already been extracted, so if the shaded partis considered to be $2,000 or more, it falls under at least $2,000 but less than $5,000, and the calculation for 3% becomes possible. Next, amounts of less than $2,000 that are not applicable to blank A are calculated with the next elseif with blank B. -30-Whats lefts the calculation for 1%. An amount of $2,000 or more has already been extracted, so ifthe conditional expression in blank B is considered to be $1,000 or more, it falls under atleast $1,000 but less than $2,000, and the calculation for 1% becomes possible. And if this is not applicable, itis less than $1,000, and it is calculated with else. Finally, blank A is 0.03 and blank B is sales 2 1000. The program is determined es follows: if (sales > BOB) bonusPoints < sales x @.10 elseif (sales > Gad) bonusPoints < sales x
8.6: elseif (KB> sales = 1000) bonusPoints < sales = Glad else bonusPoints < sales x 6.025 endif ‘Answer for Exercise P1 ‘The correct answer is ©) Exercise P2: if / for QP2. Select the correct combination of the answers to be inserted in and in the program. The function searchMax receives the array dataArray that has at least two elements as an argument, and retums the largest value in the array dataArray as the retum value. Here, the array index starts at 1. [Program] © integer: searchMax(integer []: datatrray) /* Function declaration */ integer: max integer: i nax <- dataArray[1] _/* setthe value of the first element to max */ for (increase i from 2 to the number of elements in dataArray by 1) [5s] endif endfor return max -31-A B a) | dataarray(i] by | dataarray[i] ¢) | dataarray[i] d) | dataarray[i} max__|max < dataArray[i] max__| dataArray[i] < max max__| max < datadrray[i] max__| dataArray[i] < max Explanation of Exercise P2 This is a program that finds the largest value in an array. Checking the type and name of the argument for the function searchMax shows it isan integer type array called dataArray, and the process searches for the largest value in the elements of this array and returns it as the integer type return value max. Next, noting down a figure stich as the below as an example of dataArray with five elements makes the process easy to understand. (4) (2) (3) [4] {5} dataarray{ 21 | 10 | 34 | 59 | 12 | max| 21 (Assume the first value is the largest) Here, it can be seen from the sequence description in the for statement that the process initially assumes the first element dataArray [1] is the largest value max, and then goes on to compare the elements from the second element onward with the value of max. ‘The program uses i as the current element number and increments it 1 at a time from 2 up to the number of elements in the array dataArray while comparing the largest value max with dataArray[i] in sequence, and if dataarray[4] is larger than max, it updates the value of max with the value of dataarray[i] As such, blank A is dataArray[i] > max, and blank B ismax < dataArray(i]. In the dataArray example above, max changes as shown below as the value of 4 changes, and the largest value 59 is returned as the return value. i_| Pre-comparisonnax| dataArray[i] | Post-comparison max (Start) 2a | . ‘a 2 2 I ae 21 3 2 34 34 | 4 34 59 59 | 3a a 2 -92-Answer for Exercise P2 ‘The correct answer is ¢) Exercise P3: for QP3. Select the comect combination of the answers to be inserted in and in the program, ‘The function calcMean receives the array dataArray (the number of elements 2 1) as an argument, and returns the average of values in the array dataArray as the return value. Here, the array index starts at 1. [Program] Oreal: calcMean(real []: dataarray) /* Declaration of function */ real: sum, mean integer: i sum <— 0 for (increase i from 1 to the number of elements in dataArray by 1) sun <— [A] endfor mean < sum = /* Division is done in data type real */ return mean A B a) | sum + datasrray[i] | the number of elements in dataArray b) | sum + dataArray[i] | (the number of elements in dataArray + 1) c) | sum x dataarray[i] | the number of elements in dataArray 4d) | sum x dataarrayt i} | (the number of elements in dataarray + 1) Explanation of Exercise P3 Looking at the program, a check of the type and name of the argument shows it is a real type array named dataarray, and the process of the function calcMean calculates the average value of the data in the array and returns the value as the real type return value mean. Next, noting down a figure such as the belowas an example of dataarray with five elements makes the process easy to understand. (1) (2) [3] (4) [5] dataArray | 11.2 | 10.5 | 13.1 | 15.6 | 12.8 -33-Here, to calculate the average, you just need to calculate the total of the values and divide this by the number of elements. So considering at which point in the program this is done, you can see that the variable to calculate the total is the real type sum and that the process for blank A.adds to itthe values in the array from the first element (element number 1, dataArray[1]) to the last element (dataarray[the number of elements). 5 Looking at the sequence description of the for statement, it says “increase i from | to the number of elements in dataarray by 1”, so you can see that the integer type 1 is used for the element numbex. As such, you can tell that sum + dataarray[4] is entered into blank A. Next, when execution of the for block ends, the total is calculated and put into sum, so ides this sum by the number of elements in the we can see that blank B is a process that di array dataArray and calculates the average. Given the above, the number of elements in dataArray is entered into blank B. Note, if this program is executed with the elements {11.2, 10.5, 13.1, 15.6, 12.8} in the array dataArray 12.8) +5=63.2+ ¢n as an example just before, it gives (11.2 + 10.5 + 13.1 + 15.6 + 2.64, and the mean value 12.64 is returned as the return value. Answer for Exercise P3 The correct answer is a) while QP4. Select the correct combination of the answers to be inserted in [A] and inthe program. Exercise P. The function calcSum receives the array data that has at least one element as an argument, and returns the total of the values in the elements as the return value. Here, the array index starts at 1. [Program] ©real: calcsum(real []: data) /* Function declaration */ real: sum < @ /* Initialize sum to @ */ integer: i <1 /* Initialize the array index */ while (i [A] the number of elements in data) sum <= i
4) and (age < 9) ©) ages d) age <9 =42-063. elect the correct answer to be inserted in[___] in the deseription. Here, the array index starts at | The function count receives an integer array with at least one element as an argument. When the function count is called as count({9, 6, 5, 7, 1, 7, 6, 8}),the return value is[___]. [Program] O integer: count(integer []: data) integer: pass <7, out <0 integer: i for (increase i from 1 tothe number of elements in data by 1) if (data[i] 2 pass) out < out +1 endif endfor return out a) 3 b) 5 8 d) 10 Q64. Select the correct answer to be inserted in in the description. The procedure calculate receives two positive integers ni and n2 as arguments. When the procedure calculate is called as calculate(2, 6), the output value is[_____} (Program| Ocalculate(integer: ni, integer: n2) integer: a <— ni integer: b — n2 while (a # b) if (a> b) aca-b else beb-a endif endwhile output 2 a) 0 b) 2 4 4) 6Q65. Select the correct combination of the answers to be inserted in[ A] and in the program, ‘The function toSec receives three integer values hour, min, and sec, and returns the time in seconds. For example, if hour ~ 1, min = 30, and sec = 50, the function toSec returns 5,450 (1 hour 30 min 50 sec is 5,450 seconds). Here, the ranges of given values are: 0 < hour < 23, 0 < min < 59, and 0
< + and) ©) logical product on) Low | logicalsum | [Boolean-type constants] true, false [Array reference] 1-dimensional array | 2-dimensional array | Array declaration | type []: name... | type [,]: name ... Example integer]: a1 | integer [,]: a2 1asas are 1/3/5/7/|9 4 | 24 | 12.) 2 [44 [as | 16 | 317 | 18} 19 Data reference Data 7 is referred Data 16 is referred _ toby a1[4] {toby 22[2,3] _| Notation of array | {1, 3, 5, 7, 9} | {{11, 12, 13), contents {14, 15, 16}, (17, 18, 19}} Note: The indexes of example arrays start at 1 <4n to An Introduc Algorithm and Programming for IT Passport Exam Every precaution has been taken in the preparation of this book. However, the information contained in this book is provided without any express, statutory, or implied warranties. Neithor the author, translators, nor publishers will be held liable for any demages caused or alleged to be caused either ¢irectly or indirectly by this book. First Edition: 2023-06-16 Original works in Japanese published by ITEC Inc. (IT NAA — b UAE 9 6 A) (ISBN: 978-4-86575-287-8) NT AAR hRBY D/N2] Ver. 6.05 RUSBAERA Copyright © 2022 by ITEC Inc. The contents of English edition are reconstituted from the original works in Japanese. Translation rights arranged with ITEC Inc. Translation copyright © 2023 by Information technology Promotion Agency, JAPAN Information-tochnology Promotion Agency, JAPAN Center Office 16F, Bunkyo Green Court, 2-28-8, Hon-Komagome, Bunkyo-ku, Tokyo, 113-6591 JAPAN - 48 -
You might also like
Definition of Algorithm
PDF
No ratings yet
Definition of Algorithm
7 pages
Lab 16 Abestros Jharine
PDF
No ratings yet
Lab 16 Abestros Jharine
34 pages
Elm04 10solutions - Doc 0
PDF
100% (2)
Elm04 10solutions - Doc 0
13 pages
Chapter 4. Enterprise Technologies and Big Data Business
PDF
No ratings yet
Chapter 4. Enterprise Technologies and Big Data Business
37 pages
Computational Science and Numerical Methods
PDF
No ratings yet
Computational Science and Numerical Methods
8 pages
The Tree ADT
PDF
No ratings yet
The Tree ADT
42 pages
Accounting Concepts and Conventions
PDF
No ratings yet
Accounting Concepts and Conventions
5 pages
AP Computer Science A Course Syllabus CodeHS
PDF
No ratings yet
AP Computer Science A Course Syllabus CodeHS
6 pages
Careers in Information Technology
PDF
No ratings yet
Careers in Information Technology
2 pages
GENIUS Olympiad Coding Samples
PDF
No ratings yet
GENIUS Olympiad Coding Samples
15 pages
Research Proposal: Herbal Leaves Identification App
PDF
No ratings yet
Research Proposal: Herbal Leaves Identification App
4 pages
Combinations and Permutations Notes-1
PDF
No ratings yet
Combinations and Permutations Notes-1
3 pages
Cruise Travel Managenment
PDF
No ratings yet
Cruise Travel Managenment
34 pages
C Palindrome Program
PDF
No ratings yet
C Palindrome Program
6 pages
Lab Exercise 10 Midterms - Sacasas Elizalde John M
PDF
0% (1)
Lab Exercise 10 Midterms - Sacasas Elizalde John M
5 pages
LAB Act. Task 3
PDF
No ratings yet
LAB Act. Task 3
16 pages
It Passport Training Introduction
PDF
100% (1)
It Passport Training Introduction
46 pages
Evolution of Computers in PDF
PDF
100% (1)
Evolution of Computers in PDF
2 pages
X (Age Youth, Income Medium, Student Yes, Credit Rating Fair)
PDF
No ratings yet
X (Age Youth, Income Medium, Student Yes, Credit Rating Fair)
2 pages
ACT 1301 L S Common
PDF
No ratings yet
ACT 1301 L S Common
97 pages
Question and Answer
PDF
No ratings yet
Question and Answer
6 pages
Class 7 (HTML)
PDF
No ratings yet
Class 7 (HTML)
20 pages
OS Lecture2 - CPU Scheduling
PDF
No ratings yet
OS Lecture2 - CPU Scheduling
48 pages
Chapter 9 (Machine-Independent Optimizations)
PDF
No ratings yet
Chapter 9 (Machine-Independent Optimizations)
37 pages
Application of Knapsack Algorithm
PDF
0% (1)
Application of Knapsack Algorithm
5 pages
Algorithm 11 Questions & Answers For Exam
PDF
No ratings yet
Algorithm 11 Questions & Answers For Exam
7 pages
Page Replacement Algorithms
PDF
No ratings yet
Page Replacement Algorithms
10 pages
Lecture 0 Algorithm Flowchart Pseudocode
PDF
No ratings yet
Lecture 0 Algorithm Flowchart Pseudocode
26 pages
ICT Week 3-6 LP
PDF
No ratings yet
ICT Week 3-6 LP
21 pages
System Analysis and Artificial Intelligence: Michael Zgurovsky Nataliya Pankratova
PDF
No ratings yet
System Analysis and Artificial Intelligence: Michael Zgurovsky Nataliya Pankratova
468 pages
LaboratoryNo2 Debug
PDF
No ratings yet
LaboratoryNo2 Debug
11 pages
Hcs 135: Introduction To Information Technology: Section
PDF
100% (1)
Hcs 135: Introduction To Information Technology: Section
15 pages
Computer Printots Chapter 3
PDF
No ratings yet
Computer Printots Chapter 3
10 pages
PSA3 Technical - PHP Arrays and User Defined Functions
PDF
No ratings yet
PSA3 Technical - PHP Arrays and User Defined Functions
13 pages
A Project Work On Atm
PDF
No ratings yet
A Project Work On Atm
45 pages
Unit 4
PDF
No ratings yet
Unit 4
4 pages
PPS Unit 6 Notes
PDF
No ratings yet
PPS Unit 6 Notes
23 pages
Lecture 4 - Business Plan
PDF
No ratings yet
Lecture 4 - Business Plan
36 pages
Computerised Accounting Test 1
PDF
0% (1)
Computerised Accounting Test 1
3 pages
Operating Systems & Networking
PDF
No ratings yet
Operating Systems & Networking
53 pages
ES03 Lab Manual
PDF
100% (2)
ES03 Lab Manual
59 pages
C++ Exam Past Question and Answer
PDF
No ratings yet
C++ Exam Past Question and Answer
8 pages
MSIT-104 Data Structure and Algorithms
PDF
No ratings yet
MSIT-104 Data Structure and Algorithms
237 pages
5 Flow Control
PDF
No ratings yet
5 Flow Control
16 pages
It0089 Finalreviewer
PDF
No ratings yet
It0089 Finalreviewer
143 pages
PL Questions
PDF
No ratings yet
PL Questions
6 pages
R Lab Programs
PDF
No ratings yet
R Lab Programs
65 pages
Fractional KnapSack Problem
PDF
No ratings yet
Fractional KnapSack Problem
6 pages
Hope 4 PDF
PDF
No ratings yet
Hope 4 PDF
101 pages
Computer Fundamentals and Programming
PDF
No ratings yet
Computer Fundamentals and Programming
6 pages
Assignment PGD-2104: Computer Based Accounting
PDF
No ratings yet
Assignment PGD-2104: Computer Based Accounting
14 pages
MCS-021 (2023-24) Solved Assignment
PDF
No ratings yet
MCS-021 (2023-24) Solved Assignment
34 pages
Files Inclusion Attack
PDF
100% (1)
Files Inclusion Attack
30 pages
Internet Technology Lab Exam
PDF
No ratings yet
Internet Technology Lab Exam
6 pages
Assignment 2
PDF
No ratings yet
Assignment 2
2 pages
CAPE Information Technology: U2 - M1 - O6 Data Flow Diagrams
PDF
No ratings yet
CAPE Information Technology: U2 - M1 - O6 Data Flow Diagrams
37 pages
Essay On Computer
PDF
No ratings yet
Essay On Computer
3 pages
Full Download of Computer Concepts Illustrated Introductory 9th Edition Parsons Solutions Manual in PDF DOCX Format
PDF
100% (11)
Full Download of Computer Concepts Illustrated Introductory 9th Edition Parsons Solutions Manual in PDF DOCX Format
47 pages
Water Bill
PDF
No ratings yet
Water Bill
11 pages
Algorithm BasicsFinal
PDF
No ratings yet
Algorithm BasicsFinal
51 pages