Expressing an algorithm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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.

The flow chart below visualizes an algorithm to generate the Fibonacci numbers, a famous mathematical sequence. Flow chart for Fibonacci algorithm. It starts with 3 nodes flowing from one to the next: "Start" "x ← 0" "y ← 1" Then it flows to a diamond node with condition "x < max". An arrow labeled true flows to a sequence of 4 nodes: "z ← x + y" "DISPLAY (z)" "x ← y" "y ← z" An arrow loops from that node back to the diamond node. From the diamond node, an arrow labeled false flows to a node labeled "End". [How do you read a flowchart?] If the variable max is set to 5, what would be displayed as a result of executing this algorithm?

1 2 3 5 8

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. Which of these correctly expresses that algorithm in pseudocode?

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

The flow chart below visualizes the steps of an algorithm: Flow chart for a simple algorithm. It starts with 3 nodes flowing from one to the next: "Start" "x ← 5" "sum ← 0" Then it flows to a diamond node with condition "x > 0". An arrow labeled true flows to a sequence of 2 nodes: "x ← x - 1" "sum ← sum + x" An arrow loops from that node back to the diamond node. From the diamond node, an arrow labeled false flows to a sequence of 2 nodes: "DISPLAY (sum)" "End" [How do you read a flowchart?] What would be displayed as a result of executing this algorithm? Choose 1 answer:

10

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 ← 0 level ← 1 REPEAT UNTIL (level > height) { result ← level * level total ← total + result level ← level + 1 } DISPLAY(total)

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? Choose 1 answer:

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.

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: Flow chart for program visibility algorithm. The "start" node flows to a diamond node with condition "creatorAge < 13". From there, an arrow labeled true flows to a node with "isHidden ← true" and an arrow labeled false flows to a diamond node with "adminLevel = 0". From that diamond node, an arrow labeled true flows to a diamond node with "spamScore ≥ 2.0" and an arrow labeled false flows to a node with "isHidden ← false". From the "spamScore ≥ 2.0" node, an arrow labeled true flows to "isHidden ← true" and an arrow labeled false flows to "isHidden ← false". [How do you read a flowchart?] Which pseudocode is equivalent to the algorithm in the flowchart?

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

An online shopping site uses the following algorithm to decide what related products to show on each product page. Flow chart for related products algorithm. The "start" node flows to a diamond node with condition "itemSimilarity > 0.9". From there, an arrow labeled true flows to a node with "showRelated ← true" and an arrow labeled false flows to a diamond node with condition "userSimilarity > 0.8". From that diamond node, an arrow labeled true flows to "showRelated ← true" and an arrow labeled false flows to a diamond node with condition "updatedModel = true". From that diamond node, an arrow labeled true flows to "showRelated ← true" and an arrow labeled false flows to "showRelated ← false". Flow chart for related products algorithm. The "start" node flows to a diamond node with condition "itemSimilarity > 0.9". From there, an arrow labeled true flows to a node with "showRelated ← true" and an arrow labeled false flows to a diamond node with condition "userSimilarity > 0.8". From that diamond node, an arrow labeled true flows to "showRelated ← true" and an arrow labeled false flows to a diamond node with condition "updatedModel = true". From that diamond node, an arrow labeled true flows to "showRelated ← true" and an arrow labeled false flows to "showRelated ← false". [How do you read a flowchart?] Which pseudocode is equivalent to the algorithm in the flowchart?

IF (itemSimilarity > 0.9 OR userSimilarity > 0.8 OR updatedModel = true) { showRelated ← true } ELSE { showRelated ← false }


Kaugnay na mga set ng pag-aaral

RDT 105 Positioning Situations Chest

View Set

Basic Economic Concept Unit 1 (AP Economics)

View Set

Additive and Destructive Pathologies

View Set

Smartbook: Chapter 6 Cash, Fraud, and Internal Control

View Set

Chapter 30 PrepU: Management of Patients with Hematologic Neoplasms

View Set

Unanticipated Problems and Reporting Requirements in Social and Behavioral Research

View Set