Algorithms unit test

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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.

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

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? "Which response is the most accurate?

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

The goal of the procedure reportDisallowed is to iterate through a list of strings and report how many of them contain disallowed characters ("!" and "&"). For example, if given the list ["ahoy", "mateys!", "fish&chips!"], it should return the number 2 since two of the three strings contain disallowed characters.

reportDisallowed(["computer-sc!ence", "html&css", "javascr1pt"]) reportDisallowed(["c@lculus", "prob&stats", "factorials!"])

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

sequencing Iteration

Reese develops an algorithm to determine all the possible pizza topping combinations. For a list of 3 possible toppings ("pepper", "pineapple", "mushroom"), their algorithm generates these combinations:

The algorithm does not run in reasonable time. The algorithm runs in superpolynomial time.

Yuto implements an algorithm for finding the "greatest common divisor" of two numbers. For the numbers 54 and 24, it finds a greatest common divisor of 6. He counts the number of steps required by the algorithm for numbers of increasing digit length and comes up with this table: 2 4 3 6 4 8 5 10 6 12

The algorithm runs in polynomial time. The algorithm runs in reasonable time.

Which of these applications is NOT an example of distributed computing?

"Cities: Skylines" is a single-player city simulation game created by Paradox Interactive. The creators recommend playing the game on a computer with a CPU of at least four cores, so that the simulation can run on multiple processors at once. As cities increase in size, the game uses increasingly more of the processing power available.

A computational biologist develops a computationally intensive program for DNA sequence alignment. When they use distributed computing techniques to run the program on four computers in parallel, they find a speedup of 4. In this case, what does a speedup of 4 indicate?

The program completed in a quarter of the time with four computers versus one computer.

A software engineer is developing a new operating system. The operating system has to make a decision when it sees an application taking a long time to finish executing an instruction. Should the operating system force quit the application, assuming it will run forever? Or can the operating system detect that the application will finish processing, if it has a bit more time? The engineer does some research and discovers that this is an undecidable problem.

The problem may be solvable in some cases, but there is no algorithm that will solve the problem in all cases.

Aliya implements an algorithm that generates a "munching square" like this one:She generates squares of various sizes and counts the number of steps required each time.Her findings are summarized in this table:Square size Steps 6 36 12 144 24 576 48 2304 Based on the table, which of the following statements describe the run time for this algorithm?👁️Note that there are 2 answers to this question.

The algorithm runs in polynomial time. The algorithm runs in reasonable time.

"Aba speak" is a game invented by school children to disguise what they're speaking.When speaking, they transform each word following this algorithm:For each letter in word:If letter is vowel:Add "b" afterAdd that letter after "b"Following that algorithm, how would they transform the word "avocado"?

abavobocabadobo

An app for electric car owners includes a feature that shows them the charging station that's the nearest to them. To calculate that, the app first finds the 10 closest stations according to their beeline distance from the user address. It then uses the procedure below to calculate the driving distance to each station and returns the station with the shortest distance. The call to calcDrivingDistance() takes 3 seconds to return a result, as the driving directions algorithm requires searching through many possible routes to calculate the optimal route. The other operations, like incrementing the index and comparing the distances, take only a few nanoseconds.

30 seconds

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

year leap_year 1900 false 1984 true 2000 true 2002 false

The flow chart below visualizes the steps of an algorithm: start x <--- 5 sum <--- 0

10

Malik is creating a program that can compute the difficulty of a given book, based on the difficulty level of the words it uses. This pseudocode describes the program:

10 minutes

Which of the following is the best description of parallel computing?

A computational model in which a program is broken into smaller subproblems, some of which are executed simultaneously.

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.

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

The goal of the procedure computeAverage is to calculate the average of a list of numbers, ignoring any 0 values. For example, if given the list [0, 1, 3, 5], it should return the number 3.

computeAverage([22, 9, 0, 17]) computeAverage([22, 0, 49, 8])

One way to measure the efficiency of an algorithm is to count how many steps it requires for different input sizes and then use a function to describe how the number of steps increases in proportion to the input size. The table below lists various efficiencies, where n represents the input size.

