Practice Exam1 - Computer Science

advertisement
1st Midterm Exam
Important Concepts
The test will cover all material from chapters 1, 2, and 3. In addition all material covered during lecture and lab
may be tested. Here is a listing of some of the most important concepts:



Chapter 1
o Definition of Computer Science
o Definition of Algorthim
o History of Computing
Chapter 2
o Pseudocode
o Sequential, Conditional, and Iterative Operations
o Find largest algorithm
o Premitives
Chapter 3
o Efficiency of Algorithms
o Order of Magnitude – Order n, n2, log n, 2n
o Binary Search and Sequential search algorithms
o Sorting algorithms (selection, insertion, bubble, quick, merge)
o Data Cleanup algorithms
o Common Exponential Problems (Hamiltonian Circuit Problem, Satisfiability
Problem, Bin-Packing Problem)
Sample Questions
(this is not meant to be a comprehensive list of all questions that may be asked on the exam. This is just a sampling
if questions that may be asked during the exam.)
True/False
Indicate whether the statement is true or false.
____
1. Whether or not an operation is a primitive depends, in part, on the computing agent that is expected to execute
it.
____
2. Computer science work was carried out even before the electronic computer was invented.
____
3. The five generations of modern computers are distinguished mainly by fundamental changes in the underlying
computer architecture.
____
4. John Von Neumann created the modern computer architecture when he developed a computer that stored its
program in its own memory.
____
5. The first accurate definition of computer science described it as a study of algorithms.
____
6. The three types of operations used to construct algorithms are sequential, conditional, and iterative.
____
7. The statement: “If the mixture is too dry, then add one-half cup of water to the bowl” is an example of a
conditional operation.
____
8. Euclid's algorithm finds prime numbers between any two given numbers.
____
9. If you can specify an algorithm to solve a problem you can automate its solution.
____ 10. Algorithms usually contain a set of instructions to be executed in any order.
____ 11. The first electronic programmable computer, ENIAC, was built during World War I.
____ 12. A sequential algorithm executes its instructions in a straight line from top to bottom and then stops.
____ 13. In a posttest loop, it is possible for the loop body to never be executed.
____ 14. Finding the maximum number in a given set is an example of a problem that computer scientists want to
solve.
____ 15. Java and C++ are examples of pseudocode languages.
____ 16. Languages such as Java and C++ are the algorithmic design languages of choice.
____ 17. The fact that natural language can have many different meanings in different contexts makes it difficult to use
for designing algorithms.
____ 18. The three basic sequential operations are called addition, multiplication, and exponentiation.
____ 19. Input and output allow the computing agent to communicate with the outside world.
____ 20. One of the most powerful features of a computer is its ability to handle loops.
____ 21. Iteration should be minimized when designing algorithms.
____ 22. In the sequential search algorithm, the worst case occurs when the value being searched for is the first value
in the list.
____ 23. With sequential search, the bigger the list of items, the more work that must be done to search it.
____ 24. Elegance is the first and foremost expectation of a proper algorithm.
____ 25. A collection of sets and vectors is called a graph.
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 26. The operation “Replace i with i - 1” is a(n) ____ operation.
a. Sequential
c. iterative
b. Conditional
d. hierarchal
____ 27. The ____ was the first computing device to use the base-2 binary numbering system.
a. Mark I
c. Analytic Engine
b. Difference Engine
d. ENIAC
____ 28. FORTRAN and COBOL, the first high-level (“natural”) programming languages, appeared during the ____
generation of computing.
a. First
c. third
b. Second
d. fourth
____ 29. What is a computing agent?
a. something that carries out steps of the algorithm
b. a person who works with users and developers for improving software
c. a person that writes computer code
d. the hardware that powers the computer
____ 30. What is wrong with the following algorithm?
1.
2.
3.
4.
____ 31.
____ 32.
____ 33.
____ 34.
____ 35.
____ 36.
____ 37.
____ 38.
____ 39.
____ 40.
Set X to be 1
Increment X
Print X
If X > 0, repeat from 2
a. it does not produce a result
b. it is ambiguous
c. it does not halt in a finite amount of time
d. it is not well-ordered
Integrated circuits, built on silicon chips, were introduced during the ____ generation of computing.
a. First
c. third
b. Second
d. fourth
Automation of mental tasks was part of a movement known as the ____ revolution.
a. Industrial
c. computer
b. Technological
d. designer
Most computer scientists use ____ to design and represent algorithms.
a. natural languages
c. low-level programming languages
b. high-level programming languages
d. pseudocode
A purely ____ algorithm is also called a straight-line algorithm.
a. Sequential
c. iterative
b. Conditional
d. control
Together, conditional and iterative operations are called ____ operations.
a. Sequential
c. hierarchical
b. Control
d. dynamic
The technique of looking at all the items in a list, starting at the beginning of the list, one at a time, until we
either find what we are looking for or come to the end of the list is called ____ search.
a. Sequential
c. iterative
b. Control
d. random
____ is the process of searching for a special pattern of symbols within a larger collection of information.
a. Sequential search
c. Pattern matching
b. Dynamic processing
d. Pattern search
Viewing an operation at a high level of abstraction and fleshing out the details of its implementation at a later
time is known as ____ design.
a. bottom-up
c. increasing size
b. top-down
d. increasing depth
____ is an example of a natural language.
a. C
c. English
b. Java
d. Perl
Consider this line of code: Set the value of Area to length*width
“Area” is a____.
a. Value
c.
b. Variable
d.
____ 41. If, then, and else are examples of ____ statements.
a. primitive
c.
b. iterative
d.
____ 42. A(n) ____ is a collection of useful algorithms.
a. primitive
c.
b. binary
d.
constant
primitive
sequential
conditional
set
library
____ 43. In order to implement a “find” functionality in a word processor, one would have to design a ____ algorithm.
a. pattern matching
c. sequential
b. natural language
d. do-while
____ 44. Which statement exemplifies abstraction?
a. The president of General Motors views the company in terms of every worker, every
supplier, and every car.
b. The president of General Motors views the company in terms of its corporate divisions
and high-level policy issues.
c. A good approach to algorithm design and software development, is to focus on how we
might actually implement a particular operation.
d. A convenient way to view the hardware component called “memory” is to focus on the
billions of electronic devices that go into constructing a memory unit.
____ 45. An ____ algorithm is called an exponential algorithm.
a. (lg n)
c. (n2)
b. (n)
d. (2n)
____ 46. ____ is the term to describe an algorithm’s careful use of resources.
a. Resourcefulness
c. Effectiveness
b. Time-Space Tradeoff
d. Efficiency
____ 47. ____ is the fixing of errors uncovered through repeated use of an algorithm.
a. Program maintenance
c. Data cleanup
b. Recycling
d. Garbage collection
____ 48. The ____ sort algorithm performs the task of sorting a list by growing a sorted subsection of the list from the
back to the front.
a. selection
c. shuffle-left
b. sequential
d. binary
____ 49. A ____ is a path through a graph that begins and ends on the same node and goes through every node exactly
once.
a. Newtonian loop
c. Hamiltonian circuit
b. McCarthian path
d. complete trip
____ 50. The process of timing an algorithm using the same machine but searching for different items is called ____.
a. time trials
c. comparison timing
b. Benchmarking
d. intensive testing
51. Show what is printed by each of the following partial algorithms:
a. Assign Count a value of 1
If Count < 0 then
Print 'Yes'
else Print 'No'
b. Set GPA to a value of 1.0
If GPA < 2.0 then
Print 'Uh-oh'
Print the value of GPA
c. Assign GPA a value of 2.3
If GPA < 2.0 then
Print 'Uh-oh'
ANSWER:
ANSWER:
ANSWER:
Print the value of GPA
d. Set the value of Count to 3
ANSWER:
While Count < 6 do
Print the value of Count
Set Count to the value of Count + 1
Print 'END'
52. Write pseudocode for the following operations:
a. Compute and display the value x divided by y if y is not zero. Otherwise, display "Sorry".
b. Set n to the value of 1. While n ≤ 10, print n and increment n by 1.
53. Trace the following algorithm showing the values of sum, n and the step number being executed displayed
as:
Step
sum
n
If the value isn't assigned yet, write G for its value. Assume your computing agent can add numbers
two at a time and can square numbers.
Step 1: Set sum equal to 0.
Step 2: Set n equal to 1.
Step 3: Repeat steps 4 and 5 until n > 4.
Step 4:
Set sum equal to sum + n2.
Step 5:
Replace n with n + 1.
Step 6: Print sum.
Step 7. Stop.
54. For the following list, perform a bubble sort, and show the list after each exchange.
4, 8, 2, 6
55. Suppose selection sort and bubble sort are both performed on a list that is already sorted. Does bubble sort do fewer
exchanges than selection sort?
56. Find an assignment for the variables to make the following logic statement true (satisfiability problem):
(A or B or C) and (¬A or ¬B) and (¬B or ¬C) and (¬A or ¬C)
1st Midterm Exam
Answer Section
TRUE/FALSE
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
T
T
F
T
T
T
T
F
T
F
F
T
F
T
F
F
T
F
T
T
F
F
T
F
F
MULTIPLE CHOICE
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
A
A
B
A
C
C
C
D
A
B
A
C
B
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
ANS: C
ANS: B
ANS: D
ANS: D
ANS: A
ANS: B
ANS: D
ANS: D
ANS: A
ANS: A
ANS: C
ANS: B
ANS: a. NO b. Uh-oh c. 2.3 d. 3 4 5
a. if y is not 0 then
set z to be x/y
else
print “sorry”
b. set n to 1
while n <= 10
print n
set n to be n+1
step sum n
1
0 G
2
0 1
4
1 1
5
1 2
4
5 2
5
5 3
4
14 3
5
14 4
4
30 4
5
30 5
6
30 5
7
30 5
4, 8, 2, 6
4, 2, 8, 6
2, 4, 8, 6
2, 4, 6, 8
Both do zero exchanges
A=false, B=false, C=true
Download