ap comp test review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Malik decides to change the program so that the computer can run each loop iteration in parallel.Assuming that he runs the program on a computer that can run 5 tasks in parallel, how long will the parallelized solution take?

10 minutes

The flow chart below visualizes an algorithm to generate the "hailstone sequence", an interesting series of numbers. If the variable n starts off as 5, what would be displayed as a result of executing this algorithm? circled start -> n +1 -> n MOD 2 = 0 -> n<- n / 2 _> display

16 8 4 2 1

The algorithm below determines whether a given year is a leap year. If year is not divisible by 4, set leap_year to false Else if year is not divisible by 100, set leap_year to true Else if year is not divisible by 400, set leap_year to false Else, set leap_year to true. Which of these tables correctly shows the results of this algorithm on the given values of year?

1900 false 1984 true 2000 true 2002 false

What is displayed as a result of executing the algorithm in the flowchart? circled start / rectangle count <--- 1 / {diamond count < 5 } ---> false parallelogram display (count) (under diamond) true = rectangle count <-- count +1 , loops back to diamond (under parallelogram ) cirlced end

5

A software engineer at a mapping company is asked to write a geocoding program that can convert 600,000 addresses into latitude/longitude pairs. The geocoding needs to be completed by the next day, in time for a company deadline. When the engineer tries running the program on their computer, they realize that their computer cannot complete the task quickly enough. They decide to use distributed computing to improve the performance. How could a distributed computing solution help

A distributed computing solution can geocode multiple addresses at once by using multiple computers.

reasonable time

Algorithms with a polynomial efficiency or lower (constant, linear, square, cube, etc.) are said to run in a reasonable amount of time.

A computer scientist is analyzing four different algorithms used to sort a list. The table below shows the number of steps each algorithm took to sort lists of different sizes. Which algorithms appear to run in a reasonable time ? B 2 4 8 16 32

B and C

An online app for playing Chess utilizes a variety of algorithms. Their software engineers would like the algorithms to run in under a second so that users have a great experience. Which algorithm's runtime is most likely to be improved by the use of a heuristic? choose 1 answer

Choosing a good move when the computer is playing against the human

Which of the following statements are true ?

Every problem can be solved with n algorithm for all possible inputs, but some will take more than 100 years, even with the fastest possible computer

Which of these applications is NOT an example of distributed computing

Excel is a spreadsheets application developed by Microsoft. An Excel spreadsheet can contain many formulas that require computation, so loading a spreadsheet or changing its data can take a lot of time. To speed up the process, Excel is configured to utilize all of a computer's processors at once for concurrent computation.

A restaurant delivery app uses the following algorithm to choose the restaurants it features to each user. Which pseudocode is equivalent to the algorithm in the flowchart circle start --> openNow = true --> milesAway < 5 --> reviews > 3.5 --> showFeatured <-- true

IF (openNow = true AND milesAway < 5 AND reviews > 3.5) {showFeatured ← true} ELSE {showFeatured ← false}

Here's how n! works:

Multiply all whole numbers from the given number down to the number 1. For example: Instance: 4 houses to visit 4 x 3 x 2 x 1 = 24 Instance: 7 houses to visit 7 x 6 x 5 x 4 x 3 x 2 x 1 = 5,040

A programmer develops the procedure maxPairSum() to compute the sum of subsequent pairs in a list of numbers and return the maximum sum. For example, for a list of [2, 3, 4, 1], the sums of subsequent pairs are 5 (from 2 + 3), 7 (from 3 + 4), and 5 (from 4 + 1). The procedure should return the maximum sum of 7. The programmer tests it with maxPairSum([5, 4, -4, 3, 2]) and sees a return value of 9. Can the programmer conclude that the procedure works correctly for all inputs PROCEDURE maxPairSum(nums) {i ← 1maxSum ← 0REPEAT UNTIL (i = LENGTH(nums)) {sum ← nums[i] + nums[i + 1]IF (sum > maxSum) {maxSum ← sum}i ← i + 1}RETURN maxSum}

No, they've only verified that it works for that test case. Additional analysis and reasoning is necessary.

heuristics

Provide a "good enough" solution to a problem when an actual solution is impractical or impossible

A security engineer is developing antivirus software that detects when downloaded programs look similar to known viruses. They would like the software to be able to detect viruses that it's never seen before, by predicting whether or not a program will ever execute malicious code. After a bit of research, the engineer realizes that virus detection is an undecidable problem. What are the consequences of the problem being undecidable

The engineer might come up with an algorithm that correctly predicts the execution of malicious code in some cases, but the algorithm will not be correct all of the time.

A mathematician develops a program to solve systems of linear equations. When they use distributed computing techniques to run the program on two computers in parallel, they find a speedup of 2

The program completed in half the time with two computers versus one computer.

A 5 year old visits the Computer History Museum and gets excited about everything computers can do. They ask their mother, "Mom, can computers solve every problem?"