n^2 + 6n = polynomial 6^n = superpolynomial 6n^6 = polynomial 6^2n^2 = superpolynomial n/6 = polynomial

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

sequencing Iteration

Silas develops this algorithm to compute the calories burned for an activity for a given number of minutes and body weight: 1. If the activity is running, compute caloriesPerMin by dividing weight by 10.5 2. if the activity is walking, compute caloriesPerMin by dividing weight by 15.5 3. Compute numCalories by multiplying caloriesPerMin by numMinutes He implements the algorithm in an app, and users soon ask for the ability to compute the total calories for multiple sessions of walking or running. What structure must be added to the original algorithm so that it can compute the total across multiple sessions?

Iteration

The algorithm below determines whether a given year is a leap year. 1. If year is not divisible by 4, set leap_year to false 2. Else if year is not divisible by 100, set leap_year to true 3. Else if year is not divisible by 400, set leap_year to false 4. 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

A ship goes missing in the Pacific Ocean. A programmer develops a program that can analyze satellite imagery for signs of the ship (based on colors and reflections). The programmer tries to run the program on their own computer and realizes their computer is too slow to process all of the satellite imagery of the Pacific Ocean in time for an emergency rescue. They decide to use distributed computing to improve the performance.

A distributed computing solution can process multiple images at once by using multiple computers.

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.

An algorithm will be used to decide whether every number in a list is either a 4 or a 5.There are two proposals for the algorithm:Algorithm 1: Set only45 to false. Iterate through each number in the list. If the number is not equal to 4 and not equal to 5, set only45 to false. Otherwise, set only45 to true.Algorithm 2: Set only45 to true. Iterate through each number in the list. If the number is not equal to 4 and not equal to 5, set only45 to false.Which of these statements are true about these algorithms?I. Algorithm 1 does not work on lists where a number other than 4 and 5 occurs before the last number.II. Algorithm 2 does not work on lists which contain entirely 4s or entirely 5s.

I only

Which of these applications is NOT an example of distributed computing?

Premiere Pro is a video editing program from Adobe that allows users to compose multiple videos and add special effects. Exporting the final video requires a lot of computational power, so Premiere assigns different parts of the exporting task to each of the computer's processors (as long as the computer has multiple processors).

Ryland is creating an article about commonly used compression algorithms for an online educational site. He's debating whether to express each algorithm in natural language, flow charts, pseudocode, or C++, a general-purpose programming language. Which of these is a good argument for expressing the algorithm in pseudocode?

Pseudocode doesn't depend on the syntax and subtleties of a particular programming language, so his readers will be able to understand it as long as they know at least one language.

A software engineer at a mapping company is tasked with coming up with an algorithm to solve a new problem. The engineer is nervous about whether they'll be able to solve it. Which of these outcomes is the least likely?

The engineer may discover that the algorithm is only solvable in a programming language that their company does not use.

A high school provides email addresses to freshman students. The email system typically assigns an email address in the format "[email protected]". However, if a student has the same name as a previous student, the system assigns them a different format. In order to figure out whether an email address is already assigned, the system does a binary search through its list of existing email addresses.

The list of email addresses must be sorted for binary search to work.

An online store manages an inventory of millions of products. On their front page, they show customers products related to the ones they've recently bought. This procedure comes up with a list of similar products for a given list of products: The calcSimilar() procedure takes 2 minutes to return a result, as it needs to do a complicated series of database lookups and mathematic operations. The other operations, creating the empty list and appending items to the list, only take a few nanoseconds.

10

A software engineer at a mapping company is asked to write a geocoding program that can convert 6000,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 fast quickly enough. They decide to use distributed computing to improve the performance

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

The two procedures below are both intended to find a target string in a list of strings. They should return true if they find the string and false if they do not.

Both procedures return the correct value, but procedure #1 requires more operations on average than procedure #2.

A biomedical engineer develops a procedure to help them measure the accuracy of an algorithm that predicts a disease diagnosis. They're specifically interested in the "false positive rate", the number of times the algorithm incorrectly predicted a positive diagnosis. Which change will reduce the most number of operations while still outputting a correct answer?

