AP Computer Science Final Exam Questions

Ace your homework & exams now with Quizwiz!

Consider the following code segment that appends numbers to a list one at a time. data ← [ ] APPEND (data, 2) APPEND (data, 6) APPEND (data, 9) APPEND (data, 3) APPEND (data, 1) What is the value of data[2]after the code above is executed (Assume indexing begins with 1)

6

What is the output of the code segment below? The initial state of the array is shown for you to use as a reference. Index: 1, 2, 3, 4, 5, 6 Data: 5, 8, 3, 4, 2, 1 i ← 4 a ← data[i] b ← data[i + 1] DISPLAY(a + b)

6

8 bits is enough to represent 256 different numbers. How many total bits do you need to represent 512 (twice as many) numbers?

9 bits

A student decides to draw a series of three dots(sort of like a snowman) as shown in the diagram. She wants each dot to be half the radius of the previous dot, and for the center to be on the edge of the dot below it. She writes the following code segement to do it:

2 var middle = bottom / 2; 3 var top = middle / 2;

What value will be displayed after the loop has executed? var a = 5; while (a > = 3){ a = a1; } console.log(n)

2

Two students have developed a protocol in which they send 4-bit messages to each other. They decide to modify their protocol to start sending 8-bit messages instead. How many more values can be represented in an 8-bit message than a 4-bit message?

24 = 16 times as many values

A video-streaming Web site uses 32-bit integers to count the number of times each video has been played. In anticipation of some videos being played more times than can be represented with 32 bits, the Web site is planning to change to 64-bit integers for the counter. Which of the following best describes the result of using 64-bit integers instead of 32-bit integers?

2^32 times as many values can be represented.

The counter variable in the code below increments by 1 each time through the loop. What will the value of counterbe after the following loop executes? var counter = 0; var n = 6; while(n > 0){ n = n 2; counter = counter + 1; } console.log(counter)

3

What is stored in list data after the following code segment is run? Index: 1, 2, 3 Data: 0, 1, 2 data ← [0,1,2] INSERT(data, 1, 3) INSERT(data, 2, 4) INSERT(data, 3, 5)

3, 4, 5, 0, 1, 2

The world is currently in a transition to using IPv6, a newer version of the IP protocol that uses 128-bit addresses instead of 32-bit addresses used by IPv4. What is the main problem that IPv6 was created to solve?

32-bit addresses could not ensure that every internet-connected device can receive a unique IP address

What will be displayed as a result of the code below executing? var a = 5; while (a < 5) { a = a 1; } console.log(a)

5

What is the minimum number of bits you would need to encode the 26 letters of the alphabet plus a space - a total of 27 characters?

5 bits

What is the output of the following JavaScript code segment?

55

What is the output of the following JavaScript code segment?

5hello

Consider the JavaScript code segment below. Which statement should be used in place of <missing code> such that the alarm is set to 9:00 am on weekends, and 6:30 am on weekdays.

(day == "Saturday") || (day == "Sunday")

Study the code segment below. Values of x and y will be displayed multiple times during the running of the program. From the list of possible outputs, choose two of the outputs that are impossible for this code to produce. x ← 0 REPEAT_UNTIL( x = 3 ) y ← 0 x ← x+1 REPEAT_UNTIL ( y = 3 ){ y ← y+1 DISPLAY( x + ", " + y) } }

- 0,0 - 2,4

Which of the following are actions a programmer could take when debugging a segment of code that could most likely lead to finding a problem and fixing it?

- Display the value of variables at various points during the program. - Ask a friend or collaborator to look over the code segment to see if they are able to find any errors.

What does the following code segment display? Index: 1, 2, 3, 4, 5 Data: 3, 5, 8, 2, 1 data ← [3, 5, 8, 2, 1] REMOVE(data, 3) DISPLAY(data[3])

2

Which of the following lists the numbers in order from least to greatest? 01010 1110 010000

01010, 1110, 010000

Approximately how much bigger (how many more bytes) is a megabyte than a kilobyte?

1,000 times bigger

Consider the following flow chart showing a process for program execution. Given that a = 5, and b = 10, what will be displayed by the program?

10

Given the following array, what will the code segment below display after being run? The initial state of the array is shown for you to use as a reference. Index: 1, 2, 3, 4, 5, 6 Data: 5, 8, 3, 4, 2, 1 data ← [5, 8, 3, 4, 2, 1] a ← data[5] b ← data[2] DISPLAY(a + b)

10

What is contained in the list data after the following code segment is run? Index: 1, 2, 3, 4, 5 data: 10, 45, 38, 16, 23 data ← [10, 45, 38 16 23] REMOVE(data, 2) REMOVE(data, 3)

