Sample Problems for Quiz # 2

Size: px
Start display at page:

Download "Sample Problems for Quiz # 2"

Transcription

1 EE 1301 UMN Introduction to Computing Systems Fall 2013 Sample Problems for Quiz # 2 (with solutions) Here are sample problems to help you prepare for Quiz 2 on Oct Bit-Level Arithmetic (a) Consider the following C program. # include <stdio.h> int main ( int argc, char ** argv ) unsigned int v; v = atoi ( argv [1]); v - -; v = v >> 1; v = v >> 2; v = v >> 4; v = v >> 8; v = v >> 16; v ++; printf ("%d\n", v); What will it print out if it is called as follows?./ rndpow2 32./ rndpow2 42./ rndpow Hint: the program computes 1 << (log 2 (v 1) + 1).

2 EE 1301, Fall 13 2 (b) What will the following program print out? # include <stdio.h> int main () int i; int m = 0xA; unsigned int n = 0; for (i = 0; i < 8; i ++) n = (m << i *4); for (i = 0; i < 32; i ++) printf ("%d", (n >> i) & 1); printf ("\n"); Answer:

3 EE 1301, Fall 13 3 (c) Consider the following program. # include <stdio.h> enum boolean false, true ; int main ( int argc, char ** argv ) int i; int n = atoi ( argv [1]); enum boolean sign = atoi ( argv [ 2]) > 0? true : false ; unsigned int r; if ( sign ) r = 0; r = (1 << n); else r = ~0; r ^= (1 << n); for (i = 0; i < 32; i ++) printf ("%d", (r >> i) & 1); printf ("\n"); Suppose that it is called with the following arguments. What will it print out?./ set - given - bit 7 0 Answer: / set - given - bit 27 1 Answer:

4 EE 1301, Fall Finite-Precision Arithmetic Consider the following program. # include <stdio.h> int main () unsigned char a = 100; unsigned char b = 200; unsigned char c = a + b; unsigned char d = a - b; char e = a + b; char f = a - b; char g = -(a + b); int h = a + b; printf ("%d %d %d %d %d %d %d %d %o %x\n", a, b, c, d, e, f, g, h, h, h); What will it print out? Answer: c

5 EE 1301, Fall Optimal Cost Paths Through Graphs Find the minimum cost path from A to be B, where the cost is the sum of the numbers along that path / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / 2 \ / 11 \ / 8 \ / 7 \ / 4 \ / 1 \ / 1 \ / 8 \ A / / / / / / / / B \ / \ 9 / \ 5 / \ 1 / \ 25 / \ 8 / \ 1 / \ 15 / \ 9 / \ / \ / \ / \ / \ / \ / \ / \ / \ /

6 EE 1301, Fall Number Systems (a) Suppose that the following bits represent positive numbers. their decimal equivalents. i Answer: ii Answer: iii Answer: iv Answer: Convert them to (b) Suppose that the following bits represent positive and negative numbers in two s complement notation. Perform the operation indicated. If the result cannot be represented with 8 bits, say so. i Answer: = ii Answer: Positive number plus positive number yields negative number. Conclude that result cannot be represented with 8 bits. iii Answer: = Extra bit falls off. But then we have a negative number plus a negative number yields a positive number. Conclude that result cannot be represented with 8 bits. iv Answer: = = = (c) Suppose that the following are all positive numbers. Perform the indicated conversion. i to hexademical. Answer: = 16D1EE 16. ii to hexademical. Answer: = = iii. AF AB 16 to octal. Answer: = =

7 EE 1301, Fall Ninjas and Knapsacks This problem will test your understanding of dynamic programming, an algorithmic archetype that we discussed in class Suppose that a ninja has broken into the Imperial Palace in Tokyo to steal valuable trinkets. He will catch the direct return flight with Delta to Minneapolis, but he s very annoyed at Delta s new fees for checked-in luggage. Out of principle, he refuses to pay such fees; everything that he steals from the Imperial Palace must fit in his backpack as carry-on. The tensile strength of his UMN backpack is such that he can safely pack 10 lbs. The ninja assesses the value and weight of the trinkets to be as follows: item value weight What is the value of the best choice of trinkets? Solution See attached spreadsheet.

