357 Lê Hồng Phong, P.2, Q.10, TP.HCM 1900 7060 - 028 3622 8849 info@luyenthitap.edu.vn

Practice Test - Algorithms and Programming - AP Computer Science Principles Premium 2023

ALGORITHMS AND PROGRAMMING QUESTIONS

hVPkn02taIV61CFThtPAOhl_CuZzeRGclzQto98Z

1. What will the following algorithm display?

UbvEflYUczaKcJ2z_eiFOsFs8CD2IwqzYfm9Vye-

(A) 2 14 17
(B) 13 17 5
(C) 2 12 2
(D) 14 17 2


2. What will the following algorithm display?

5HYJTxwBwKxc720kc9sj-CAnsyeIHIhjqcM6l8PV

(A) 13
(B) 17
(C) 18
(D) 19


3. What will the following algorithm display?

Y4eVIjm74IwhdVniT8eMLzYLGAOUbvOBQ2ZXgE5H

(A) 0
(B) 42
(C) 84
(D) 126


4. What will the following algorithm display?

(A) Milk
(B) Milk Cookies Soda
(C) put them in a bag and they stay crisp
(D) Milk Cookies Soda Chips put them in a bag so you know they stay crisp


5. What is the value displayed after the program is run?

(A) a 8
(B) a 6
(C) 8 6
(D) 16 4


6. What is the value displayed after the program is run?

rw2DIbzUMNKfEiJx5vY6PD2NtmZR8f9ZNZk-V3q3

(A) a 8
(B) a c
(C) 8 6
(D) 16 4


7. What will the following algorithm display?

GzUfMKhf9rKVcQmNvobEaiq_7nyWaRFPAfN1-O2J

(A) 26
(B) 13
(C) 1
(D) 0


8. What will the following algorithm display?

TcE9WdqT2TUHuIsEA-HwY_5jdShB9mueqhky4gCl

(A) 26
(B) 13
(C) 1
(D) 0


9. What will the following algorithm display?

1rmUy6Eduo0iObvPNpxmNJIl-e9rXilsQ-X1picp

(A) 26
(B) 13
(C) 8
(D) 1


10. What will the following algorithm display?

IDVemHzwb8Zf0zSYuDZt2r-mLwltpf4CLr9EGp9j

(A) 26
(B) 13
(C) 8
(D) 0


11. What will the following algorithm display?

JEzRL4xwfcXti-IOKhpTbHDTYgYOP5Z5sTFksNRh

(A) 26
(B) 13
(C) 2
(D) 0


12. What will the following algorithm display?

o_sLLMG73YnKXrSkrGNfREzwhV8AkPSLciQ1DmV7

(A) 26
(B) 13
(C) 1
(D) 0


13. What will the following algorithm display?

ZHPmKvxDlTh6vlbTAaG8kDJ8iMBdUw_fS17mYpGB

(A) 26
(B) 13
(C) 1
(D) 0


14. What will the following code segment display?

3qenr4ifelD8pmnfBY4IqcGJdgrwDqQEwlaBpdoG

(A) 13 5
(B) 5 13
(C) a b
(D) 13 13


15. If this statement is executed many times, about what percentage of times does it display true?

2R0CJ2vb2PyCUhA-dQzqNMvawUnc1Bl8Psh-Jwky

(A) 9%
(B) 10%
(C) 60%
(D) 100%


16. If this statement is executed many times, about what percentage of times does it display true?

ff1k6WQZsRDv10DUaLBj3mIB6bfh3r-R8Xor3QzO

(A) 10%
(B) 20%
(C) 60%
(D) 100%


17. If this statement is executed many times, about what percentage of times does it display true?

ifUCZ_ro9grthKvxfrFPgVOM-0x6XSMFLzBE0C9J

(A) 0%
(B) 20%
(C) 60%
(D) 100%


18. If this statement is executed many times, about what percentage of times does it display true?

Q9sK_sMahEBLKj9eymztCMTmkifAidkBgoISkxAH

(A) 0%
(B) 20%
(C) 60%
(D) 100%


19. If this statement is executed many times, about what percentage of times does it display true?

FA8MgZDofOjNmwH11GP7NwpNCze0MVJ_73TlrpbL

(A) 0%
(B) 20%
(C) 60%
(D) 100%


20. If this statement is executed many times, about what percentage of times does it display true?

rV_LdxtDytxsDEwtGCMpxmBSSZ6Re17H6470lI1Y

(A) 9%
(B) 10%
(C) 60%
(D) 100%


21. If this statement is executed many times, about what percentage of times does it display true?

XHBb60CbWKbMwPdEk0v-85x42Q0f-q3J4RxNW9uR

(A) 20%
(B) 40%
(C) 60%
(D) 100%


22. If this statement is executed many times, about what percentage of times does it display true?

iRHHJ77pyG-8wa1yCrOBLW-UQsWaxmoXkitPJ_Ah

