Unit 9: Algorithms

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

Which of the following algorithms is the same as the flowchart shown below? a) myNum ← RANDOM(1, 10) IF (myNum > 8) { DISPLAY("Done") } ELSE { DISPLAY(myNum) } b) myNum ← RANDOM(1, 10) REPEAT UNTIL (myNum > 8) { DISPLAY(myNum) myNum ← RANDOM(1, 10) } DISPLAY ("Done") c) myNum ← RANDOM(1, 10) IF (myNum < 8) { DISPLAY("Done") } ELSE { DISPLAY(myNum) } d) myNum ← RANDOM(1, 10) REPEAT UNTIL (myNum > 8) { DISPLAY("Done") } DISPLAY(myNum)

b) myNum ← RANDOM(1, 10) REPEAT UNTIL (myNum > 8) { DISPLAY(myNum) myNum ← RANDOM(1, 10) } DISPLAY ("Done")

A sequential algorithm is broken into three stages: Sequential Algorithm Time Download stage: 1 minute Sorting stage: 6 minutes Upload stage: 1 minute A parallel version of the algorithm completes the sorting stage in parallel leading to a new set of times: Parallel Algorithm Time Download stage: 1 minute Sorting stage: 2 minutes Upload stage: 1 minute What is the speedup of the parallel solution? Show your calculations.

*** DON'T COPY WORD PER WORD PLEASE *** 1 + 6 + 1. = 8. One plus six plus one equals eight 1 + 2 +1 = 4. Then you solve one plus two plus one equals four 8/2 = 4 After that you take the two numbers and divide them both which in this e case is eight divide by two which equals 4 The speedup of the parallel solution is 2.

Two students are writing algorithms to determine if a number is in a list. Jamal writes the algorithm using a linear search and Hannah writes the algorithm using a binary search. A. They run their programs to find out if the number 99 is in this list of numbers: 5, 17, 22, 46, 68, 81, 90, 95, 99, 108 Which algorithm is the most efficient in finding the solution? Explain your reasoning. B. They run their programs again to find out if the number 5 is in the same list of numbers: 5, 17, 22, 46, 68, 81, 90, 95, 99, 108 Which algorithm is the most efficient in finding the solution? Explain your reasoning. C. In general, which of the programs is the most efficient? Explain your reasoning.

*** DON'T COPY WORD PER WORD PLEASE *** A. A binary algorithm is much quicker than a linear because it will cut the data in half compared to a linear search starting at point 1. B. A linear algorithm would be quicker because the number 5 is at the start of the data. c. If the data size was much larger a binary algorithm would be faster because it splits the data in half and makes it easier to go through the data.

The Traveling Salesman Problem is typically solved using a heuristic rather than an algorithm. Briefly explain a real-world problem that may be solved using a heuristic.

*** DON'T COPY WORD PER WORD PLEASE *** An example of a heuristic is a navigation system offering several route options that may account for shortest, fastest or eco friendly route. One real world problem that may be solved using a heuristic is seeing a person who is wearing an all black outfit with hoodie on walking side to side while you are walking alone. So you will try to walk pass by them quickly or go a different direction/way.

This graph shows the efficiencies of two different algorithms that solve the same problem. In your own words, explain what the graph shows about the efficiencies of these algorithms.

*** DON'T COPY WORD PER WORD PLEASE *** From the above graph it shows that Algorithm A is linear and Algorithm B is exponential.Algorithm B is more efficient than Algorithm A because it requires less iterations until you reach more than 1,000,000 inputs. At that point Algorithm A is more efficient.

In your own words, explain parallel computing. Name at least one advantage and one disadvantage of this type of computing.

*** DON'T COPY WORD PER WORD PLEASE *** In a parallel computing model, programs are divided into smaller chunks, some of which are operate simultaneously. The ability to solve extremely complex problems that would typically be impossible to solve on a single computer is one benefit of parallel computing. However, there comes a point where having one additional parallel computer when not always lead to additional optimization.

A team of programmers is trying to determine the efficiency of a piece of code. They run the code with inputs of different sizes and also record the number of iterations through the core block of code. The data is recorded in the table below. Based on the data provided, does this algorithm run in a reasonable or unreasonable time? Explain your answer.

*** DON'T COPY WORD PER WORD PLEASE *** This runs in an unreasonable time because as the input size increases the iterations at a minimum double which follows more of an exponential function.

In your own words, explain what is meant by an "undecidable" problem.

*** DON'T COPY WORD PER WORD PLEASE *** Undecidable problems are those for which no algorithm can be developed that can reliably return a yes-or-no response. For every input, there is a proper yes/no response, but there is no algorithm that will always provide the right response.

Match the term on the left with its definition on the right: __5__ the repetition of part of an algorithm until a condition is met or for a specified number of times __1__ a general description of a task that can (or cannot) be solved with an algorithm __3__ the application of each step of an algorithm in the order in which the code statements are given __4__ determines which parts of an algorithm are executed based on a condition being true or false __2__ a finite set of instructions that accomplish a task