8 EE 1301, Fall Sorting This problem tests your understanding of sorting (and, of course, recursion). Here is the algorithm that we discussed in class, mergesort(). What does the code print out? # include <stdio.h> mergesort ( int a[], int low, int high ) int mid ; if(low < high ) mid =( low + high )/2; mergesort (a, low, mid ); mergesort (a, mid + 1, high ); merge (a,low, high, mid ); return (0); merge ( int a[], int low, int high, int mid ) printf ("%d, %d, %d\n", low, high, mid ); int i, j, k, c [10]; i = low ; j = mid + 1; k = low ; while ((i <= mid ) &&( j <= high )) if(a[i] < a[j]) c[k] = a[i]; k ++; i ++; else c[k] = a[j]; k ++; j ++; while (i <= mid ) c[k] = a[i]; k ++;

9 EE 1301, Fall 13 9 i ++; while (j <= high ) c[k] = a[j]; k ++; j ++; for (i = low ; i < k; i ++) a[i] = c[i]; int main ( int argc, char ** argv ) int i; int v [10] = 6, 21, 3, 89, 2, 77, 1, 78, 79, 99; mergesort (v, 0, 9); for ( i = 0; i < 10; i ++) printf ("%d ", v[i ]); printf ("\n"); Answer 0, 1, 0 0, 2, 1 3, 4, 3 0, 4, 2 5, 6, 5 5, 7, 6 8, 9, 8 5, 9, 7 0, 9,

10 EE 1301, Fall Here is one the most common sorting algorithm, quicksort(). What does the code printout? # include <stdio.h> /* swap : interchange v[i] and v[j] */ void swap ( int v[], int i, int j) int temp ; temp = v[i]; v[i] = v[j]; v[j] = temp ; /* qsort : sort v[ left ]... v[ right ] into increasing order */ void qsort ( int v[], int left, int right ) int i, last ; printf (" left %d, right %d\n", left, right ); /* do nothing if array contains fewer than two elements */ if ( left >= right ) return ; /* move " pivot " element to v [0] */ swap (v, left, ( left + right )/2); last = left ; /* partition */ for ( i = left + 1; i <= right ; i ++) if (v[i] < v[ left ]) swap (v, ++ last, i); /* restore " pivot " element */ swap (v, left, last ); qsort (v, left, last -1); qsort (v, last +1, right ); int main ( int argc, char ** argv )

11 EE 1301, Fall int i; int v [10] = 6, 21, 3, 89, 2, 77, 1, 78, 79, 99; qsort (v, 0, 9); for ( i = 0; i < 9; i ++) printf ("%d ", v[i ]); printf ("\n"); Answer left 0, right 9 left 0, right 0 left 2, right 9 left 2, right 4 left 2, right 2 left 4, right 4 left 6, right 9 left 6, right 5 left 7, right 9 left 7, right 6 left 8, right 9 left 8, right 7 left 9, right

12 EE 1301, Fall Graphs for Coding This problem asks you to formulate codes for characters of the alphabet, using graphs specifically binary decision diagrams. In 1951, David A. Huffman and his MIT information theory classmates were given the choice of a term paper or a final exam. The professor, Robert M. Fano, assigned a term paper on the problem of finding the most efficient binary code. Huffman, unable to prove any codes were the most efficient, was about to give up and start studying for the final when he hit upon the idea of using a frequency-sorted binary tree and quickly proved this method the most efficient. In doing so, the student outdid his professor, who had worked with information theory inventor Claude Shannon to develop a similar code. Huffman avoided the major flaw of previous coding by building the tree from the bottom up instead of from the top down. Suppose that the following characters appear with the given frequency. Determine an optimal binary code for these characters. Char Frequency space 7 a 4 e 4 f 3 h 2 i 2 m 2 n 2 s 2 t 2 l 1 o 1 p 1 r 1 u 1 x 1

13 EE 1301, Fall Solution Char Frequency Code space a e f h i m n s t l o p r u x

ECE264 Fall 2013 Exam 1, September 24, 2013