(A) 0%
(B) 40%
(C) 60%
(D) 100%


23. What is the percentage of times that this algorithm displays true?

o-uAv_c08o3g4Id5WoA9t5kDpeOXJfnv6pyhPw2i

(A) 0%
(B) 40%
(C) 60%
(D) 100%


24. The algorithm below displays true 60% of the time.

JIzLD1GrJVUvwCCucjxgOMFaSNpF1Zbqh0BXNZcV

What can replace the missing condition so the code segment works as intended?

(A) x < 10
(B) x ≤ 10
(C) x > 10
(D) x ≥ 10


25. What is the value displayed after the algorithm is run?

YJlma2TpavC33yA0jXuUb7CO2shfYqRWlqh-pDt9

(A) 0
(B) 1
(C) 10
(D) 13


26. What is the value displayed after the algorithm is run?

gUHU7qQB7Re65gw8v2YNlrC94UaFqgkq_OVN-yzv

(A) 0
(B) 1
(C) 10
(D) 12


27. What is the value displayed after the algorithm is run?

PIFNW35PZo964MbeR1amt9TnvZWmswYpzEwoGFY_

(A) 0
(B) 1
(C) 9
(D) 12


28. What is the value displayed after the algorithm is run?

s8h_0e9OcsqYrynhX8gHy9qNfYKe_G0j8KQaqTE8

(A) 0
(B) 1
(C) 10
(D) Nothing is displayed due to an infinite loop.


29. What is the value displayed after the algorithm is run?

VJlfMIarTjVw7in516al2gbWUhCIJG2Cr-Cla256

(A) 0
(B) 1
(C) 10
(D) 12


30. What is the value displayed after the algorithm is run?

w-Yb8Ln-Cx1T2KHbSi9BI2oWvGNOOjhpTTDmQb-o

(A) 0
(B) 9
(C) 10
(D) 12


31. What is the value displayed after the algorithm is run?

Csn3Yjy_3gTdqx-MjKO5DYPh17SvtHHvfBCEieae

(A) 2 4 6
(B) 0 2 4 6
(C) 6
(D) 8


32. What is the value displayed after the algorithm is run?

RkCclf-HTMgTmrgvH06dZSY8m7qgAax563zcG9uU

(A) 2 4 6
(B) 0 2 4 6
(C) 6
(D) 8


33. What is the value displayed after the algorithm is run?

gdK_7l6ms8ceSz37kmD6OAWIJBN0m8nIeP3Rp5qR

(A) Nothing is displayed.
(B) Even Even Even
(C) ODD ODD ODD
(D) 2 4 6


34. What is the value displayed after the algorithm is run?

O0dip4irDMrchajrXD1g7a-4DhkcPcD1foGKgjFy

(A) Nothing is displayed.
(B) Even Even Even
(C) ODD ODD ODD
(D) 2 4 6


35. What is the value displayed after the algorithm is run?

YI3k51eq-xrFsLFrV9FTEPtx8s4Nb2hryy-cjP7M

(A) 0
(B) 2
(C) 5
(D) 6


36. What is displayed after the algorithm is run?

q1YS1pWGV7B8BCBsjmY8fv_3QiJ8nnmkzAZNJhmj

(A) 0
(B) 3
(C) 9
(D) 12


37. What is displayed after the algorithm is run?

xScL4G6N-gLp8fsnrnDyDJOW5T5lGuKuYitALoDd

(A) 0
(B) 3
(C) 9
(D) 12


38. How many numbers will the following algorithm display?

v2rMNJCJB8J0Lw-rFkC1yUPB8LmwwqQuJYybmPdx

(A) 0
(B) 10
(C) 100
(D) An infinite amount


39. What will be printed when this algorithm is run?

q25hvUaKpMMx1DAstKC2yWe1NP7HYoIZffiJDKIP

(A) Pineapple
(B) Kumquat
(C) Star Fruit
(D) Pineapple Kumquat Star Fruit


40. How many times will “fish” be displayed?

QN6m7BFfe_zcrXwVNrFWjxZnJEzZg3BfGakb4PLw

(A) 4
(B) 3
(C) 2
(D) 1


41. What is displayed at the end of the algorithm?

nC5kdG_0JQmeRLSaJpF_ofd5Dd4dui1qfDAKpA7T

(A) Elephant
(B) Alligator Ostrich
(C) Alligator
(D) Elephant Alligator Ostrich


42. A user inputs 5 for the value of a. What is a possible value of c?

a ← INPUT( )
b ← RANDOM(a, 6)
cb − 6

(A) −3
(B) −1
(C)  1
(D)  3


43. The following is a truth table for all possible values of A and B.

xMQO_JwobCHsmBa48Qi3eYxjRllHEOMSS73t-J8k

Which of the following can replace the missing condition?

(A) (A AND B)
(B) (A OR B)
(C) (A OR NOT(A))
(D) (A AND NOT(A))