There are some problems a computer can't solve, no matter how much time they have.

unreasonable time

Unreasonable Time: Algorithms with exponential or factorial efficiencies are examples of algorithms that run in an unreasonable amount of time.

algorithm

a finite set of instructions that accomplish a task. There are usually many algorithms to solve the same problem, and many ways to write or express one algorithm including natural language, psuedocode, diagrams, and are implemented using programming code. All algorithms can be created by combining steps in three different ways.

problem

a general description of a task that can (or cannot) be solved with an algorithm There are usually many algorithms to solve the same problem, and many ways to write or express one algorithm including natural language, psuedocode, diagrams, and are implemented using programming code. All algorithms can be created by combining steps in three different ways.

efficiency

a measure of how many steps are needed to complete an algorithm

binary search

a search algorithm that starts at the middle of a sorted set of numbers and removes half of the data; this process repeats until the desired value is found or all elements have been eliminated.

linear search

a search algorithm which checks each element of a list, in order, until the desired value is found or all elements in the list have been checked.

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The code segment below is intended to display all multiples of 5 between the values and , inclusive. For example, if has the value and has the value , the code segment should display the values , , , and . Assume that and are multiples of 5 and that is less than . Line 1: i <--- start Line 2: REPEAT <MISSING EXPRESSION> TIMES Line 3: { Line 4: DISPLAY (i) Line 5: i <--- i + 5 Line 6: }

a. (( end - start ) /5 ) + 1

Suppose that a list of numbers contains values [-4, -1, 1, 5, 2, 10, 10, 15, 30]. Which of the following best explains why a binary search should NOT be used to search for an item in this list?

a. The elements of the list are not sorted