ECE264 Fall 2013 Exam 1, September 24, 2013 ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

Introduction to Computing Systems Fall Lab # 3

Introduction to Computing Systems Fall Lab # 3 EE 1301 UMN Introduction to Computing Systems Fall 2013 Lab # 3 Collaboration is encouraged. You may discuss the problems with other students, but you must write up your own solutions, including all your

More information

ECE264 Summer 2013 Exam 1, June 20, 2013

ECE264 Summer 2013 Exam 1, June 20, 2013 ECE26 Summer 2013 Exam 1, June 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it. I

More information

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 3, November 20, 2013 ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

ECE264 Spring 2013 Exam 1, February 14, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013 ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Sample Problems for Quiz # 3

Sample Problems for Quiz # 3 EE 1301 UMN Introduction to Computing Sstems Spring 2013 Sample Problems for Quiz # 3 1. Implementing XOR with AND gates Recall that the Eclusive-OR (XOR) function is 1 if an odd number of the inputs are

More information

ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

More information

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal. Problem 1 Recall the definition of root in project 1. (The declaration of struct entrynode appears below.) struct entrynode * root; Give the type of each of the following expressions. The answer may be

More information

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:... Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS

More information

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators CSE 351: The Hardware/Software Interface Section 2 Integer representations, two s complement, and bitwise operators Integer representations In addition to decimal notation, it s important to be able to

More information

Lecture 6 Sorting and Searching

Lecture 6 Sorting and Searching Lecture 6 Sorting and Searching Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 77 42 35 12 101 5 1 2 3 4 5 6 5 12 35 42 77 101 There are many algorithms for sorting a list

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

Functions. Arash Rafiey. September 26, 2017

Functions. Arash Rafiey. September 26, 2017 September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic

More information

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin CS 61B Summer 2005 (Porter) Midterm 2 July 21, 2005 - SOLUTIONS Do not open until told to begin This exam is CLOSED BOOK, but you may use 1 letter-sized page of notes that you have created. Problem 0:

More information

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm Name: Umail Address: @ umail.ucsb.edu Circle Lab section: 9am 10am 11am noon (Link to Printer Friendly-PDF

More information

CS 241 Data Organization Binary

CS 241 Data Organization Binary CS 241 Data Organization Binary Brooke Chenoweth University of New Mexico Fall 2017 Combinations and Permutations In English we use the word combination loosely, without thinking if the order of things

More information

Beginning C Programming for Engineers

Beginning C Programming for Engineers Beginning Programming for Engineers R. Lindsay Todd Lecture 6: Bit Operations R. Lindsay Todd () Beginning Programming for Engineers Beg 6 1 / 32 Outline Outline 1 Place Value Octal Hexadecimal Binary

More information

Make sure the version number is marked on your scantron sheet. This is Version 1

Make sure the version number is marked on your scantron sheet. This is Version 1 Last Name First Name McGill ID Make sure the version number is marked on your scantron sheet. This is Version 1 McGill University COMP 208 -- Computers in Engineering Mid-Term Examination Tuesday, March

More information

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name: CS-211 Fall 2017 Test 1 Version A Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If I code a C

More information

COMP2012H Spring 2014 Dekai Wu. Sorting. (more on sorting algorithms: mergesort, quicksort, heapsort)

COMP2012H Spring 2014 Dekai Wu. Sorting. (more on sorting algorithms: mergesort, quicksort, heapsort) COMP2012H Spring 2014 Dekai Wu Sorting (more on sorting algorithms: mergesort, quicksort, heapsort) Merge Sort Recursive sorting strategy. Let s look at merge(.. ) first. COMP2012H (Sorting) 2 COMP2012H

More information

This is CS50. Harvard University Fall Quiz 0 Answer Key

This is CS50. Harvard University Fall Quiz 0 Answer Key Quiz 0 Answer Key Answers other than the below may be possible. Binary Bulbs. 0. Bit- Sized Questions. 1. Because 0 is non- negative, we need to set aside one pattern of bits (000) for it, which leaves

More information

Chapter 7 C Pointers

Chapter 7 C Pointers Chapter 7 C Pointers Objectives of This Chapter Definition and Operations with Pointers Using Pointers to pass arguments as call by reference call. Using Pointers to deal with arrays and strings. Character

More information

CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name:

CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name: CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a)