44. The following is a truth table for all possible values of A.

bZ5sZcfR7Nm3WoYbmeRCjFyV-DosqMzk_HZn_HCA

Which of the following can replace the missing condition?

(A) (A AND B)
(B) (A OR B)
(C) (A OR NOT(A))
(D) (A AND NOT(A))


45. Which of the following statements describes the major building blocks of algorithms?

I. Sequencing—statements execute in a given order
II. Selection—Boolean conditions determine an algorithm’s path
III. Iteration—the repetition of parts of an algorithm

(A) I only
(B) I and II only
(C) II and III only
(D) I, II, and III


46. A programmer is writing code to display the difference of the squares of two user-inputted numbers (i.e., a2b2). The following lines represent parts of the code. What order should they be placed in?

1. DISPLAY(a - b)
2. b ← INPUT()
3. aa * a
4. a ← INPUT()
5. bb * b

(A) 1, 2, 3, 4, 5
(B) 1, 2, 4, 5, 3
(C) 2, 4, 3, 5, 1
(D) 4, 2, 5, 1, 3


47. An algorithm compares the user-inputted number picked to the randomly selected number drawing and calls the method victoryJingle( ) if the two are the same. What should replace  in the following algorithm?

i01vtK50_yRVRY1UEJpRblW4RhjijVM1dZDz45sh

(A) IF(picked AND drawing)
(B) IF(picked = drawing)
(C) IF(picked ≠ drawing)
(D) IF(picked NOT drawing)


48. Using the program below, where will the robot land after the code segment executes?

TCUuc3wmQAlK3lYEBFjfIkAbsaD8mic182ZFvNMV

(A)

biKhUgoRJhh9UFHosn5umutiUHPlvunhDfGAcAiO

(B)

H-ENh9oeTLhmmwjRU7l0I3VJGb0-KQ7Gc2Hu1I6o

(C)

YFVs4UcuvJ9kNVGt_in3yW-bHthmx9dhjy0RQZKv

(D)

oKNywPEQY5A3VrEKLhHbtYyUbBAcu34z46lE-mAn


49. Using the program below, which of the following is a possible landing spot after the code segment executes?

f0CSx0E8Lvfnx8MPFitFRGRpyNRy2N8VKzoXG1q3

Line 1: move ← INPUT()
Line 2: REPEAT move TIMES
Line 3: {
Line 4: MOVE_FORWARD()
Line 5: ROTATE_RIGHT()
Line 6: }

jyiZO9lZQP2rE0V0zY4haFe3X4GwMJZd0ZPSWx6Z


50. Using the program below, what are the possible locations the robot could visit?

BzsyIticRII662V2-JayNbbVwZRx-p76Y9btkmPD

What are the possible landing spots for the robot?

(A)

bl3S-OQoX9gJcQHFlrhg2G0pTU6ujlOKGh77KzCz

(B)

iUUT0Fs-EJ3K-pxvfEUa67CsNxRDXdsBvITic5iP

(C)

vvxW0ce4YPY5gUOzTABhXbblV-_UYrQPwlj8HwpL

(D)

cLtXg_--05V_oJlWNyX9K5XZh_SVUVIQKHdSvk8v


51. Using the program below, where will the robot land after the code segment executes?

rm04lsbZ4_yBIJv3GHxGFTd5H39Cq-naC4K7KNWC

Starting Grid

beqOnvmULl3RdUW0YGCfCe3_fpWmFyxBKxH-zdHA

(A)

hRlk4xhVeph6suXg8OfgjobTyKs5Z0tKhI_lETNM

(B)

_SexqFCSGimSzd6iErldBteZ-vGsJCvUyTv_foSP

(C)

wgaMW5N_MaklJi2HU3meMg1TTlpVqqAhP4yUk_iQ

(D)

jZCHeYsCZW47HlNLCm2n9_Qs0w6yxJQDDbvEb-ZY


52. A programmer is creating an algorithm that doubles the square root of an inputted number and prints “small” if the result is less than 100. Which of the following would be an appropriate way to express it?

(A) input number n1
     square root of n1
     multiply n1 by 2
     is n1 < 100?
     yes -> print “small”
     no -> do nothing

(B)

 ixtrKqo8azHr7AjCzrzsMZYLlbQDy6tKR-rl-Dnd

(C) 

vnbpYvGAXK9ItzQE9XSwmLqF-yIrAziCmySjUmF9

(D) All of the above


53. Which of the following MUST an algorithm be written in or be converted into to be executed by a computer?

(A) Natural language
(B) Pseudocode
(C) High-level language
(D) Low-level machine language


54. Suppose that a programmer has created an algorithm using a low-level assembly language. If the algorithm is translated exactly into a higher-level language such as Python, will the solution utilized still work? Why?

