Algorithm and Programming

Algorithm and Programming

67 questions · Fundamental Engineering · 51–67

Practice

Which of the following is a binary search tree?

When the procedure described below is executed in sequence for an empty stack and empty queue, what is the value assigned to variable x? Here, the functions used in the procedure are defined as follows:

[Function definitions] push(y):pushes data y onto the top of the stack. pop():removes the data from the top of the stack and returns it as the function value. enq(y):inserts data y at the tail of the queue. deq():removes the data from the head of the queue and returns it as the function value.

[Procedure]

  push(a)

  push(b)

  enq(pop())

  enq(c)

  push(d)

  push(deq())

  x ← pop()

For a function f(x, y) defined below, what is the value of f(775, 527)? Here, x mod y represents the remainder after division of x by y.

f(x, y): if y = 0 then return x else return f(y, x mod y)

The flowchart below shows the algorithm of concatenating two character strings in X and Y, with the resulting character string in Z. Which of the following is the appropriate pair of operations to insert in the blanks, A and B? Here, X and Y are character arrays of dimensions m and n, respectively, where the i-th character of each string is stored as the i-th element of the character array.

StartLoop 1k:1, 1, mALoop 1Loop 2k:1, 1, nBLoop 2End

Note:

The description in Loop 1 indicates that variable k varies from 1 to m by 1. So does Loop 2.

OptionAB

Data A, B, C and D are entered as an input sequence. Which of the following is a possible output sequence by only using a single stack?

For integers x and y (x > y ≥ 0), a function F(x, y) is defined as follows. What is the value F(231, 15)? Here, x mod y represents the remainder after division of x by y.

F(x, y) =
x(when y = 0)F(y, x mod y)(when y > 0)

In a web environment, which of the following is the name of a program that runs on a web server and achieves dynamic processing?

Which of the following is a binary search tree whose keys are numbers assigned to nodes in natural order?

Function F(n) is a recursively defined integer function that calculates the factorial of n for any non-negative integer n. Which of the following is an appropriate expression for the blank A?

F(0) = 1

F(n) = A (if n > 0)

What is the result of the procedure in the flowchart below, when x and y are positive integers?

Starts0txt < yYesEndNott − yss + 1
OptionValue of sValue of t

In a direct organization file that has a range of storage addresses one (1) through six (6), the data is stored under the conditions below. Which of the following is the key value of the data that is stored in address one (1)?

[Conditions](1)Data is stored in the order of key values three (3), four (4), eight (8), 13, 14, and 18.(2)The storage address is the value that is the remainder obtained by dividing the key value of data by five (5) and then adding one (1) to it.(3)If the storage address is already occupied, the data is stored in the next address. This process is repeated until the data is stored. The next address of the last address is the first address.(4)In the initial status, nothing is stored in the file.

The flowchart below shows the process of converting a decimal integer j (0 < j < 100) into an 8-digit binary number. The binary number is stored in array elements NISHIN(1) through NISHIN(8), starting from the lowest-order digit. Which of the following is the appropriate combination of processes to be inserted into blanks A and B in the flowchart? Here, j div 2 represents the integer part of the quotient when j is divided by 2, and j mod 2 represents the remainder when j is divided by 2.

StartInput jConversionk: 1, 1, 8 (Note)ABConversionEnd

(Note) The repetition specification of a loop limit shows variable name: initial value, increment, final value.

OptionAB

When the flowchart in Figure 1 was executed with array A in the state shown in Figure 2, array B came to be in the state shown in Figure 3. Which of the following is the operation to be inserted into blank a in Figure 1? Here, the elements of arrays A and B are A(i, j) and B(i, j), respectively.

StartLoop 1i: 0,1,7 (Note)Loop 2j: 0,1,7 (Note)aLoop 2Loop 1End

Figure 1 Flowchart

(Note) The repetition specification of a loop limit shows variable name: initial value, increment, final value.

ji0123456701234567∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Figure 2 State of array A

ji0123456701234567∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Figure 3 State of array B after execution

Which of the following is an appropriate item to be specified in the coding standards of a program?

The tree structure in the figure is a binary search tree. Which of the following is the appropriate relationship in magnitude among the values of a through g? Here, no two of the values of a through g are the same.

abcdefg

Data whose key is one lowercase letter of the alphabet (any of a, b, …, z) is stored in a hash table of size 10. As the hash function, the digit in the ones place of the ASCII code of the letter expressed in decimal notation is used. Which of the following is the combination of keys that causes a collision? In ASCII code, consecutive binary numbers in ascending order are assigned as codes in alphabetical order.

In the following flowchart, in order to have the processing executed in the order

① → ② → ③ → ⑤ → ② → ③ → ④ → ② → ⑥

which of the following is the relationship between the initial values a and b that should be given to m and n in ①? Here, a and b are both positive integers.

Start①m ← an ← b②m : n≠③m : n<=>④m ← (m − n)⑤n ← (n − m)⑥Print thevalue of mEnd