Ask Question

Cutting a stick A stick n inches long needs to be cut into n 1-inch pieces. Outline an algorithm that performs this task with the minimum number of cuts if several pieces of the stick can be cut at the same time. Also give a formula for the minimum number of cuts.

+3
Answers (1)
  1. 3 May, 10:30
    0
    The algorithm and its formula are given below

    Explanation:

    Algorithm:

    Start

    Input Length of stick in inches

    while (1) do / / Loop runs until break statement execute

    if (inchesOfStick = = 1) do / / If there is 1 inch stick

    break / / exit from loop

    end if

    if (inchesOfStick % 2 = = 0) do / / if the inches remaining is even

    inchesOfStick / = 2 / / Forula to cut

    end if

    else if (inchesOfStick % 2 = = 1) do / / if the inches remaining is odd

    inchesOfStick = (inchesOfStick + 1) / 2 / / Formula to cut

    increment minimumCuts

    end else

    end while

    print minimum number of cuts

    end program
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Cutting a stick A stick n inches long needs to be cut into n 1-inch pieces. Outline an algorithm that performs this task with the minimum ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers