Top Banner
Outline 1 midterm exam on Friday 11 July 2014 policies for the first part 2 questions with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 1 / 39
39

review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

Apr 12, 2018

Download

Documents

phamnhan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

Outline

1 midterm exam on Friday 11 July 2014policies for the first part

2 questionswith some potential answers...

MCS 260 Lecture 10.0Introduction to Computer Science

Jan Verschelde, 9 July 2014

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 1 / 39

Page 2: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

review of the first 9 lectures

1 midterm exam on Friday 11 July 2014policies for the first part

2 questionswith some potential answers...

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 2 / 39

Page 3: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

policies

The first part of the exam will be closed book, no notes,and no computer.

The material breaks down in two parts:1 computer science concepts: algorithms, computer architecture,

functionality of operating systems, mass storage, formallanguages, flowcharts and pseudocode, logic gates, transistorsand flip flops, adder circuits, functional programming.

2 mathematical CS: binary and hexadecimal representations ofnumbers, precision and accuracy, boolean algebra, truth tables,simulation and Monte Carlo, histograms.

This review contains some preliminary examples of questions whichmay help you prepare for the first part of the midterm exam.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 3 / 39

Page 4: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

review of the first 9 lectures

1 midterm exam on Friday 11 July 2014policies for the first part

2 questionswith some potential answers...

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 4 / 39

Page 5: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 1

List the characteristics of an algorithm.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 5 / 39

Page 6: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 1

The question: List the characteristics of an algorithm.

A potential answer: There are four characteristics:1 ordered: steps in the execution come after each other;2 unambiguous: the steps must be executable and clear;3 correctness: must meet its specification, its intended goals;4 terminating: must stop after a finite number of steps.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 6 / 39

Page 7: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 2

How many bytes are 15 terabytes?

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 7 / 39

Page 8: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 2

The question: How many bytes are 15 terabytes?

A potential answer: tera = 240.

So 15 terabytes are 15 × 240 bytes,or approximately 15 trillion bytes.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 8 / 39

Page 9: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 3

Explain the difference between 34/87 and 34.0/87.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 9 / 39

Page 10: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 3

The question: Explain the difference between 34/87 and 34.0/87.

A potential answer:

34/87 represents the division of the integer 34 by the integer 87.

The result of this integer division is zero.

34.0/87 represents the division of the float 34.0 by the integer 87.

The result of this float division is a floating-point numberwhich represents the rational number 34/87up to machine precision.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 10 / 39

Page 11: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 4

What is an interrupt?

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 11 / 39

Page 12: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 4

The question: What is an interrupt?

A potential answer:

An interrupt causes an executing process to goin waiting (e.g.: wait for input from a device)or ready state (e.g.: because the CPU is busy on another process).

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 12 / 39

Page 13: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 5

Describe the differences between a compiler and an interpreter.

What are the advantages/disadvantages of using a compiler and aninterpreter?

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 13 / 39

Page 14: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 5, part one

The first part of the question:Describe the differences between a compiler and an interpreter.

A potential answer:

A compiler translates an entire program into executable format.The program is not executed.

An interpreter translates statements in a program one afterthe other andexecutes each statement as soon as its translation is done.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 14 / 39

Page 15: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 5, part two

The second part of the question:What are the advantages/disadvantages of using a compiler and aninterpreter?

A potential (very short) answer:

Compiled code executes faster than interpreted code.

Code can be developed faster with an interpreterthan with a compiler.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 15 / 39

Page 16: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 6

Convert 318 into hexadecimal notation.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 16 / 39

Page 17: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 6

The question: Convert 318 into hexadecimal notation.A potential answer:

n n/16 n mod 16318 19 14 318 = 19 × 16 + 1419 1 3 19 = 1 × 16 + 31 0 1 1 = 0 × 16 + 1

Collecting the remainders gives 1, 3, 14 (or E).

So the decimal 318 equals 13E in hexadecimal.