Moving the calculation of falsePosRate to be after the loop (but before the return)

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

Han develops an algorithm to compute the average amount of time that users watch a particular video on Khan Academy. He then realizes that the average is very low, due to a large number of times with duration "0" or "1", and decides that the algorithm should ignore those durations.

Selection

Farrah develops an algorithm that figures out how to pack variously sized boxes into containers. The algorithm comes up with this packing for 6 boxes into 2 containers 6 64 7 128 8 256 9 512

The algorithm runs in superpolynomial time. The algorithm does not run in reasonable time.

The flow chart below visualizes an algorithm to generate the "hailstone sequence", an interesting series of numbers. n /= 1 false

16 8 4 2 1

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

sequencing Iteration

Ophelia is working on a program that uses machine learning to analyze hospital CT scans for signs of cancer. With her first version of the program, the computer took an average of 24 minutes to analyze 1000 images. To improve the performance, she parallelized the image analysis operation. When running the parallelized program on a hospital computer, the computer took an average of 6 minutes to analyze 1000 images. What is the speedup of the parallel solution?

4

A school IT administrator develops a procedure that compares two lists of grades and returns the percentage of grades in the second list that are higher than the related grade in the first list. They plan to use the procedure to measure student improvement. As input, the procedure takes two lists of numbers:

Moving the calculation of percentGreater to be after the loop (but before the return)

The two algorithms below are both intended to calculate the product of squares from 1 to n, where n is any positive integer. For example, if n is 3, the algorithms should calculate a product of 36, from 1^2 x 2^2 x 3^2

Neither algorithm calculates the correct product.

A mathematician comes up with an algorithm to search a matrix for a value. This table shows how many steps the algorithm requires for different matrix sizes: 2 4 4 16 6 36 8 64

n^2

Which of these best describes which algorithms are more efficient with parallel computing

An algorithm that benefits from parallel computing is one that can be broken down into smaller independent operations

TensorFlow is an open-source machine learning platform with support for distributed computing. This chart shows the speedup gained from using TensorFlow to train a neural network with an increasing number of computers:

Distributed computing can reduce the time it takes to solve large problems.

The two algorithms below are both intended to calculate the sum of cubes from 1 to n, where n is any positive integer. For example, if n is 3, the algorithms should calculate a sum of 36, from 1^3 + 2^3 + 3^3.

Both algorithms calculate the correct sum.

Which of these situations is most analogous to parallel computing?

When multiple people work on a jigsaw puzzle, they can each work on a different part of the puzzle. Once each person has put together a significant area of the puzzle, they can merge the areas and see the completed puzzle.

One way to measure the efficiency of an algorithm is to count how many steps it requires for different input sizes and then use a function to describe how the number of steps increases in proportion to the input size. The table below lists various efficiencies, where nnn represents the input size. Categorize each efficiency as either polynomial or superpolynomial:

n/10 polynomial n! superpolynomial n^10 polynomial 10n^2 polynomial 10^n superpolynomial

A programmer for a weather website needs to display the proportion of days with freezing temperatures in a given month. Their algorithm will operate on a list of temperatures for each day in the month. It must keep track of how many temperatures are below or equal to 32. Once it's done processing the list, it must display the ratio of freezing days over total days. Which of these correctly expresses that algorithm in pseudocode?

numFreezing ← 0 numDays ← 0 FOR EACH temp IN temps { IF (temp ≤ 32) { numFreezing ← numFreezing + 1 } numDays ← numDays + 1 } DISPLAY(numFreezing/numDays)

An algorithm will be used to calculate the difference between the smallest and largest values in a list. For the list of [10, 3, 5, 6], it should calculate a difference of 7. There are two proposals for the algorithm: Algorithm 1: Set minVal to the first value in the list and maxVal to the last value in the list. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal. Algorithm 2: Set minVal to 1000 and maxVal to 0. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal. Which of these statements are true about these algorithms? I. Algorithm 1 does not work on lists where the smallest value is at the start of the list or the largest value is at the end of the list. II. Algorithm 2 does not work on lists that contain all negative numbers or all numbers over 1000.