1. Problem 2. Algorithm 3. Sequencing 4. Selection 5. Iteration

Match the term on the left with its definition on the right: __2__ a model in which programs are broken into small pieces, some of which are run simultaneously __1__ a model in which programs run in order, one command at a time __3__ a model in which programs are run by multiple devices

1. Sequential computing 2. Parallel computing 3. Distributed computing

The following algorithm is followed by a person every morning when they get up from bed to go to school: Wake up Brush teeth Put on shirt Put on pants Put on socks Put on shoes Tie shoes Which concept does this algorithm BEST demonstrate? a) Sequencing b) Selection c) Iteration d) Execution

a) Sequencing

A computer is performing a binary search on the sorted list of seven numbers below. What is the MAXIMUM number of iterations needed to find the item? 1, 5, 20, 50, 51, 80, 99 Question options: a) 1 b) 3 c) 6 d) 7

b) 3

A town government is designing a new bus system. The planners are deciding where to put the different bus stops. They want to pick a set of bus stop locations that will minimize the distance anyone needs to walk in order to get to any bus stop in town. What term best defines this kind of problem? Question options: a) A decision problem b) An optimization problem c) An undecidable problem d) An efficiency problem

b) An optimization problem

A school is creating class schedules for its students. The students submit their requested courses and then a program will be designed to find the optimal schedule for all students. The school has determined that finding the absolute best schedule for every student cannot be solved in a reasonable time. Instead they have decided to use a simpler algorithm that produces a good but non-optimal schedule in a more reasonable amount of time. Which principle does this decision best demonstrate? Question options: a) Unreasonable algorithms may sometimes also be undecidable. b) Heuristics can be used to solve some problems for which no reasonable algorithm exists. c) Two algorithms that solve the same problem must also have the same efficiency. d) Approximate solutions are often identical to optimal solutions.

b) Heuristics can be used to solve some problems for which no reasonable algorithm exists.

Which of the following is true of algorithms? a) Algorithms may have an infinite set of instructions. b) Algorithms must be expressed using a programming language. c) Every algorithm can be constructed using combinations of sequencing, selection, and iteration. d) Every problem can be solved with an algorithm.

c) Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

A software company used to run an algorithm sequentially on one server. As more users started using their app, the company decided to rewrite the program to be parallel. It is now run on six separate servers instead of one. Thanks to the use of a parallel algorithm, the same process that used to take 40 minutes to run now only requires 15 minutes. The company is considering purchasing additional computers to decrease the time the program runs even further. Which of the following best describes the impacts of running the parallel algorithm on an even larger number of computers? Question options: a) The algorithm will likely require more time since it is now being run sequentially on more computers. b) The algorithm will likely require the same amount of time to run because it is processing the same amount of data. c) The algorithm will likely require less time to run though the improvements in efficiency will not be as significant as before. d) The algorithm is unlikely to still run since parallel algorithms are not designed to scale to additional computers.

c) The algorithm will likely require less time to run though the improvements in efficiency will not be as significant as before.

Which of the following algorithmic efficiencies would be considered LEAST efficient? Question options: a) Linear b) Constant c) Polynomial d) Exponential

d) Exponential

A group of students each writes their name and unique student ID number on a sheet of paper. The sheets are then randomly placed in a stack. Their teacher is looking to see if a specific ID number is included in the stack. Which of the following BEST describes whether their teacher should use a linear or a binary search? Question options: a) The teacher could use either type of search though the linear search is likely to be faster. b) The teacher could use either type of search though the binary search is likely to be faster. c) Neither type of search will work since the data is numeric. d) Only the linear search will work since the data has not been sorted.

d) Only the linear search will work since the data has not been sorted.

Which of these algorithms will move the robot along the same path as the algorithm below? REPEAT 2 TIMES { REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() } a) REPEAT 6 TIMES {MOVE_FORWARD() ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() } b) REPEAT 2 TIMES{ MOVE_FORWARD() MOVE_FORWARD() MOVE_FORWARD() MOVE_FORWARD() ROTATE_LEFT() ROTATE_RIGHT() } c) REPEAT 4 TIMES { MOVE_FORWARD() MOVE_FORWARD() MOVE_FORWARD() ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() } d) REPEAT 2 TIMES { MOVE_FORWARD() MOVE_FORWARD() MOVE_FORWARD() ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() }

d) REPEAT 2 TIMES { MOVE_FORWARD() MOVE_FORWARD() MOVE_FORWARD() ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() }


Set pelajaran terkait

Routing and Switching Essentials (V6.0) - RSE 6.0 Chapter 8 Exam

View Set

Chapter 16: Infectious Diseases Affecting the Skin

View Set

Logical Fallacies -- Definitions

View Set