An alternative method is to convert to binaryand group the bits in sequences of four.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 17 / 39

Page 18: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 7

Rank all memory elements we have seen twice:1 use once its speed (memory that is fastest to access comes first);

and2 use once its capacity (memory that is largest in size comes first).

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 18 / 39

Page 19: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 7

The question: Rank all memory elements we have seen twice:1 use once its speed (memory that is fastest to access comes first);

and2 use once its capacity (memory that is largest in size comes first).

A potential answer:1 registers, cache, internal memory, disk, tape;2 tape, disk, internal memory, cache, registers.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 19 / 39

Page 20: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 8

What is the kernel of an operating system?

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 20 / 39

Page 21: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 8

The question: What is the kernel of an operating system?

A potential answer:

The kernel of an operating system1 controls the execution of programs;2 allocates and frees internal memory;3 manages the peripherals (i/o devices).

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 21 / 39

Page 22: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 9

Consider the circuit shown below. For b1 = 1 and b2 = 0 as input,indicate on the picture below the input and output for every logical gate.

��HH c

��HH c

C

Ss

s

s

s

b2

b1

s

s

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 22 / 39

Page 23: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 9

Consider the circuit shown below. For b1 = 1 and b2 = 0 as input,indicate on the picture below the input and output for every logical gate.

The answer:

��HH c

��HH c

C

Ss

s

s

s

b2

b1

s

s

1 00 0

1

0 11 1

10 0

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 23 / 39

Page 24: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 10

Draw the flowchart for the algorithm to search for the maximum in a listof unsorted numbers.

Write pseudo code for this algorithm as well.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 24 / 39

Page 25: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 10: the flowchart

The question: Draw the flowchart for the algorithm to search for themaximum in a list of unsorted numbers.A potential answer:

n = len(L); m = L[0]; i = 1

?

���HHHHHH���i < n?

?True

-Falseprint m

?

���HHHHHH���L[i] > m?

?True

False

m = L[i]

?i = i + 1

?

-

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 25 / 39

Page 26: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 10: the pseudocode

The question: Draw the flowchart for the algorithm to search for themaximum in a list of unsorted numbers. Write pseudo code for thisalgorithm as well.

A potential answer:

Input: L, a list of unsorted numbers.Output: m, the maximum of the elements in L.

let m be L[0]for i from 1 to the length of L do

if L[i] > m thenlet m be L[i]

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 26 / 39

Page 27: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 11

An exclusive or, denoted as XOR returns False only when the inputsare both the same, and True otherwise.

1 Give the truth table for the exclusive or.2 Show how the XOR can be realized with NOT, OR, and AND by

giving the logical expressions and their corresponding truth tables.3 Draw the circuit for the XOR, using the symbols for the gates NOT,

OR, and AND.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 27 / 39

Page 28: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 11, item 1

The question: An exclusive or, denoted as XOR returns False onlywhen the inputs are both the same, and True otherwise.

1 Give the truth table for the exclusive or.

The answer:

x y x XOR y0 0 00 1 11 0 11 1 0

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 28 / 39

Page 29: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 11, item 2

The question: An exclusive or, denoted as XOR returns False onlywhen the inputs are both the same, and True otherwise.

2 Show how the XOR can be realized with NOT, OR, and AND bygiving the logical expressions and their corresponding truth tables.

The answer:

x y x OR y x AND y NOT (x AND y) b0 0 0 0 1 00 1 1 0 1 11 0 1 0 1 11 1 1 1 0 0

where b = ( x OR y ) AND ( NOT ( x AND y ) )

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 29 / 39

Page 30: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 11, item 3

The question: An exclusive or, denoted as XOR returns False onlywhen the inputs are both the same, and True otherwise.

3 Draw the circuit for the XOR, using the symbols for the gates NOT,OR, and AND.

The answer:

s

y

s

x

��HH c

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 30 / 39