II only

The following algorithm displays a sequence of 10 odd squares: Start by setting n to 1. Repeat 10 times: Multiply n by itself and display the result Add 2 to n

n ← 1 REPEAT 10 TIMES { result ← n * n DISPLAY(result) n ← n + 2 }

A research project used distributed computing to analyze traffic speeds in major cities. This chart shows the speedup gained when the traffic analysis was run on an increasing number of computers:

Distributed computing can reduce the time it takes to solve large problems.

Khan Academy uses an algorithm to determine whether to show or hide user-created programs to other users. This flow chart shows a simplified version of that algorithm: creatorAge < 13

IF (creatorAge < 13 OR (adminLevel = 0 AND spamScore ≥ 2.0)){ isHidden ← true } ELSE { isHidden ← false }

An algorithm will be used to calculate the difference between the smallest and largest values in a list. For the list of [10, 3, 5, 6], it should calculate a difference of 7.There are two proposals for the algorithm:Algorithm 1: Set minVal to the first value in the list and maxVal to the last value in the list. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal.Algorithm 2: Set minVal to 1000 and maxVal to 0. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal.Which of these statements are true about these algorithms?I. Algorithm 1 does not work on lists where the smallest value is at the start of the list or the largest value is at the end of the list.II. Algorithm 2 does not work on lists that contain all negative numbers or all numbers over 1000.

II only

An algorithm will be used to count how many numbers in a list are multiples of either 5 or 10. For the list of [5, 3, 2, 10, 20, 7], it should count 3 numbers (5, 10, 20). There are two proposals for the algorithm: Algorithm 1: Set value of count to 0. Iterate through each number in the list. If the current number is a multiple of 5 and a multiple of 10, increment count by 1. Algorithm 2: Set value of count to 0. Iterate through each number in the list. If the current number is a multiple of 5, increment count by 1. Then, if the current number is a multiple of 10, increment count by 1. Which of the following best describes the behavior of these algorithms?

Neither algorithms will output the correct count on all inputs, due to issues with under-counting or over-counting multiples.

An algorithm will be used to count how many numbers in a list are multiples of either 5 or 10. For the list of [5, 3, 2, 10, 20, 7], it should count 3 numbers (5, 10, 20).There are two proposals for the algorithm:Algorithm 1: Set value of count to 0. Iterate through each number in the list. If the current number is a multiple of 5 and a multiple of 10, increment count by 1.Algorithm 2: Set value of count to 0. Iterate through each number in the list. If the current number is a multiple of 5, increment count by 1. Then, if the current number is a multiple of 10, increment count by 1.Which of the following best describes the behavior of these algorithms?

Neither algorithms will output the correct count on all inputs, due to issues with under-counting or over-counting multiples.

An online news website relies on in-page advertisements to make money. Their article pages have multiple slots for advertisements, and each slot can be used for a full-size ad or multiple smaller ads. Advertisers specify their size and desired display count per day.

Use a heuristic-based algorithm that suggests an advertisement schedule that is close to optimal.

Hearify is an online music streaming service. They want to introduce a new feature that automatically generates 60-minute long playlists of popular music in different genres. They want each playlist to be exactly 60 minutes long and to include the most highly rated songs possible. They develop the feature but discover that it takes a long time for the computer to consider all the possible combinations of songs, and that extra time costs them money. Can the run time of the feature be improved?

Yes, they can speed up the run time by using a heuristic to output a playlist that is not optimal, but close enough.


संबंधित स्टडी सेट्स

AH Exam 1: Chapter 22, Ch 22: Management of Patients with Upper Respiratory Tract Disorders, Chapter 22: Management of Patients With Upper Respiratory Tract Disorders

View Set

Money, Banking & Financial Markets

View Set

Missed and guessed Q's from Law of Contracts

View Set

Confirmed in the Spirit Chapter 7

View Set

很重要SAUNDERS LEADERSHIP ( 2 )

View Set