More information

Searching Elements in an Array: Linear and Binary Search. Spring Semester 2007 Programming and Data Structure 1

Searching Elements in an Array: Linear and Binary Search. Spring Semester 2007 Programming and Data Structure 1 Searching Elements in an Array: Linear and Binary Search Spring Semester 2007 Programming and Data Structure 1 Searching Check if a given element (called key) occurs in the array. Example: array of student

More information

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Lecture given by: Paolo Bientinesi First exam, 10.02.2015 The following document is a transcript from memory created

More information

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Please check your tutorial (TUT) section from the list below: TUT 101: F 11:30, MC 4042 TUT 102: M 10:30, MC 4042 TUT 103: M 11:30, MC 4058 TUT 104: F 10:30,

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

COSC242 Lecture 7 Mergesort and Quicksort

COSC242 Lecture 7 Mergesort and Quicksort COSC242 Lecture 7 Mergesort and Quicksort We saw last time that the time complexity function for Mergesort is T (n) = n + n log n. It is not hard to see that T (n) = O(n log n). After all, n + n log n

More information

Chapter 4: Computer Codes. In this chapter you will learn about:

Chapter 4: Computer Codes. In this chapter you will learn about: Ref. Page Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence Ref. Page

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

C0MP1911 Final Exam 1337 Computing 1

C0MP1911 Final Exam 1337 Computing 1 Family Name: Other Names: Signature: Student Number: This PAPER is NOT to be retained by the STUDENT The University Of New South Wales C0MP1911 Final Exam 1337 Computing 1 July 2006 Time allowed: 3 hrs

More information

Data Types. Operators, Assignment, Output and Return Statements

Data Types. Operators, Assignment, Output and Return Statements Pseudocode Reference Sheet rev 4/17 jbo Note: This document has been developed by WeTeach_CS, and is solely based on current study materials and practice tests provided on the TEA website. An official

More information

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal Positional notation Ch.. /continued Conversions between Decimal and Binary Binary to Decimal - use the definition of a number in a positional number system with base - evaluate the definition formula using

More information

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number:

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number: Login Preceptor Precept Number: Computer Science 126 Second Midterm Exam 11/22/1999 7pm - 9pm This exam has 10 questions. The weight of each question is printed in the table below and next to each question.

More information

Better sorting algorithms (Weiss chapter )

Better sorting algorithms (Weiss chapter ) Better sorting algorithms (Weiss chapter 8.5 8.6) Divide and conquer Very general name for a type of recursive algorithm You have a problem to solve. Split that problem into smaller subproblems Recursively

More information

Solutions to Assessment

Solutions to Assessment Solutions to Assessment [1] What does the code segment below print? int fun(int x) ++x; int main() int x = 1; fun(x); printf( %d, x); return 0; Answer : 1. The argument to the function is passed by value.

More information

The type of all data used in a C (or C++) program must be specified

The type of all data used in a C (or C++) program must be specified The type of all data used in a C (or C++) program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Efficient Sorting Algorithms Eng. Anis Nazer First Semester 2017-2018 Efficient Sorting Simple sorting complexity Efficient sorting complexity O(n 2 ) O(nlg n) Merge sort

More information

Administrivia. HW on recursive lists due on Wednesday. Reading for Wednesday: Chapter 9 thru Quicksort (pp )