(A) Yes, because an exact translation of an algorithm affects only the way that it is read.
(B) Yes, because an algorithm will always work regardless of the language.
(C) No, because the readability of a language affects how complex algorithms can be.
(D) No, because an algorithmic solution can exist only in the language it is written in.


55. Why is it important that algorithms be executed in a reasonable time?

(A) An algorithm that does not execute in a reasonable time will break the computer it is running on.
(B) An algorithm that does not execute in a reasonable time will be rejected by the compiler.
(C) This ensures that the algorithm is capable of handling the data sets it will be given.
(D) This ensures that the algorithm is capable of finding an exact answer.


56. An algorithm has n number of steps. Which of the following would NOT be considered a reasonable number of steps?

(A) n
(B) 4n + 8n2
(C) 100n4
(D) 3n


57. Why might a programmer decide to make a portion of an algorithm heuristic?

(A) Heuristics are more accurate, so adding them makes for a stronger algorithm.
(B) Although heuristics are not as accurate compared to an algorithmic solution, they are much faster to run, which would make the ultimate algorithm more efficient.
(C) Heuristics are always easier to add into a program.
(D) Heuristics make an algorithm much harder to copy.


58. Which of the following would be considered a heuristic solution?

(A) A file-organizing algorithm determines the content of a file based on a certain number of bytes in the beginning of the file.
(B) A sorting algorithm passes every value, swapping two values where the first is lower. This repeats until there are no more swaps left.
(C) An antivirus program scans the entirety of every file on the hard drive.
(D) A searching algorithm determines the bit-level location of a text string in a document.

 

ALGORITHMS AND PROGRAMMING QUESTIONS PART 2

qmePBCJPr1qs7Ew5AYQWul0bekmEdQDhYxrVQrqp

 59. What will the following call to the procedure “mystery” display?

TnMmNz5sgptEStPEQp_7TFnIM0ienWNa7GiaBiVv

(A) even
(B) odd
(C) True
(D) False


60. What will the following call to the procedure “mystery” display?

5SuZRYSnKO4ZyXMu4sBtbxuUjsK6klJcyD9GNIX0

(A) even
(B) odd
(C) True
(D) False


61. What will the following call to the procedure “mystery” display?

r17dFpnmuYK9NetJVedl6Dr3o5h0YE1wAUajef-G

(A) 0
(B) 1
(C) 2
(D) Nothing is returned due to an infinite loop.


62. What will the following call to the procedure “mystery” display?

NHcXATSA-ib189yQQcPsiQVo2pLwGFbH447o7ySY

(A) 0
(B) 1
(C) 2
(D) Nothing is returned due to an infinite loop.


63. What will the following call to the procedure “mystery” display?

NYo52cULC8EGt67O-IM9YHRcBnYmqIY3NLXsF6ve

(A) 2 4
(B) 2 4 5
(C) 9
(D) 6 


64. What will the following call to the procedure “mystery” display?

H_aKdKjH2UWzLUsNAfziqoFBmJ9iXC0X-i5Rz-KE

(A) 0 2
(B) 2 4 5
(C) 2
(D) 5 


65. What will the following call to the procedure “mystery” display?

Crsz90Sm1wPmHgfa5_x1CWZg88hJIlMJWoLQllE4

(A) 0 2
(B) 2 4 5
(C) 2
(D) 5


66. What will the following call to the procedure “mystery” display?

Gf-AaZxk3LRwvqxxfIT89XEEazl0ZnRF1PeBsexV

(A) 0
(B) 2 4 5
(C) 2
(D) 5


67. What will the following call to the procedure “mystery” display?

hFAcgV6f2PuaJqcyQnGWOIO4Sz8OZrzYJVSUDyye

(A) 0
(B) 2 4 5
(C) 2
(D) 5


68. The following call to the procedure “mystery” is intended to display the number 2.

02h_09K_Jid14HCvq9vzwhPIb4Mpvq6-toG0Dp8N

Which of the following can be used to replace so that the procedure will work as intended?

(A) (num < 2)
(B) (num > 2)
(C) (num < 3)
(D) (num > 3)


69. The following call to the procedure “mystery” is intended to display the number 6.

VYgsOPhtlYh9JnPTwYMlFKobc2R_jHuTD5rSWDld

Which of the following can be used to replace so that the procedure will work as intended?

(A) (num < 3)
(B) (num > 3)
(C) (num < 6)
(D) (num > 5)


70. What will the following call to the procedure “mystery” display?

jjAzKQG8y3_KUIV8K0RGw5rOrR_3ct98WAbsE5Iu

(A) 0
(B) 1
(C) 2
(D) 3


71. What will the following call to the procedure “mystery” display?

z--IOtNcG8vNgBUcC-n995FdG_mY-2qJxzDZ3tzx

(A) 0
(B) 1
(C) 2
(D) 3


72. What will the following program display?

G78IT43S1SgcsrV5v19bNBmc4oC0LAak4aOa62ZF

(A) 0
(B) 4
(C) 13
(D) 35