Page 31: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 12

Use truth tables to verify that

((NOT A) AND B AND C) OR (A AND (NOT B) AND C)OR (A AND B AND (NOT C)) OR (A AND B AND C)

is equivalent to

(A AND B) OR (B AND C) OR (A AND C).

Draw a realization of the second expression using the diagrams for thelogic gates.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 31 / 39

Page 32: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 12: first truth tableGive the truth table of

((NOT A) AND B AND C) OR (A AND (NOT B) AND C)OR (A AND B AND (NOT C)) OR (A AND B AND C)

Let D = NOT A, E = NOT B, F = NOT C, G = D AND B AND C,H = A AND E AND C, I = A AND B AND F , J = A AND B AND C,K = G OR H OR I OR J.

A B C D E F G H I J K0 0 0 1 1 1 0 0 0 0 00 0 1 1 1 0 0 0 0 0 00 1 0 1 0 1 0 0 0 0 00 1 1 1 0 0 1 0 0 0 11 0 0 0 1 1 0 0 0 0 01 0 1 0 1 0 0 1 0 0 11 1 0 0 0 1 0 0 1 0 11 1 1 0 0 0 0 0 0 1 1

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 32 / 39

Page 33: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 12: second truth table

Give the truth table of

(A AND B) OR (B AND C) OR (A AND C).

Let D = A AND B, E = B AND C, F = A AND C, G = D OR E OR F .

A B C D E F G0 0 0 0 0 0 00 0 1 0 0 0 00 1 0 0 0 0 00 1 1 0 1 0 11 0 0 0 0 0 01 0 1 0 0 1 11 1 0 1 0 0 11 1 1 1 1 1 1

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 33 / 39

Page 34: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 12: the realization

Draw the realization of

(A AND B) OR (B AND C) OR (A AND C).

using the diagrams for the logic gates.The answer:

A s

B s

C s

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 34 / 39

Page 35: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 13Consider the flowchart, that takes on input the word w :

n = len(w)

?

��

�@@

@@

@@�

��

n > 0 ?

?True

-Falsestop

n = n − 1print w [n]

?

-

1 Explain what the algorithm defined by the flowchart does, that is:write pseudo code.

2 Redraw the flowchart that swaps the test with the body of the loop.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 35 / 39

Page 36: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 13: the pseudocode

The question: Explain what the algorithm defined by the flowchartdoes, that is: write pseudocode.

A potential answer:

The algorithm writes a word backwards.

Pseudocode:

Input: w, a sequence of n characters.Output: the sequence w written backwards.

for i from n-1 to 0 doprint w[i]

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 36 / 39

Page 37: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

answer to question 13: redraw the flowchart

Redraw the flowchart that swaps the test with the body of the loop.

n = len(w)

?n = n − 1print w [n]

?

��

�@@

@@

@@�

��

n == 0 ?

?False

-Truestop

-

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 37 / 39

Page 38: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

question 14

Describe the top down functional design for a program that takesorders in a fastfood restaurant.The program should display a menu, prompt the customer to make aselection, calculate the price of the order, and then finally ask thecustomer to confirm the order.Draw a hierarchy of the functions and for every function write a leastone line for documentation string.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 38 / 39

Page 39: review for the midterm, part 1 - University of Illinois at …homepages.math.uic.edu/~jan/mcs260s14/revoneans.pdfOutline 1 midterm exam on Friday 11 July 2014 policies for the first

potential answer to question 14

main��������

PPPPPPPPmenu price confirm

Short description for each function:

main: calls menu, price, and confirm (in that order).

menu: displays the menu, prompts for a choice,returns the choice to the main function.

price: given the choice, calculates the price,returns the price to the main function.

confirm: given the choice and the price, prints a confirmation.Prompts the user to confirm (or cancel) the order.

Intro to Computer Science (MCS 260) review for the midterm, part 1 L-10.0 9 July 2014 39 / 39