Outline. policies. with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016

Similar documents
Digital Logic Design Exercises. Assignment 1

Experimental Methods I

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Computer Organization and Levels of Abstraction

CDS Computing for Scientists. Midterm Exam Review. Midterm Exam on October 22, 2013

Computer Systems. Binary Representation. Binary Representation. Logical Computation: Boolean Algebra

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Binary Values. CSE 410 Lecture 02

The Design of C: A Rational Reconstruction

This podcast will demonstrate a logical approach as to how a computer adds through logical gates.

History of Computing. Ahmed Sallam 11/28/2014 1

The Design of C: A Rational Reconstruction"

Computer Organization and Levels of Abstraction

Outline. elements and behavior executing programs. developing programs use as a calculator converting strings to numbers

ETGG1801 Game Programming Foundations I Andrew Holbrook Fall Lecture 0 - Introduction to Computers 1

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

UNCA CSCI 255 Exam 1 Spring February, This is a closed book and closed notes exam. It is to be turned in by 1:45 PM.

WELCOME TO. ENGR 303 Introduction to Logic Design. Hello my name is Dr. Chuck Brown

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

Year 10 OCR GCSE Computer Science (9-1)

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Question Total Possible Test Score Total 100

The LC3's micro-coded controller ("useq") is nothing more than a finite-state machine (FSM). It has these inputs:

CS 202: Introduction to Computation Fall 2010: Exam #1

User. Application program. Interfaces. Operating system. Hardware

Syllabus for Computer Science General Part I

Outline. half adders adder circuits. the while loop the for loop. Euclid s algorithm approximating π

UNIT 1 USING LOGIC. UPGRADE 8 Write a detailed report on how logic gates would be used to add up two nibbles using examples and explanations

a name refers to an object side effect of assigning composite objects

ECE 341 Midterm Exam

5. (a) What is secondary storage? How does it differ from a primary storage? (b) Explain the functions of (i) cache memory (ii) Register

1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?

Electronic Engineering Part 1 Laboratory Experiment. Digital Circuit Design 1 Combinational Logic. (3 hours)

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Arab Open University. Computer Organization and Architecture - T103

Von Neumann Architecture

CDS130 Mid-term exam: Sample

COURSE OUTLINE & WEEK WISE BREAKAGE

Unit 2: Data Storage CS 101, Fall 2018

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Computer Architecture: Part V. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

One and a half hours. Section A is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Midterm Examination CLOSED BOOK

Digital Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields.

The Design of C: A Rational Reconstruction" Jennifer Rexford!


Computer Organisation IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

The Design of C: A Rational Reconstruction

Recitation Session 6

ECE 341 Midterm Exam

Midterm Exam Review. CS 2420 :: Fall 2016 Molly O'Neil

BCS Higher Education Qualifications. Level 4 Certificate in IT. Computer Network Technology Syllabus

Module 1: Information Representation I -- Number Systems

Philadelphia University Student Name: Student Number:

CS 105 Review Questions #3

CONCORDIA UNIVERSITY Department of Computer Science and Software Engineering COMP 228/4 Section PP Midterm Exam

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Binary Adders: Half Adders and Full Adders

Lecture 10: Floating Point, Digital Design

Fundamentals of Programming

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Chapter 4. Operations on Data

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

CE161-4-AU UNIVERSITY OF ESSEX. Undergraduate Examinations 2014 DIGITAL SYSTEMS ARCHITECTURE. Time allowed: TWO hours

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Lecture 10: Floating Point, Digital Design

Bits and Bit Patterns

EE292: Fundamentals of ECE

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

SIR C.R.REDDY COLLEGE OF ENGINEERING, ELURU DEPARTMENT OF INFORMATION TECHNOLOGY LESSON PLAN

Midterm Exam 2B Answer key

Introduction to the Use of Computers

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

EE 109L Review. Name: Solutions

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

CS 1313 Spring 2000 Lecture Outline

Topics. Computer Organization CS Exam 2 Review. Infix Notation. Reverse Polish Notation (RPN)

Read this before starting!

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

Computer science Higher level Paper 1

Welcome to MCS 275. Course Content Prerequisites & Expectations. Scripting in Python from OOP to LAMP example: Factorization in Primes

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Chapter 1. Data Storage Pearson Addison-Wesley. All rights reserved

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

Midterm Exam 2A Principles of Computing Fall November 10, 2014

GARDEN CITY UNIVERSITY. Bachelor of Computer Applications SEMESTER- I. Course: CONCEPTS OF PROGRAMMING USING C LANGUAGE CODE: 05ABCAR17111 CREDITS: 04

Read this before starting!

DIGITA L LOGIC AND COMPUTER ORGA NIZATION

Basic Arithmetic (adding and subtracting)

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Introduction to Computing Module No: CS/ES/1 Quadrant 1 e-text

Transcription:

Outline 1 midterm exam on Friday 26 February 2016 policies 2 questions with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 1 / 39

review of the first 18 lectures 1 midterm exam on Friday 26 February 2016 policies 2 questions with some potential answers... Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 2 / 39