73. What will the following program display?

AlftdOLEr0qZ6Kcie8buXN31wVe0Z5B3_nQaWwU6

(A) 0
(B) 12
(C) 16
(D) 35


74. What does list2 contain after the program is run?

p7OZz0nv-Mw1bsfuTOGss8o6ga8KThDt2rli23kt

(A) [6, 76, 4, 98]
(B) [1, 1, 35]
(C) [1, 1, 35, 6, 76, 4, 98]
(D) [ ]


75. What will the following program display?

7RaOwMYa0nbw-TcEiXSMAjXFtKG1GuTqdgV2SXEf

(A) 0
(B) 13
(C) 16
(D) 35


76. What will list2 contain after this program segment is run?

LFIyA_GOD6lccUDim8Lnrlcthic71tNHdrAKbjfq

(A) [6, 76, 4, 98]
(B) [1, 1, 35]
(C) [1, 1, 35, 6, 76, 4, 98]
(D) [ ]

 

77. What will list2 contain after this program segment is run?

-sYchbu05jM9n_SfyIV_ZH-V_ezr_GbHthMtkmQf

(A) [0]
(B) [−11]
(C) [−35]
(D) [ ]


78. What will list2 contain after this program segment is run? 

f05jZGJvt1hNqummLLKBX0hHJo11Fequm4cjgHnq

(A) [6, 76, 4, 98]
(B) [1, 1, 35]
(C) [1, 1, 35, 6, 76, 4, 98]
(D) [ ]


79. What will the following program display?

vso2VnlJLj0aXO23HjkdY86ODTf6Gnq2VU7MgND6

(A) 0
(B) 1
(C) 76
(D) 98


80. What will the following program display?

ivSdwYnjqZorCTqqfTdrb16MFfQzaZtjvi97FwHK

(A) 98
(B) 1
(C) 0
(D) −98


81. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

h7oaCKeCMxHsobtSuxqD-_BWqfFinuakFaFHWXmA

Code for the procedure “mystery” is shown here. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . .).

nTs-DaPZ7BccyLWY8tfWus-mCpu7Fm52gTmPwlvt

Which of the following shows a possible result of calling the procedure?

(A)

1b6c4fetIp3N75Vqb0JA0sM0gAbdQkbnrrOk_0kS

(B)

iahPM6gDzcI5OJJWsFvErSj04oQCUCy6SltEqV6D

(C)

HcDLdmCHT7PWN-bqZNoFFEotgPnfDvT3DinHP-Im

(D)

DDqbJD5h3nW4uZp19dcyzJBzUNyWFkACu22HXJaI


82. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

-57Sw-S1MGxOp7tTyVkeuzPJMc4JaJV2fJTO4yko

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . .).

g3uOKkeM6DuLljkQKigvgyUiO-U8WNhBGnGFIUkB

Which of the following shows the result of calling the procedure when p = 4?

(A)

4Zq6Vg-FcKVAlWMAg3lE9Moldu6puI7fiEQsiWpK

(B)

B52zOb3xfXZuQaAYR3yYkSVzEKemYqk0RZ-KeACc

(C)

aD-rAeCSjc98XW2lquOyPZtUrgW8c3EUmywqKS-P

(D) Error. The robot will be out of the grid.


83. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

HJOP2P-_JM-siORCXYUejo4lPUBmxI3qBOPprAgo

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . .).

nc_JEHh79eq9wi5SJ9tgePXA_HORzjfAHVL9K2WP

Which of the following shows the result of calling the procedure when p = 4?

(A)

Z8Bc3wGe_F-tJkVn9mOP788XxP4-pRbCuYkW3s4E

(B)

civQQDsjzClAs8YeWLUyEkbm_26iwfB8NwzJBjNJ

(C)

BlpCtj1UowehhCZ3XKlKqxbKhxA8bK5mgLfZZs63

(D)

XtSn9vpz8i9Qbs4vF1ieOqJVWGPEVPjteyvgVl7s


84. The program below is intended to find the highest non-negative number in a list.

kukSXs5b4Fxc07r4L6_tZTREA5nbEOkWFIuStUED

Does the program work as intended?

(A) Yes, the program works as intended; it displays 1.
(B) No, the program does not work as intended; the result starts at 0.
(C) Yes, the program works as intended; it displays 3.
(D) No, the program does not work as intended; the “IF” conditional should be “item > result AND item < 0.”


85. The following program is intended to find the lowest number in a list.

CN5CJlqSdImSMjYKIlKQrrjtc4jgjp1Atnl_m5xr

Does the program work as intended?

(A) Yes, the program works as intended; it displays −7.
(B) No, the program does not work as intended; the result is always list[1].
(C) Yes, the program works as intended; it displays 1.
(D) No, the program does not work as intended; it produces a runtime error.


86. The following program is intended to find the lowest number in a list.