10, 38, 23

What is the 4-bit binary number for the decimal number Ten (10)?

1010

A programmer designed a program for an airline to determine whether there is an extra fee on a checked bag. The logic is shown in the flow chart at right. The code they wrote (see below) runs without error, but unfortunately it does not work as intended. What is the problem? Consider the list of values below and choose two that if assigned to weight will result in the incorrect message being displayed as the response

125

Choose the answer that is NOT a feature of Public Key Cryptography:

A Public Key database ensures 3rd party accountability of security

What is one important naming convention of functions?

A function name should be as descriptive as possible to indicate what the function does.

Short Response: What might a programmer create a global variable instead of a local variable?

A global variable would be created if the variable is used throughout the program and not just in one specific function; ex. score needs to be changed when divided(function)

The Internet Engineering Task Force (IETF) defines the protocols and standards for how the Internet works. The members of the IETF are:

A loosely organized collection of citizens and engineers.

Pick the two expressions involving the Modulo operation that compute to the exact same value

A. 9 MOD 8 B. 1 MOD 16

Programming languages have some similarities and differences to the "natural" language you use in everyday speech. Select the two true statements about programming languages:

A. Ambiguities in natural language necessitate the creation of programming languages for controlling a computer B. Compared to the number of words in a natural language, the number of defined words in a programming language is very small.

Which of the following is true about the way digital data is transmitted on the Internet?

A. Bit-rate (bandwidth) is the time elapsed between the transmission and receipt of a piece of digital data.

An artist makes an RGB raster image in which each pixel color is encoded with 12-bits --- 4 bits each for red, green and blue. Which of the following correctly shows the hexadecimal value for Red as a 12-bit representation.

A. F00

To uncompress the data back into its original binary state, you simply reverse the process. This technique is an example of what type of compression?

A. Lossless compression

Which one of the following statements about functions is TRUE

A. Two functions in a single program can have different names but contain identical code.

The image below shows an encoding for a black and white pixel image. The first two bytes of the data (circled in red) are used to encode the width and height of the image. What is the best term for this type of "data about the data"?

A. metadata

Explain how abstraction allows for the creation of increasingly complex systems. Reference top-down design strategy in your response.

Abstraction allows for the creation of increasingly complex systems because it is random and will always create something different. The design will not be a specific shape, it will be a bunch of connected lines with angles.

A middle school is expanding to open a high school next year, doubling the total number of students. The school keeps a database in which each student's unique ID number is stored as an 8 bit number called studentID. Before the arrival of the new students almost every 8 bit number has already been assigned to a student. which is the smallest change to the way studentID is represented necessary to ensure each incoming student receives a unique ID?

Add a bit to studentID to double the number of IDs that the database can represent.

What is a Distributed Denial of Service (DDoS) attack?

An attempt to compromise a single target by flooding it with requests from multiple systems.

Which of the following is FALSE about element IDs?

An element with a unique ID must always have an event handler associated with it.

ASCII characters can also be represented by binary numbers. According to ASCII character encoding, which of the following letters is represented by the 8-bit binary value: 0100 0010

B. ASCII Character: B

Which of the following statements are true about routers and routing on the Internet?

B. Routers are hierarchical and the "root" router is responsible for communicating to sub-routers the best paths for them to route internet traffic. C. A packet traveling between two computers on the Internet may be rerouted many times along the way or even lost or "dropped".

Which of the following is NOT true about TCP/IP packets?

B. TCP guarantees that no packets are ever dropped

A programmer wrote an essay for his history class, and realized he has confused the names of Benjamin Franklin and Alexander Grahm Bell.

Benjamin Franklin was born 141 years before Benjamin Franklin, so he was never able to telephone his neighbors.

Assume that a variable temperature is assigned like this: var temperature = 30; Choose the two (2) Boolean expressions that evaluate to FALSE.

D. (temperature == 0) || (temperature > 32) E. (temperature < 0) || (temperature >32)

What is the output to the console after the following code segment is executed? 1. var x = 10;

Error. Cannot make a new variable x inside function increase()

What is the output to the console after the following code segment is executed? 1. fiveMore();

Error. Unknown Identifier: x

Which of the following is FALSE about event-driven programs?

Event-driven programs do not implement algorithms.

In JavaScript you can find the number of characters in String by using .length. For example: For the next two questions, consider the following JavaScript code segment. If the above code segment is run, and "hello" is entered at the prompt, what will be displayed in the console?

I have never heard that before.

Consider the following incorrect program, which is intended to move the robot around the perimeter of a grid, as indicated by the drawing below. The starting position and direction of the robot is indicated in the diagram.

Fig: What the robot is supposed to do