policies The exam will be closed book, no notes, and no computer. The material on computer literacy breaks down in two parts: 1 computer science concepts: algorithms, computer architecture, functionality of operating systems, mass storage, formal languages, flowcharts and pseudocode, logic gates, transistors and flip flops, adder circuits, functional programming. 2 mathematical CS: binary and hexadecimal representations of numbers, precision and accuracy, boolean algebra, truth tables, simulation and Monte Carlo, histograms. This review contains some preliminary examples of questions which may help you prepare for the first part of the midterm exam. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 3 / 39

review of the first 18 lectures 1 midterm exam on Friday 26 February 2016 policies 2 questions with some potential answers... Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 4 / 39

question 1 List the characteristics of an algorithm. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 5 / 39

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-19 24 February 2016 6 / 39

question 2 How many bytes are 15 terabytes? Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 7 / 39

answer to question 2 The question: How many bytes are 15 terabytes? A potential answer: tera = 2 40. So 15 terabytes are 15 2 40 bytes, or approximately 15 trillion bytes. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 8 / 39

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-19 24 February 2016 9 / 39

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 number which represents the rational number 34/87 up to machine precision. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 10 / 39

question 4 What is an interrupt? Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 11 / 39

answer to question 4 The question: What is an interrupt? A potential answer: An interrupt causes an executing process to go in 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-19 24 February 2016 12 / 39

question 5 Describe the differences between a compiler and an interpreter. What are the advantages/disadvantages of using a compiler and an interpreter? Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 13 / 39

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 after the other and executes each statement as soon as its translation is done. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 14 / 39

answer to question 5, part two The second part of the question: What are the advantages/disadvantages of using a compiler and an interpreter? A potential (very short) answer: Compiled code executes faster than interpreted code. Code can be developed faster with an interpreter than with a compiler. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 15 / 39

question 6 Convert 318 into hexadecimal notation. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 16 / 39

answer to question 6 The question: Convert 318 into hexadecimal notation. A potential answer: n n/16 n mod 16 318 19 14 318 = 19 16 + 14 19 1 3 19 = 1 16 + 3 1 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 binary and group the bits in sequences of four. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 17 / 39

question 7 Rank all memory elements we have seen twice: 1 use once its speed (memory that is fastest to access comes first); and 2 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-19 24 February 2016 18 / 39

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); and 2 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-19 24 February 2016 19 / 39

question 8 What is the kernel of an operating system? Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 20 / 39

answer to question 8 The question: What is the kernel of an operating system? A potential answer: The kernel of an operating system 1 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-19 24 February 2016 21 / 39

question 9 Consider the circuit shown below. For b 1 = 1 and b 2 = 0 as input, indicate on the picture below the input and output for every logical gate. b 1 S C b 2 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 22 / 39

answer to question 9 Consider the circuit shown below. For b 1 = 1 and b 2 = 0 as input, indicate on the picture below the input and output for every logical gate. The answer: b 1 1 0 1 1 0 0 1 0 1 S 1 0 0 C b 2 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 23 / 39

question 10 Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers. Write pseudo code for this algorithm as well. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 24 / 39

answer to question 10: the flowchart The question: Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers. A potential answer: n = len(l); m = L[0]; i = 1 i < n? False print m True L[i] > m? False True m = L[i] i = i + 1 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 25 / 39

answer to question 10: the pseudocode The question: Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers. Write pseudo code for this algorithm 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 then let m be L[i] Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 26 / 39

question 11 An exclusive or, denoted as XOR returns False only when the inputs are 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-19 24 February 2016 27 / 39

answer to question 11, item 1 The question: An exclusive or, denoted as XOR returns False only when the inputs are both the same, and True otherwise. 1 Give the truth table for the exclusive or. The answer: x y xxory 0 0 0 0 1 1 1 0 1 1 1 0 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 28 / 39

answer to question 11, item 2 The question: An exclusive or, denoted as XOR returns False only when the inputs are both the same, and True otherwise. 2 Show how the XOR can be realized with NOT, OR, and AND by giving the logical expressions and their corresponding truth tables. The answer: x y xory x AND y NOT (x AND y) b 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 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-19 24 February 2016 29 / 39

answer to question 11, item 3 The question: An exclusive or, denoted as XOR returns False only when 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: x y Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 30 / 39

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 the logic gates. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 31 / 39

answer to question 12: first truth table Give 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 K 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 32 / 39

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 G 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 33 / 39

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 B C Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 34 / 39

question 13 Consider the flowchart, that takes on input the word w: n = len(w) n > 0? False stop True n = n 1 print 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-19 24 February 2016 35 / 39

answer to question 13: the pseudocode The question: Explain what the algorithm defined by the flowchart does, 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 do print w[i] Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 36 / 39

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 1 print w[n] n == 0? True stop False Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 37 / 39

question 14 Describe the top down functional design for a program that takes orders in a fastfood restaurant. The program should display a menu, prompt the customer to make a selection, calculate the price of the order, and then finally ask the customer to confirm the order. Draw a hierarchy of the functions and for every function write a least one line for documentation string. Intro to Computer Science (MCS 260) review for the midterm, part 1 L-19 24 February 2016 38 / 39

potential answer to question 14 main menu 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-19 24 February 2016 39 / 39