vrgz7ZvzFdFsG6XKPhz3-7mnjJzVpN9RpdMQD_ZO

Does the program work as intended?

(A) Yes, the program works as intended and returns −10.
(B) No, the program does not work as intended; although this code runs, it returns a logical error of the value 0.
(C) Yes, the program works as intended and returns the value −1.
(D) No, the program does not work as intended and results in a runtime error not returning a number.


87. The following program is intended to find the greatest number in a list.

hnIRvJZcNbzA-5iwn5Nminx9Ex5_Qk9DmzZOxllH

Does the program work as intended?

(A) Yes, the program works as intended, returning −200.
(B) No, the program does not work as intended; the result never changes and instead returns −3.
(C) Yes, the program works as intended and returns −1.
(D) No, the program does not work as intended; it produces a runtime error.


88. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

KhtZDNyseuMKJ_e0K0-0EPhgqaYQhfAIW2ajHaBV

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . .).

UDMX0h0-fWzgVNjro4K0Pe0sg8P_56L2g-5m2vIQ

Which of the following shows the result of calling the procedure when mystery(6)?

(A)

08nOa3vBJIWd1uVLVvrZIFghffAiA21i4CD9G_cE

(B)

srQ_G3MK-tpEZnl2mWY3RV5s1tzmzl_IKnpxYVbg

(C)

PECzO_npLo09JovZRTu8efouxEeBWipBX1z-XQr1

(D)

WnRRblvEpcawRtCj1HNpZS1sXKYkmE6kEHu_uRQS


89. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

vtbHlIXQrzD2y451BCPrc-q0Rqrc6_PpLfK4MVuB

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . .).

40TJ7YZdCreGwnQ0PWa6wdLRD4rrkY9dpLfSLa6X

Which of the following shows the result of calling the procedure when calling mystery(6)?

(A)

powshM50wOcVgclIxr-8Nbo1xq7sycZvTj4yTOGe

(B)

eaYeXVICABarQQCt66ULv-rYiSoWryUcGDNUoAWZ

(C)

OuGvyFOzzPGp-88IlTRWAsKUFBkiEl0ZnG138qVO

(D) Error. The robot will stay in its current location and the program will terminate.


90. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom-left square of the grid and facing toward the top of the grid.

hJ427PNBv1WjMQp47Zwjsn1mr3Ipljh0VPqG_c_Q

Which of the following code segments produces the result above?

(A) n <- 2
      REPEAT n TIMES {
      ROTATE_RIGHT 
      MOVE_FORWARD
      ROTATE_LEFT
      MOVE_FORWARD
      }
(B) MOVE_FORWARD
      MOVE_FORWARD
      ROTATE_RIGHT
      MOVE_FORWARD
(C) n <- 2
      ROTATE_RIGHT
      REPEAT n TIMES
      {
         MOVE_FORWARD
       }
      ROTATE_LEFT
      MOVE_FORWARD
(D) n <- 2
      REPEAT n TIMES
       {
          ROTATE_RIGHT 
          MOVE_FORWARD
          ROTATE_LEFT 
  MOVE_FORWARD
  }
  ROTATE_RIGHT


91. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

TyRzMgQfjq9rDFqR0zJ1unO9AG-Khn2kebMN4Jqv

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, . . . ).

20jZldJ5jVWybTFlpqPGjLY5tQVr_6E37FtNPuqf

Which of the following could be the result of calling the procedure for any positive value of p?

Select two answers.

(A) 

LODGZEYXlKjfsNVcFoLjKdBUfaddneJ45S0pkPTx

(B)

7Anf80l1egXTt5hbK1COjGg2jtxuPCRZVfZRkgos

(C)

vwXO5MIRlIyEueqCfD8jiOt0pyNEp5g-x93v3MMH

(D)

X4leW9HtBM7yFJlZcAT5sKa_24fKpeyKtUfhygIG


92. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the top-left square of the grid and facing toward the top of the grid.

JzbwhUaxhKFOjzvEeZTAyT4vHTjI_-jqBHJSsVOW

Code for the procedure “mystery” is shown below. Assume that the parameter p has been assigned a positive integer value of either 0 or 1.

g6m5Lq6rN8jKt5CCw5Ug9u8nAPsuTED4GbyLOrR2

Which of the following shows the result of calling the procedure for the value of p equal to 0 or 1?

Select two answers.

 kKw3ARXgb2WNXS3dEhCOVaRAQ8BNfccrwCtnobP6

ZG8ZNgt1uwOA56_Zf4Edj4_uylVo-KbTyRsLVezV


93. The following program is intended to find the average of a class’s scores.

BrBnos7TV7Mads5lIt7XNJuylnGI-4pAfyesjDUE

What does the code segment display?

(A) 0
(B) 5
(C) 20
(D) Nothing, runtime error


94. The following code segment is intended to find the maximum.

vd5TGvBtk3Qn5aAUaWvWRlWbJ-HrMHXWdgxR-OHF