For this scenario related to turtle drawing, indicate whether it is better to write a loop or a function (or a set of functions) to handle the task: Drawing a circle of any size at any point on the screen

Function(s)

For this scenario related to turtle drawing, indicate whether it is better to write a loop or a function (or a set of functions) to handle the task: Drawing out the letters of a word "HELLO"

Function(s)

Which of the following is NOT true about functions in programming?

Functions cannot make calls to other functions within the same program.

From the list provided choose the two (2) answers that correctly describe which internet protocol relies on the other

HTTP relies on TCP/IP TCP/IP relies on DNS

Which of the following are true statements about digital certificates in Web browsers? I. Digital certificates are used to verify the ownership of encrypted keys used in secured communication II. Digital certificates are used to verify that the connection to a Web site is fault tolerant.

I only

A pseudocode program is started below that asks the user for input and stores the value in a variable. Continue writing pseudocode to accomplish this task: If the hour is within the school day (8 to 15) then display "Nice to see you!", Otherwise, display "It's time to go home!

IF (hour >= 8) AND (hour <= 15) { DISPLAY ("Nice to see you!") } ELSE{ DISPLAY ("It's time to go home!") }

A programmer created a list of all of her sibling's ages: 1 2 3 ages: 10 12 17 Unfortunately, she made a typo! Her middle sibling is 13 years old. Which of the following solutions will not​fix the typo?

INSERT the value 13 at the index of 2

What will be displayed as a result of the javascript code below executing? var a = 0; while( a != 5 ){ a = a+2; } console.log(a);

Infinite Loop

How does a computer resolve a domain name into an IP address?

It asks a DNS server for the corresponding IP address

What is the best explanation for why digital data is represented in computers in binary?

It's easier, cheaper, and more reliable to build machines and devices that only have to distinguish between binary states.

The colors of the pixels in a digital image are often represented by red, green, and blue values between 0 and 255 (an RGB triplet). A photographer is manipulating a digital image to lighten it because all of the RGB values in the image are less than 100, making it very dark. He does this by adding 20 to the R, G, and B values of each pixel, then overwriting the original image. What type of transformation is the photographer using on the digital image?

Lossless transformation

In very broad terms the MP3 audio compression algorithm identifies frequencies and volume levels - low and high - that are outside the range of human hearing and removes the data representing these frequencies from the original. This technique results in a smaller audio file that sounds exactly the same to the human ear. This technique is an example of what type of compression?

Lossy compression

Which of the following BEST describes how protocols on the Internet (e.g. IP, TCP, HTTP) make use of abstraction to accomplish their respective purposes?

Low level protocols can provide functionality to high level protocols without revealing the details of how this is accomplished.

Which of the following most accurately describes Moore's Law:

Moore's Law is the observation that computing power tends to double every two years

Given the options below, which lines should be removed so the program will work as intended?

Line 3 and Line 4

For this scenario related to turtle drawing, indicate whether it is better to write a loop or a function (or a set of functions) to handle the task: Drawing 100 tiny dots in a line

Loop

For this scenario related to turtle drawing, indicate whether it is better to write a loop or a function (or a set of functions) to handle the task: Drawing a hexagon (six-sided shape)

Loop

Why are parameters useful when programming?

Parameters allow for more flexible, generalized behaviors in functions

When programmers work together, what is an example of how abstraction in programming can promote collaboration?

Programmers can use functions created by their partners, relying on the functionality without needing to know the specific details of how the function is implemented.

Which of the following statements best describes the properties of public key encryption?

Public key encryption is an encryption method which relies on separate keys for encrypting and decrypting information.

A robot is represented as a triangle in a grid of squares. The initial position and direction of the robot is shown below. The robot can move onto a white square, but cannot move into a black region. Consider the following program: REPEAT 4 TIMES { REPEAT UNTIL (NOT CAN_MOVE (forward)) { MOVE_FORWARD () } REPEAT UNTIL ( CAN_MOVE(forward) ) { ROTATE_LEFT () } } After running the code above, what will the ending location and direction of the robot be?

Robot will be in the bottom left corner of the screen, tip pointing up towards the top.

Which of the following is NOT true about representing digital data?

Some large numbers cannot be represented in binary and can only be represented in decimal.

Which of the following statements about strings in JavaScript is FALSE?

Strings with numerical digits in them are invalid.

Fill in the blank of the following statement: "______ encryption is a method of encryption involving one key for both encryption and decryption."

Symmetric

Consider the code segment below given in pseudo code (see reference above). Assuming that variables a, b and c already have numeric values assigned to them, what is the expected output of this code segment?

The code will display the largest of the three values