Which of the following best compares the execution times of the two versions of the program? Version I topScore ← 0 idList ← [1298702, 1356846, 8848491, 8675309] FOR EACH id IN idList { score ← GetPrediction (id) IF (score > topScore) { topScore ← score } DISPLAY (topScore) Version II idList ← [1298702, 1356846, 8848491, 8675309] topID ← idList[1] FOR EACH id IN idList { IF (GetPrediction (id) > GetPrediction (topID)) { topID ← id } DISPLAY (GetPrediction (topID))

a. version I requires approximately 5 more minutes to execute than version II b. version I requires approximately 1 more minuts to execute than version II c. version II requires approximately 5 more minutes to execute than version I

The two algorithms below are both intended to calculate the sum of squares from 1 to n, where n is any positive integer. For example, if n is 333, the algorithms should calculate a sum of 141414, from 1^2 + 2^2 + 3^212+22+321, squared, plus, 2, squared, plus, 3, squared. Algorithm 1: i ← 1sum ← 0REPEAT n TIMES {sum ← sum + (i * i)i ← i + 1}algorithm 2 alg 2; i ← 1sum ← 0REPEAT n TIMES {sum ← sum + (i + i)i ← i + 1} Which statements best describe the behavior of the algorithms?

algorithm 1 calculates the correct sum, but algorithm 2 does not

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Which of the following changes will NOT affect the results when the code segment is executed? Line 1: IF (a=0) Line 2: { Line 3: b <-- a + 10 Line 4: } Line 5: ELSE Line 6: { Line 7: b <-- a + 20 Line 8: }

b. changing line 3 to b <-- 10

For which of the following lists can a binary search be used to search for an item in the list? I. ["blue", "green", "jade", "mauve", "pink"] II. [5, 5, 5, 5, 6, 7, 8, 8, 8] III. [10, 5, 3, 2, -4, -8, -9, -12]

c. III only

Which of the following changes will NOT affect the results when the code segment is executed ? Line 1: IF (a=0) Line 2: { Line 3: b <-- a + 10 Line 4: } Line 5: ELSE Line 6: { Line 7: b <-- a + 20 Line 8: }

c. changing line 3 to b <-- 10

Which of the following best compares the values displayed by program A and B ? program A: i <-- 1 REPEAT UNTIL i > 10 DISPLAY i i <-- i + 1 Program B: i <-- 0 REPEAT UNTIL i >= 10 i <-- i + 1 DISPLAY i

c. program A and B display identical values in the same order

Consider the following program, which is intended to display the number of times a number target appears in a list. count <-- 0 FOR EACH n IN THE list If n = target count <--- count + 1 display [count] Which of the following best describes the behavior of the program?

c. the program correctly displays the number of times target appears in the list

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. In the program below, y is a positive integer (e.g., 1, 2, 3, ...). result <--- 0 REPEAT 3 TIMES result <--- result + 1

d. 3y

Which of the following best explains how algorithms that run on a computer can be used to solve problems?

d. some problems cannot be solved by an algorithm.

selection

deciding which steps to do next

iteration

doing some steps over and over

A programmer wants to present their idea for an algorithm at a company meeting. They're debating whether to express the algorithm in flow charts, pseudocode, or a programming language. Which of these is a good argument for expressing the algorithm in a flow chart at the company meeting?

flow charts can require less technical knowledge to understand than pseudocode or programming languages.

A flowchart is a way to visually represent an algorithm. The flowchart below uses the following building blocks. oval = start or end of algorithm rectangle = one or more processing steps, such as a statement that assigns a value to a variable diamond = a condition or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwise parallelogram = displays a message

flowchart information (not a question)

he Traveling Salesman Problem

he Traveling Salesman Problem can be solved with an algorithm, which checks each possible option. BUT, it would take massive amounts of computing power to compare every single option, especially as the number of homes to visit (otherwise known as nodes) increases. Therefore, it would take an unreasonable amount of time for the solution to be calculated for most instances of the problem.

How to prove max number of connection between n nodes is n*(n-1)/2

https://stackoverflow.com/questions/13730546/how-to-prove-max-number-of-connection-between-n-nodes-is-nn-1-2#:~:text=you%20have%20n%20%2D%20nodes%2C%20each,*(n%2D1)%2F2%20.

Makayla is developing software for an animal shelter. After some research, she comes up with this algorithm for calculating the number of daily calories required for a dog: Calculate the Resting Energy Requirement (RER) by raising the dog's weight to the 3/4 power and multiplying the result by 70 If the dog is neutered, multiply RER by 1.6 Otherwise, multiply RER by 1.8 After verifying the algorithm comes up with a reasonable number for a single dog, she decides to extend it to compute the total calories needed for all the dogs in the shelter each day. What structure must be added to the original algorithm so that it can compute the calories for multiple dogs?

iteration

Split author name into first name and last name. Combine last name, comma, first name, and period. Combine title with period, and wrap in italics style. Combine publisher, comma, year published, and period. Combine strings from steps 2-4. After using the algorithm successfully for a single book, she decides to extend it to generate citations for all of her books at once. What structure must be added to the original algorithm so that it can operate on multiple books?

iteration

The following algorithm computes the standard deviation of all the scores on the AP Computer Science Principles exam: Compute the average of all the scores. For each score, compute the square of its difference from the average. Sum the values from step 2. Divide the sum by the number of scores. Take the square root. Which building blocks are involved in this algorithm

iteration and sequencing

A university library contains 30,000 books. One of the librarians is developing a program that can search through a list of those books, sorted by their title, to determine whether they have a particular title. They need to decide whether to use the linear search or binary search algorithm. Which of the following statements are true about those algorithms? I. Binary search is more efficient than linear search on sorted lists. II. Linear search is more efficient than binary search on sorted lists. III. Binary search is more efficient than linear search on both sorted and unsorted lists. IV. Linear search and binary search are equally efficient on all types of lists.

only I

parallel computing

programs are broken into small pieces, some of which are run simultaneously

distributed computing

programs are run by multiple devices

sequential computing

programs run in order, one command at a time.

sequencing boxes

putting steps in an order

Randomly set coin1 to either "heads" or "tails" Randomly set coin2 to either "heads" or "tails" If coin1 matches coin2, increment score1 by 1 Otherwise, increment score2 by 1 Assuming that score1 and score2 start at 0, what will be the values of score1 and score2 after the three rounds heads and heads tails and tails heads and tails

score1 will be 2 and score2 will be 1

Akuchi develops an algorithm that counts the number of words used in an essay. Now they've been asked to extend the algorithm to ignore common words (like "the" and "to"). What structure must be added to the algorithm so that it does not count common words?

selection

The following algorithm computes the average height for a list of basketball player heights. Initialize a variable sum to 0. For each height in the list: Convert height from feet & inches format to total inches Add height to sum. Return sum divided by the total number of heights. Which building blocks are involved in this algorithm

sequencing and iteration

speedup

sequntial time divided by parallel time

Polynomial and Exponential both curve up. Why do you think only exponential is considered "unreasonable"?

sharp increasing line = unreasonable, everything else is reasonable, when it gets exponentially large very quick it becomes unreasonable

parallel

some steps are performed at the same time.

speedup

the time used to complete a task sequentially divided by the time to complete a task in parallel

Rania plans to build a pyramid out of concrete blocks. To help her decide how many blocks to buy, she comes up with this algorithm for a pyramid of a given height. Start by setting total to 0 and level to 1. Repeat for each level of pyramid:Multiply level by itself and store result.Add result to total. Display the final total. Assuming height represents the pyramid height, which of these correctly expresses that algorithm in pseudocode?

total ← 0level ← 1REPEAT UNTIL (level > height) {result ← level * leveltotal ← total + resultlevel ← level + 1}DISPLAY(total)


Set pelajaran terkait

Human Physiology Final Exam study guide

View Set

MEDSURG II: Saunders Diagnostic Testing

View Set

Chapter 2 Operations Strategy in a Global Environment

View Set

2022 Honors Human Geography: City Sustainability (Exam)

View Set

Psychology - CH. 9 & 11 Study Guide

View Set