Which of the following code segments can replace missing code to make the procedure work as intended?

(A) max > item
(B) max = item
(C) item > max
(D) max >= item


95. What does the following code segment return?

qGfnBlNApITfk9C-NrQLJ1uqIpLP5yH0egocn5_Z

(A) The number of even items in list
(B) The number of items in list
(C) The number of odd items in list
(D) Nothing, the code causes a runtime error

96. The following procedure is intended to find the amount of numbers in a list that are divisible by 5 and 2.

XyvdWmN3wildnifWIXYFL55kzIXoVAI6wah4vX02

Which of the following code segments can replace missing code to make the procedure work as intended?

(A) item MOD 5 = 0 OR item MOD 2 = 1
(B) item MOD 2 = 1 AND item MOD 5 = 1
(C) item MOD 5 = 0 AND item MOD 2 = 1
(D) item MOD 2 = 0 AND item MOD 5 = 0


97. The following code segment is intended to switch the values of x and y (assume x and y have already been initialized).

iF6z-Ng2xBOcVUjhP9vT0yCBfDoErkgPXhrrSOyQ

What can be done to make the code segment work as intended?

(A) Add “temp ← x” above “xy” and replace “y ← x” with “y ← temp.”
(B) Nothing, the code works as intended
(C) Add “temp ← x” below “x ← y
(D) Add “temp ← y” above “x ← y


98. What is the purpose of the following procedure?

tv33-antUOIjeHZo0BSNcJ7e1BKBPonCr0yL5d9v

(A) To find the amount of items in list
(B) To find the amount of items in list that are equal to number
(C) To find the amount of items in list that do not equal number
(D) Nothing, syntax error


99. What is returned by the following procedure?

wn0UvnhiqIMRcGiRR0Wi6Imp3FAEuaQw5A9vA2JA

(A) Nothing, syntax error
(B) To find the number of items in list that equal number
(C) To find the amount of items in list that are divisible by number
(D) Nothing, runtime error


100. The following procedure is intended to find the amount of values divisible by 15 in list.

Z6bfiGY8CD7ZJQr_riNNzlt87Wh60zfDcMeK09uw

What can replace missing code to make the function work as intended?

(A) item MOD 15 = 0
(B) item/15 = 1
(C) item MOD 15 = 1
(D) item/15 = 0


101. What will the following code segment display?

x ← 10
arr ← [“I”, “Love”, “Puppies”]
DISPLAY(arr[(x − LENGTH(arr)) MOD 4])

(A) I
(B) Love
(C) Puppies
(D) ArrayOutOfBoundsException


102. The method isFound(list, item) returns true if the item is in the list. What does list3 contain after the procedure is run below?

0ZCxkInX9Y16HpBY2YixgHWLypT3l1gIruRjgviv

(A) [−4, −98]
(B) [1, 6, −4]
(C) [−4]
(D) [1, 35, 6, 76, 4, 98, 5, 1, 8, 96, −4]


103. The method isFound(list, item) returns true if the item is in the list. What does list3 contain after the program is run below?

yoGrYnrg9KCIxqjOcLM-DnbQg05fi12kBxlbOaaZ

(A) [−4, −98]
(B) [1, 6, −4]
(C) [−4]
(D) [1, 6]


104. In the following program, which chart displays the ways in which the variables are changed?

x ← 5
y ← 10
z ← 15
z ← x − y
x ← z − 15
y ← y + x
x ← x + y + z

Caq9eX1ov1ciBpHmptYxGqHbXbxxVK_mNugv1qW6

105A programmer is curious about the accuracy of a new touchpad. To test it, he creates a program that graphically displays the location of the detected pressure and technical information about the device’s current state. What types of input and output are used by this program?

r3bM-K_XhqEqofZx3JJJNdDoxob1uLEC4BW2NjUw


106. Which of the following statements correctly describes a procedure?

I. A procedure can be used in any program as long as the original procedure can be located.
II. A procedure is able to work in any program without translation, regardless of the language in which the program is coded.
III. A procedure can be reused throughout a program.

(A) I only
(B) I and II only
(C) I and III only
(D) II and III only


107. Why is it generally considered a better idea to use procedures in a program?

Select two answers.

(A) Procedures make a program easier to read because they can collapse complex algorithms into a single procedure call.
(B) Procedures make a program easier to share because procedures used in the program will always be in the same file.
(C) Procedures are easier to read because they ensure that the code is working correctly.
(D) Procedures make a program easier to modify because editing a repeated algorithm in a procedure requires editing only the procedure.


108. What is the benefit of using a programming library?

(A) Programming libraries include procedures for common functions, such as exponents, which save programmers from having to make such procedures themselves.
(B) Programming libraries make it easy to translate code from one programming language to another.
(C) Programming libraries allow people to derive code from a compiled program because these libraries correspond between compiled code and high-level code.
(D) Programming libraries slow the execution time of programs.