A Boolean expression is an expression that evaluates to which of the of the following?

True/False

A programmer is writing a system that is intended to be able to store large amounts of personal data. As the programmer develops the data system, which of the following is LEAST likely to impact the programmer's choices in designing the structure of the system?

The frequency of a particular item occurring in a data set.

What is the most likely outcome of running the code shown at right?

The program will run without error, but will not draw anything.

Which of the following is a true statement about data compression?

There are trade-offs involved in choosing a compression technique for storing and transmitting data.

Consider the following JavaScript code segment. Something is wrong with the logic in the program above. For which values of time will the greeting "Good Morning" be displayed?

There is no value of time that will result in "Good Morning" being displayed

If the above code segment is run, and "goodbye" is entered into the prompt, what will be displayed in the console?

Use that word on the SAT.

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem?

When the problem cannot be solved in a reasonable time and an approximate solution is acceptable

A school starts tracking which websites each computer in the school is visiting by monitoring the packets leaving the school. Which of the following is MOST likely to be answerable using all the data collected by this monitoring?

Which websites are most frequently visited before and after school hours from a school computer

Which of the following is true about while loops in Javascript?

While loops run as longs as a given boolean condition is true.

A coffee shop is considering accepting orders and payments through their phone app and have decided to use public key encryption to encrypt their customers' credit card information. Is this a secure form of payment?

Yes, public key encryption is built upon computationally hard problems that even powerful computers cannot easily solve.

What is the expected output of the given pseudo code segment? A reference for the pseudo code can be found immediately below the question

You are old enough to be President!

Which of the following scenarios is most characteristic of a phishing attack.

You get an email from the IT support desk that asks you to send a reply email with your username and password to verify your account

Consider the following segment given in pseudo code (see reference from previous question): What will be displayed if grade is set to 70?

You passed! (apparently this is the answer according to Quia)

Which of the following will call the function drawStar?

drawStar ( );

Consider the code segment below: var a = 0; var b = 3; var c = 4; a = a+c b = a+c c = a+c What are the values of a, b, and c after this code segment has been run?

a:4 , b:8, c:8

According to the domain name system (DNS), which of the following is a subdomain of the domain example.com?

about.example.com

Which of the following JavaScript statements will result in the following output being displayed to the console?

console.log("Hello! \nHow are you?");

she would like the variable to increase by 1. What code should Jasmine insert where it says in order for her app to work?

cartTotal = cartTotal +1;

She wrote the code but there is a problem: it runs in an infinite loop. How can Tiffany change her code so it doesn't loop forever? 0 var numItems = promptNum("How many items?"); 1 var total = 0; 2 while (numItems > 0){ 3 total = total + promptNum("Enter next item price"); 4 } 5 console.log("The total is" + total);

dd after line 3: numItems = numItems - 1;

Select the answer that lists the units of bytes in ascending order (from smallest to largest)

kilobyte, gigabyte, terabyte

A statistician would like to simulate rolling a single die until she has rolled the die a total of 100 times, or she rolls a six a total of 25 times, whichever comes first. Which boolean expression should she use for the <missing code>​to accomplish this? var rolls = 0; var sixes = 0; while ( <missing code> ​){ var nextRoll = randomNumber(1, 6); if(nextRoll == 6) { sixes = sixes + 1; } rolls = rolls + 1; } console.log(rolls); console.log(sixes);

rolls < 100 && sixes < 25

Which of the following images is the most likely outcome of the drawing?

the square, with the cursor pointed towards the top of the paper in the left corner.

What is displayd by the console.log statement after the following code segment executes?

value is: 4

Which of the following code segments will correctly swap the values as described?

var temp = from; from = to; to = temp:

You are trying to write a function swap(list, a, b), which will swap the position of the two values at indexes and bin the list. Example: before and after a call to swap(list, 1, 2)on the list shown below: Swap(list, 1, 2) Before swap: Index: 1 2 3 List: 30 75 80 After swap: Index: 1 2 3 list: 75 30 80 The function header is defined for you. Choose the 3 lines of code that will perform the swap correctly. ​function swap(list, a, b){ <choose option from below> }

var temp = list[b]; list[b] = list[a]; list[a] = temp;


Related study sets

Chapter 12 Gene Expression EZ Test

View Set

Data Structures Final True/ False

View Set

Mod 7 DHCPv4 HW Homework in Homework

View Set

M9 Life Insurance and Investment-linked policies - Chapter 6 Participating Life Insurance Policies

View Set

SFDC Sales Cloud Certification - NaBil

View Set

Chapter 13: Integrative Physiology I: Control of Body Movement

View Set

008 - Networking - C11.1. WAN Concepts / Questions

View Set