Administrivia. HW on recursive lists due on Wednesday. Reading for Wednesday: Chapter 9 thru Quicksort (pp ) Sorting 4/23/18 Administrivia HW on recursive lists due on Wednesday Reading for Wednesday: Chapter 9 thru Quicksort (pp. 271-284) A common problem: Sorting Have collection of objects (numbers, strings,

More information

Divide and Conquer Strategy. (Page#27)

Divide and Conquer Strategy. (Page#27) MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com Reference Short Questions for MID TERM EXAMS CS502 Design and Analysis of Algorithms Divide and Conquer Strategy

More information

QuickSort

QuickSort QuickSort 7 4 9 6 2 2 4 6 7 9 4 2 2 4 7 9 7 9 2 2 9 9 1 QuickSort QuickSort on an input sequence S with n elements consists of three steps: n n n Divide: partition S into two sequences S 1 and S 2 of about

More information

Answer all questions. Write your answers only in the space provided. Full marks = 50

Answer all questions. Write your answers only in the space provided. Full marks = 50 Answer all questions. Write your answers only in the space provided. Full marks = 50 1. Answer the following: [2+3+2+1=8 marks] a) What are the minimum and maximum numbers that can be represented in 10-bit

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures ITEC2620 Introduction to Data Structures Lecture 5a Recursive Sorting Algorithms Overview Previous sorting algorithms were O(n 2 ) on average For 1 million records, that s 1 trillion operations slow! What

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of

More information

Introduction to Algorithms and Data Structures. Lecture 12: Sorting (3) Quick sort, complexity of sort algorithms, and counting sort

Introduction to Algorithms and Data Structures. Lecture 12: Sorting (3) Quick sort, complexity of sort algorithms, and counting sort Introduction to Algorithms and Data Structures Lecture 12: Sorting (3) Quick sort, complexity of sort algorithms, and counting sort Professor Ryuhei Uehara, School of Information Science, JAIST, Japan.

More information

CS 146 Midterm Exam 2 Grade: Professors Howard, Fine, and Howard have proposed the following sorting algorithm:

CS 146 Midterm Exam 2 Grade: Professors Howard, Fine, and Howard have proposed the following sorting algorithm: CS 146 Midterm Exam 2 Name: Grade: The test will be open book, open notes, 75 minute time limit. No electronic devices allowed (except a music player whose buttons you don t push). Please write your answers

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

Assignment 4: Question 1b omitted. Assignment 5: Question 1b clarification

Assignment 4: Question 1b omitted. Assignment 5: Question 1b clarification Announcements Assignment 4: Question 1b omitted Assignment 5: Question 1b clarification /* initialize and keep track of the last processed element smaller than pivot; use the mid variable from lecture

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

CS 137 Part 7. Big-Oh Notation, Linear Searching and Basic Sorting Algorithms. November 10th, 2017

CS 137 Part 7. Big-Oh Notation, Linear Searching and Basic Sorting Algorithms. November 10th, 2017 CS 137 Part 7 Big-Oh Notation, Linear Searching and Basic Sorting Algorithms November 10th, 2017 Big-Oh Notation Up to this point, we ve been writing code without any consideration for optimization. There

More information

UNIT-2. Problem of size n. Sub-problem 1 size n/2. Sub-problem 2 size n/2. Solution to the original problem

UNIT-2. Problem of size n. Sub-problem 1 size n/2. Sub-problem 2 size n/2. Solution to the original problem Divide-and-conquer method: Divide-and-conquer is probably the best known general algorithm design technique. The principle behind the Divide-and-conquer algorithm design technique is that it is easier

More information

CHAPTER 7 Iris Hui-Ru Jiang Fall 2008

CHAPTER 7 Iris Hui-Ru Jiang Fall 2008 CHAPTER 7 SORTING Iris Hui-Ru Jiang Fall 2008 2 Contents Comparison sort Bubble sort Selection sort Insertion sort Merge sort Quick sort Heap sort Introspective sort (Introsort) Readings Chapter 7 The

More information

Bubble sort starts with very first two elements, comparing them to check which one is greater.

Bubble sort starts with very first two elements, comparing them to check which one is greater. Bubble Sorting: Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they

More information

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers CSC 2400: Computer Systems Bits, Bytes and Data Types 1 Goals for this Week Binary number system Why binary? Converting between decimal and binary and octal and hexadecimal number systems Finite representations

More information

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

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

Searching Algorithms/Time Analysis

Searching Algorithms/Time Analysis Searching Algorithms/Time Analysis CSE21 Fall 2017, Day 8 Oct 16, 2017 https://sites.google.com/a/eng.ucsd.edu/cse21-fall-2017-miles-jones/ (MinSort) loop invariant induction Loop invariant: After the

More information

CSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms

CSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms Lecture 18 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms 17-Oct-2018 Location: Chemistry 125 Time: 12:35 13:25

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

COMP1917 Computing 1 Written Exam Sample Questions

COMP1917 Computing 1 Written Exam Sample Questions COMP1917 Computing 1 Written Exam Sample Questions Note: these sample questions are intended to provide examples of a certain style of question which did not occur in the tutorial or laboratory exercises,

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Midterm Exam Review Slides

Midterm Exam Review Slides Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Review Topics Number Representation Base Conversion

More information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 0-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

Practice final for EECS 380, 2001: Prof Markov

Practice final for EECS 380, 2001: Prof Markov Practice final for EECS 380, 2001: Prof Markov Available in Postscript and PDF Total pages: 5 Exam duration: 1hr 50min. Write your name and uniqname on every sheet, including the cover. Maximum score:

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS Fast sorting algorithms Shellsort, Mergesort, Quicksort Summary of the previous lecture Why sorting is needed? Examples from everyday life What are the basic operations in

More information

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : End-Semester Examination

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : End-Semester Examination Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn 2017-18: End-Semester Examination Time: 3 Hours Full Marks: 100 INSTRUCTIONS 1. Answer ALL questions. 2. Please

More information

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn 2017-18: Mid-Semester Examination Time: 2 Hours Full Marks: 60 INSTRUCTIONS 1. Answer ALL questions 2. Please write

More information

Duration: 110 minutes

Duration: 110 minutes EASTERN MEDITERRANEAN UNIVERSITY Computer Engineering Department CMPE-231 DATA STRUCTURES FINAL EXAMINATION 13 June 2014 Duration: 110 minutes Name, Surname. SOLUTION KEY......... Student ID #..........

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

CS13002 Programming and Data Structures, Spring 2005

CS13002 Programming and Data Structures, Spring 2005 CS13002 Programming and Data Structures, Spring 2005 Mid-semester examination : Solutions Roll no: FB1331 Section: @ Name: Foolan Barik Answer all questions. Write your answers in the question paper itself.

More information

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

CSCI 2132 Software Development. Lecture 17: Functions and Recursion CSCI 2132 Software Development Lecture 17: Functions and Recursion Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 15-Oct-2018 (17) CSCI 2132 1 Previous Lecture Example: binary

More information

Tools for algorithms and programs. From practice to theory and back again. On to sorting: Selection Sort. To code or not to code, that is the

Tools for algorithms and programs. From practice to theory and back again. On to sorting: Selection Sort. To code or not to code, that is the From practice to theory and back again Tools for algorithms and programs In theory there is no difference between theory and practice, but not in practice We ve studied binary search: requires a sorted

More information

Quiz 0 Review Session. October 13th, 2014

Quiz 0 Review Session. October 13th, 2014 Quiz 0 Review Session October 13th, 2014 Topics (non-exhaustive) Binary. ASCII. Algorithms. Pseudocode. Source code. Compiler. Object code. Scratch. Statements. Boolean expressions. Conditions. Loops.

More information

Computer Organization & Systems Exam I Example Questions

Computer Organization & Systems Exam I Example Questions Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C

More information

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 3:- Divide and Conquer Compiled By:- Assistant Professor, SVBIT. Outline Introduction Multiplying large Integers Problem Problem Solving using divide and conquer algorithm - Binary Search Sorting

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms Instructor: SharmaThankachan Lecture 10: Greedy Algorithm Slides modified from Dr. Hon, with permission 1 About this lecture Introduce Greedy Algorithm Look at some problems

More information

Review Topics. Midterm Exam Review Slides

Review Topics. Midterm Exam Review Slides Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University!! Computer Arithmetic!! Combinational

More information

Programming in C. Pointers and Arrays

Programming in C. Pointers and Arrays Programming in C Pointers and Arrays NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313 http://www.csee.umbc.edu/courses/undergraduate/313/fall11/" Pointers and Arrays In C, there is a strong relationship

More information

Recursion. Chapter 17 CMPE13. Cyrus Bazeghi

Recursion. Chapter 17 CMPE13. Cyrus Bazeghi Recursion Chapter 17 CMPE13 Cyrus Bazeghi What is Recursion? A recursive function is one that solves its task by calling itself on smaller pieces of data. Similar to recurrence function in mathematics.

More information

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort Principles of Imperative Computation V. Adamchik CS 15-1 Lecture Carnegie Mellon University Sorting Sorting Sorting is ordering a list of objects. comparison non-comparison Hoare Knuth Bubble (Shell, Gnome)

More information

AMCAT Automata Coding Sample Questions And Answers

AMCAT Automata Coding Sample Questions And Answers 1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return

More information

CSC 505, Spring 2005 Week 6 Lectures page 1 of 9

CSC 505, Spring 2005 Week 6 Lectures page 1 of 9 CSC 505, Spring 2005 Week 6 Lectures page 1 of 9 Objectives: learn general strategies for problems about order statistics learn how to find the median (or k-th largest) in linear average-case number of

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or

More information

David Rappaport School of Computing Queen s University CANADA. Copyright, 1996 Dale Carnegie & Associates, Inc.

David Rappaport School of Computing Queen s University CANADA. Copyright, 1996 Dale Carnegie & Associates, Inc. David Rappaport School of Computing Queen s University CANADA Copyright, 1996 Dale Carnegie & Associates, Inc. Data Compression There are two broad categories of data compression: Lossless Compression

More information

Quicksort. Repeat the process recursively for the left- and rightsub-blocks.

Quicksort. Repeat the process recursively for the left- and rightsub-blocks. Quicksort As the name implies, this is the fastest known sorting algorithm in practice. It is excellent for average input but bad for the worst-case input. (you will see later). Basic idea: (another divide-and-conquer

More information

Denotational semantics

Denotational semantics 1 Denotational semantics 2 What we're doing today We're looking at how to reason about the effect of a program by mapping it into mathematical objects Specifically, answering the question which function

More information

CSCI 2132 Final Exam Solutions

CSCI 2132 Final Exam Solutions Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question

More information

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring: ECE 120 Midterm 1 HKN Review Session Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location: Your Room on Compass What to bring: icard, pens/pencils, Cheat sheet (Handwritten) Overview of Review Binary IEEE

More information

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \ BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Expression and Operator

Expression and Operator Expression and Operator Examples: Two types: Expressions and Operators 3 + 5; x; x=0; x=x+1; printf("%d",x); Function calls The expressions formed by data and operators An expression in C usually has a

More information

Data Structures and Algorithms 2018

Data Structures and Algorithms 2018 Question 1 (12 marks) Data Structures and Algorithms 2018 Assignment 4 25% of Continuous Assessment Mark Deadline : 5pm Monday 12 th March, via Canvas Sort the array [5, 3, 4, 6, 8, 4, 1, 9, 7, 1, 2] using

More information

MPATE-GE 2618: C Programming for Music Technology. Unit 4.2

MPATE-GE 2618: C Programming for Music Technology. Unit 4.2 MPATE-GE 2618: C Programming for Music Technology Unit 4.2 Quiz 1 results (out of 25) Mean: 19.9, (standard deviation = 3.9) Equivalent to 79.1% (SD = 15.6) Median: 21.5 High score: 24 Low score: 13 Pointer

More information

Sorting. Bringing Order to the World

Sorting. Bringing Order to the World Lecture 10 Sorting Bringing Order to the World Lecture Outline Iterative sorting algorithms (comparison based) Selection Sort Bubble Sort Insertion Sort Recursive sorting algorithms (comparison based)

More information

Simple Data Types in C. Alan L. Cox

Simple Data Types in C. Alan L. Cox Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

n 1 x i = xn 1 x 1. i= (2n 1) = n 2.

n 1 x i = xn 1 x 1. i= (2n 1) = n 2. Questions 1. Use mathematical induction to prove that, for any n 1 n 1 x i = xn 1 x 1. (Recall that I proved it in a different way back in lecture 2.) 2. Use mathematical induction to prove that, for all

More information