109. The following question uses a robot in a grid. The robot is presented as a triangle, which is initially in the lower-left square of the grid and facing toward the top of the grid.

KXEnkD3qLGgKa3PQHlPP5LigsomB1oHHBE4xWhgb

Which of the following programs will place the robot in the ending grid location?

8ljJNpuJowk5B7glL0XYY-fCVGHwBUq1xHG6y7Qv


110. The following question uses a robot in a grid. The robot is presented as a triangle, which is initially in the lower row of the grid and facing up. Which of the following calls to moveAndTurn will result in the robot’s landing on the star?

 

JPrIMnhyefzK2W7MCgHQrp1xCQJ37tmL5BtJNbV2

qOAmj-bBM6uaqDZAl2mIXUtSNWLGpZCqJMLQf3mN

(A) moveAndTurn()
(B) moveAndTurn()
      moveAndTurn()
(C) moveAndTurn()
      moveAndTurn()
      moveAndTurn()

(D) moveAndTurn()
      moveAndTurn()
      moveAndTurn()
      moveAndTurn()


111. The following question uses a robot in a grid. The robot is presented as a triangle, which is initially in the lower-left row of the grid and is facing up. Which of the following calls to moveAndSpin will result in the robot’s landing on the star?

u-mgJZm4KcD9c1f8s5cy0Cml2ZJgWxm09WbW-opS

IrmhSJcMBKoKn_Ujq4nI5U_xQXwiGDjVmTXyqyDQ

Select two answers.

(A) moveAndSpin(4, 1)
      moveAndSpin(6, 0)

(B) moveAndSpin(0, 1)
      moveAndSpin(6, 3)
      moveAndSpin(4, 0)

(C) moveAndSpin(7, 3)
(D) moveAndSpin(0, 7)


112. A procedure is shown.

Be8hKkZuJB-O8FKC3fxGH2fmYedNwH3Y-JV7BYC6

Which of the following values for myList will cause the procedure mystery to assign the value of sum to the total value of all the elements in myList added together?

(A) [3, 5, 23, 88]
(B) [−3, −5]
(C) [−3, 5, −8]
(D) [−4, 0]


113. The following procedure is intended to return true if the string contained in target is in the data structure list.

otUib2qP5cL3_yyo7PMNE2JrZdowt9L3kOxSKeGB

Which of the following method calls will NOT return true?

(A) mystery(“pig”, [“cat”, “pig”])
(B) mystery(“pig”, [“cat”, “pig”, “snake”])
(C) mystery(“pig”, [“cat”, “pig”, “pig”])
(D) mystery(“Cookie”, [pig”, “elephant”, “Cookie”])


114. The following procedure is intended to return true if the string contained in the target is in the data structure list.

oBGmFS--vR0YQ-RE3vFxxKEPevibPcvXUymU_KJl

Which of the following test cases will return the value true?

(A) mystery(“pig”, [“cat”, “pig”])
(B) mystery(“pig”, [“cat”, “pig”, “snake”])
(C) mystery(“pig”, [“cat”, “pig”, “pig”])
(D) mystery(“pig”, [“pig”, “elephant”, “Cookie”]


115. In the procedure “mystery” below, the parameter number is a positive integer.

31eXE_JaqBELnTDwyHg4roYj1bY5hDQFVOBbHuLC

Which of the following best describes the result of running the procedure “mystery”?

(A) The procedure will return 0 if the number is even and −1 if the number is odd.
(B) The procedure will return −1 if the number is greater than 3 and 0 if the number is less than 3.
(C) The procedure will return −1 for all numbers that are greater than 0.
(D) This program will not return a number as it is in an infinite loop.


116. What will the procedure “mystery” below return when the parameters (A, B) are Boolean values?

6J5957P_E3AdXZNT_Um8_234kYKUSjpJ4_BRZOVu

(A) The output will be TRUE no matter the value of A or B.
(B) The output will be FALSE no matter the value of A or B.
(C) The output will be TRUE if input A is TRUE; otherwise it will be FALSE.
(D) The output will be TRUE if input B is TRUE; otherwise it will be FALSE.


117. What will the procedure “mystery” below return when the parameters (A, B) are Boolean values?

DlIc2sHxsp45bQHqe4ww5UPu3YVkeKdNYAgJy5r9

(A) The output will be TRUE no matter the value of A or B.
(B) The output will be FALSE no matter the value of A or B.
(C) The output will be TRUE if input A is TRUE; otherwise it will be FALSE.
(D) The output will be TRUE if input B is TRUE; otherwise it will be FALSE.

 

Tư vấn miễn phí
PHUONG NAM EDUCATION - HOTLINE: 1900 7060
Để lại số điện thoại
để được Phuong Nam Digital liên hệ tư vấn

Hoặc gọi ngay cho chúng tôi:
1900 7060

Gọi ngay
Zalo chat