Preview

Exam on Algorithms

Powerful Essays
Open Document
Open Document
1238 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Exam on Algorithms
thAlgorithms

Chapter assessment

1. Use the following pseudo code with your own choice of values of X.

10 INPUT X 20 LET Y = X/3 30 LET R = Y – INT(Y) 40 IF R = 0 PRINT ACCEPT, GOTO A 50 PRINT REJECT 60 LABEL A 70 END

(i) Explain what is being achieved. [4]

(ii) If you replaced the line LET Y = X/3 by the line LET Y = X/5, how would this change the outcome of the above? [1]

2. The following algorithm is to be applied to the positive integers from 1 to 12.

Step 1: Cross out every even number. Step 2: Change the state of every multiple of 3 (including 3) – i.e. for every multiple of 3, if it is crossed out then remove the crossing out, and if it is not crossed out then cross it out. Step 3: Change the state of every multiple of 4 (including 4). Step 4: Change the state of every multiple of 5 (including 5). … … Step 11: Change the state of every multiple of 12 (including 12).

(iii) Numbers | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 2 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 3 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 4 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 5 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 6 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 7 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 9 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 10 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Step 11 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

Apply the algorithm, using a row of the table below for each step. In each step the crossings-out should be the same as in the previous step except for those numbers whose state is changed. [4]

(iv) Say what the algorithm

You May Also Find These Documents Helpful

  • Powerful Essays

    COM 100 Exam 1

    • 1961 Words
    • 9 Pages

    You will have 60 minutes to complete the exam from the time it is distributed. You will have ample time to read each test item carefully and respond to each test item thoughtfully. Test items are not intended to be tricky, but rather to assess the depth of your understanding.…

    • 1961 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    Exam4 Spring2011

    • 3006 Words
    • 14 Pages

    Schalheim Sisters Inc. has always paid out all of its earnings as dividends, hence the firm has no retained earnings. This same situation is expected to persist in the future. The company uses the CAPM to calculate its cost of equity, its target capital structure consists of common stock, preferred stock, and debt. Which of the following events would REDUCE its WACC?…

    • 3006 Words
    • 14 Pages
    Good Essays
  • Good Essays

    Chasing lincoln's killer

    • 430 Words
    • 2 Pages

    I wold profer this becase this is a lot esair to do than antothere way . hwunlgjan jlrgajjrabgbsm,agsdbgbsgkjabjgbbjbjgkbjbjbjgbjgbjgbj kbjbjbjb j b bjbgjbkjsbkabgjsajbajkgbjfbjkbakbgbbbbbbbbbbbbbbbbbbbbbbbbbb-…

    • 430 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Greatest Common Factor

    • 1530 Words
    • 7 Pages

    Write the prime factorization. Circle the common prime factors. 12 = 2 × 2 × 3 24 = 2 × 2 × 2 × 3 60 = 2 × 2 × 3 × 5 The…

    • 1530 Words
    • 7 Pages
    Good Essays
  • Good Essays

    Note Conversion

    • 1708 Words
    • 7 Pages

    Step 8. Now time to calculate the answer. We multiply any numbers in the top and divide by the ones in the bottom.…

    • 1708 Words
    • 7 Pages
    Good Essays
  • Good Essays

    Exam 1

    • 1499 Words
    • 6 Pages

    Many researchers have criticized Maslow's Need Hierarchy Theory because there is no clear evidence that:…

    • 1499 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    1,543 552 0 0 0 2,095 1,309 5 0 0 12 1,326 2,978 221 2,237 0 435 5,871 66 0 0 0 0 66 5,897 779 2,237…

    • 796 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    exam 1

    • 1209 Words
    • 4 Pages

    Be aware of research ethics. What is informed consent? What does the American Anthropological Association recommend regarding ethics (read about this in Kottak)?…

    • 1209 Words
    • 4 Pages
    Powerful Essays
  • Good Essays

    Past Microprocessor Question

    • 4111 Words
    • 17 Pages

    124*1 = 124, 124*2 = 248, 124*3 = 372 and that 124, 248 and 372 each contain the digit 2. It is possible to generalize this property to be the smallest number whose first n multiples each contain the digit 2. Write a function named smallest(n) that returns the smallest number whose first n multiples contain the digit 2. Hint: use modulo base 10 arithmetic to examine digits.…

    • 4111 Words
    • 17 Pages
    Good Essays
  • Powerful Essays

    PageRank Algorithm

    • 4244 Words
    • 17 Pages

    and explain each procedure. We also explain the mathematical setup of the algorithm, including all…

    • 4244 Words
    • 17 Pages
    Powerful Essays
  • Powerful Essays

    Java Exam

    • 5195 Words
    • 21 Pages

    Java is a general-purpose, concurrent, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. Java is, as of 2012, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.…

    • 5195 Words
    • 21 Pages
    Powerful Essays
  • Powerful Essays

    Btech Grades

    • 883 Words
    • 4 Pages

    BB AA AA AB AB BB AB BC CD AA AA AB CD AA AB AB BB AB CC BB AB…

    • 883 Words
    • 4 Pages
    Powerful Essays
  • Powerful Essays

    A [i +1] and whenever a pair of adjacent numbers is found to be out of order, then the positions of the numbers are exchanged. The algorithm repeats the process for numbers at positions A [i+1] and A [i + 2]…

    • 4183 Words
    • 17 Pages
    Powerful Essays
  • Satisfactory Essays

    get -3 , -4 , or -5 in box-2 in 3 steps.Use all operations i.e. ( +,-,*,/ ).…

    • 531 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Life Insurance

    • 5327 Words
    • 22 Pages

    I S S N : 2 3 3 0 - 9 5 1 9 (O n l i n e ) | I S S N : 2 2 3 1-2463 ( P r in t)…

    • 5327 Words
    • 22 Pages
    Powerful Essays