Introduction to Programming (Java) 3/12

Size: px
Start display at page:

Download "Introduction to Programming (Java) 3/12"

Transcription

1 Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c Michal Krátký Introduction to Programming (Java) 1/31

2 Statement Introduction to Programming (Java) 3/12 A statement is the expression finished by ; a = b + c ; / / an assignment statement i ++; sum( a, b ) ; / / a d e c l a r a t i o n statement i n t i ; double x, y, z ; / / a d e c l a r a t i o n and d e f i n i t i o n statement i n t i = 4 ; double x = , y, z = i 2. 0 ; c Michal Krátký Introduction to Programming (Java) 2/31

3 Block 1/2 Introduction to Programming (Java) 3/12 A block is a sequence of statements between braces and. Example: a = 2 7 ; i n t b = a / 3 ; / / b = 9 a = b % 2 ; / / a = 1 a = b / 2 ; / / a = 4 c Michal Krátký Introduction to Programming (Java) 3/31

4 Block 2/2 Introduction to Programming (Java) 3/12 A scope of a local variable declaration is from the point of the declaration to the end of the enclosed block. int a; a = 2 7 ; i n t b = a / 3 ; / / b = 9 a = b % 2 ; / / a = 1 a = b / 2 ; / / a = 4 / / here : a i s i n scope, b i s not v a l i d c Michal Krátký Introduction to Programming (Java) 4/31

5 1/4 An array is the static data structure including values of the same data types: homogeneous data structure the array size (length or the number of items) is known in the time of the array creation an identifier (the name of the array) is a reference at the array of values c Michal Krátký Introduction to Programming (Java) 5/31

6 2/4 double vector [ ] = new double [ 5 ] ; vector [ 0 ] = 1. 6 ; vector [ 1 ] = 2. 0 ; vector [ 2 ] = 0. 1 ; vector [ 3 ] = 1. 0 ; vector [ 4 ] = 1. 2 ; vector vector[0] vector[1] vector[2] vector[3] vector[4] An array is possible to initialize during the declaration (the new operator is called implicitly): double vector [ ] = 1. 6, 2. 0, 0. 1, 1. 0, 1. 2 ; c Michal Krátký Introduction to Programming (Java) 6/31

7 3/4 The index (the location of an item in an array) starts from 0 (the first item has the index 0). The last item in an array of the n size has the (n 1) index. The array includes the special attribute with the size of the array: i n t [ ] vector = new i n t [ 5 ] ; i n t n = v e ctor. l e n g t h ; The following declarations are equivalent: i n t [ ] vector ; i n t vector [ ] ; vector vector[0] vector[1] vector[2] vector[3] vector[4] c Michal Krátký Introduction to Programming (Java) 7/31

8 4/4 If the variable is declared as an array i n t [ ] a = new i n t [ 4 ] ; we call the a variable as the array. After an ansignment: i n t [ ] b = a ; a and b reference the same array. If we change the a[0] value, the b[0] value is changed as well. a b c Michal Krátký Introduction to Programming (Java) 8/31

9 , Example f i n a l i n t size = 3 1 ; i n t arraya [ ] = new i n t [ s ize ] ; i n t arrayb [ ] = arraya ; arraya [ 0 ] = 1 ; System. out. p r i n t l n ( " arraya [ 0 ] = " + arraya [ i ] + ", arrayb [ 0 ] = " + arrayb [ i ] ) ; c Michal Krátký Introduction to Programming (Java) 9/31

10 Multidimensional Multidimensional array is the one-dimensional array with arrays as items. double matrix [ ] [ ] = 1. 0, 0. 0, 0. 0, 0. 0, 0. 0, 1. 0, 0. 0, 0. 0, 0. 0, 0. 0, 1. 0, 0. 0 ; matrix [ 2 ] [ 2 ] = ; System. out. p r i n t l n ( " m a t r i x [ 2 ] [ 2 ] = " + m a t r i x [ 2 ] [ 2 ] ) ; System. out. p r i n t l n ( "NxM= " + m a t r i x. l e n g t h + " x " + matrix [ 0 ]. length ) ; / / MxN=3x4 / / an exception i s thrown System. out. p r i n t l n ( " m a t r i x [ 4 ] [ 4 ] = " + m a t r i x [ 4 ] [ 4 ] ) ; c Michal Krátký Introduction to Programming (Java) 10/31

11 Branching 1/3 Statement if-else enables to control the run-time of a program. i f ( value > value2 ) r e s u l t = 1 ; else i f ( value1 < value2 ) r e s u l t = 1; else r e s u l t = 0 ; c Michal Krátký Introduction to Programming (Java) 11/31

12 Branching 2/3 We can use a prescript without blocks, however, the program is less readable and the insertion of new statements is more complicated. i f ( value > value2 ) r e s u l t = 1 ; else i f ( value < value2 ) r e s u l t = 1; else r e s u l t = 0 ; // you must insert braces and the new statement i f ( value > value2 ) r e s u l t = 1 ; i ++; else... c Michal Krátký Introduction to Programming (Java) 12/31

13 Branching 3/3 The condition is a boolean expression. Condition operators (&& and ) enables the quick evaluation compare to & and boollean operators. boolean f l a g = false ; i n t k = 0 ; i f ( f l a g && ++ k > 0 ) / / k = 0... c Michal Krátký Introduction to Programming (Java) 13/31

14 Cycles Introduction to Programming (Java) 3/12 Java includes 3 kinds of cycles. are repeated since the control condition is true. for with the fixed number of iterations while with a condition in the cycle s start do-while with a condition in the cycles s end c Michal Krátký Introduction to Programming (Java) 14/31

15 Cycles Introduction to Programming (Java) 3/12 i n t i = 0 ; while (++ i < 2 ) System. out. p r i n t l n ( " i : " + i ) ; / / Output : 1 / / i n t i = 0 ; do System. out. p r i n t l n ( " i : " + i ) ; / / Output : 0, 1 while (++ i < 2 ) ; / / for ( i n t i = 0 ; i < 2 ; i + + ) / / the same as ++ i System. out. p r i n t l n ( " i : " + i ) ; / / Output : 0, 1 c Michal Krátký Introduction to Programming (Java) 15/31

16 Cycles, Appropriate Inscription while ( i < 2 j ) i + + ; / / i n a p p r o p r i a t e i n s c r i p t i o n while ( i < 2 j ) i + + ; / / i n a p p r o p r i a t e ( o f t e n used ) i n s c r i p t i o n while ( i < 2 j ) i + + ; / / a p p r o p r i a t e i n s c r i p t i o n c Michal Krátký Introduction to Programming (Java) 16/31

17 Cycles Introduction to Programming (Java) 3/12 i n t i = 0 ; boolean f l a g = true ; while ( f l a g ) System. out. p r i n t l n ( " i : " + i ) ; / / Output :0,1,2,3 i ++; f l a g = ( i < = 3 ) ; / / i = 0 ; while ( i <= 3) System. out. p r i n t l n ( " i : " + i ) ; / / Output :0,1,2,3 i ++; c Michal Krátký Introduction to Programming (Java) 17/31

18 Cycles,, Example 1/2 f i n a l i n t size = 3 1 ; i n t arraya [ ] = new i n t [ s ize ] ; i n t arrayb [ ] = arraya ; for ( i n t i = 0 ; i < arraya. l e n g t h ; i ++) arraya [ i ] = 1 < < i ; / / the m u l t i p l i c a t i o n by 2 for ( i n t i = 0 ; i < arrayb. l e n g t h ; i ++) System. out. p r i n t l n ( i + " : " + arrayb [ i ] ) ; c Michal Krátký Introduction to Programming (Java) 18/31

19 Cycles,, Example 2/2 Output: 0: 1 1: 2 2: 4 3: 8 4: 16 5: 32 6: 64 7: 128 8: 256 9: : : c Michal Krátký Introduction to Programming (Java) 19/31

20 Cycles,, Example double matrix [ ] [ ] = 1. 0, 0. 0, 0. 0, 0. 0, 1. 0, 0. 0, 0. 0, 0. 0, 1. 0 ; for ( i n t i = 0 ; i < m a t r i x. l e n g t h ; i ++) for ( i n t j = 0 ; j < m a t r i x [ i ]. l e n g t h ; j ++) System. out. p r i n t l n ( " m a t rix [ " + i + " ] [ " + j + " ] = " + m a t r i x [ i ] [ j ] ) ; c Michal Krátký Introduction to Programming (Java) 20/31

21 Control of Cycles 1/2 The control of cycles is possible by break and continue statements. break finishes the cycle without an execution of the rest cycle statements continue finishes the current iteration and continues from the cycle s start c Michal Krátký Introduction to Programming (Java) 21/31

22 Control of Cycles 2/2 for ( i n t i = 0 ; ; i ) i f ( i % 2 = = 0 ) continue ; i f ( ( i + = 2 ) > = 2 0 ) break ; c Michal Krátký Introduction to Programming (Java) 22/31

23 Control of Cycles 2 1/2 In the case of nested break and continue statements, we can use labels. i n t i = 0 ; outer : while ( true ) while ( true ) i ++; i f ( i = = 1 ) break ; i f ( i = = 4 ) break outer ; c Michal Krátký Introduction to Programming (Java) 23/31

24 Control of Cycles 2 2/2 while ( true ) i ++; i f ( i = = 2 ) continue ; i f ( i = = 3 ) continue outer ; c Michal Krátký Introduction to Programming (Java) 24/31

25 switch 1/2 switch is appropriate for a test of an integer expression defining one or more values. switch ( < intexpr >) case intvalue1 :... break ; case intvalue2 : case intvalue3 :... break ;... default :... c Michal Krátký Introduction to Programming (Java) 25/31

26 switch 2/2 i n t state, i ;... switch ( s t a t e ) case 0 : i = 0 ; break ; case 1 : case 2 : i ++; break ; default : i ; c Michal Krátký Introduction to Programming (Java) 26/31

27 Example 3.1 1/3 public class Example0301 public s t a t i c void main ( S t r i n g [ ] args ) S t r i n g s t r = " This i s a s t r i n g " ; char ch = t ; i n t number = 0 ; for ( i n t i = 0 ; i < s t r. l e n g th ( ) ; i ++) i f ( s t r. charat ( i ) = = ch ) number ++; c Michal Krátký Introduction to Programming (Java) 27/31

28 Example 3.1 2/3 switch ( number ) case 0 : System. out. p r i n t ( "No Occurrence " ) ; break ; default : System. out. p r i n t ( " The Number of Occurrences : + number ) ; break ; System. out. p r i n t l n ( ", of the character " + ch + " i n the s t r i n g " + s t r + " " ) ; c Michal Krátký Introduction to Programming (Java) 28/31

29 Example 3.1 3/3 Output: The Number of Occurrences: 1, of the character t in the string This is a string c Michal Krátký Introduction to Programming (Java) 29/31

30 Example 3.2 1/2 The computation of sin for an angle in 0, 2π in the step 0.1. f i n a l double step = 0. 1 ; f i n a l double maxangle = ; f i n a l double maxx = Math. PI 2 ; i n t i = 0 ; for ( double x = 0. 0 ; x <= maxx ; x + = step ) double deg = ( x / Math. PI ) maxangle ; double sinvalue = Math. s i n ( x ) ; System. out. p r i n t l n ((++ i ) + ". Angle : " + x + " ( " + deg + " ), s i n ( ) = " + sinvalue ) ; c Michal Krátký Introduction to Programming (Java) 30/31

31 Example 3.2 2/2 Output: 1. Angle: 0.0 (0.0), sin()= Angle: 0.1 ( ), sin()= Angle: 0.2 ( ), sin()= Angle: 0.3 ( ), sin()= Angle: 0.4 ( ), sin()= Angle: 0.5 ( ), sin()= Angle: 0.6 ( ), sin()= Angle: ( ), sin()= c Michal Krátký Introduction to Programming (Java) 31/31

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow

More information

1. Write a program to calculate distance traveled by light

1. Write a program to calculate distance traveled by light G. H. R a i s o n i C o l l e g e O f E n g i n e e r i n g D i g d o h H i l l s, H i n g n a R o a d, N a g p u r D e p a r t m e n t O f C o m p u t e r S c i e n c e & E n g g P r a c t i c a l M a

More information

Lecture 14: Nov. 11 & 13

Lecture 14: Nov. 11 & 13 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Running Time Evaluation

Running Time Evaluation Running Time Evaluation Quadratic Vs. Linear Time Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 19 1 Running time 2 Examples 3 Big-Oh, Big-Omega, and Big-Theta Tools 4 Time

More information

Elementary Sorts 1 / 18

Elementary Sorts 1 / 18 Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the

More information

Übung Informatik I - Programmierung - Blatt 7

Übung Informatik I - Programmierung - Blatt 7 RHEINISCH- WESTFÄLISCHE TECHNISCHE HOCHSCHULE AACHEN LEHR- UND FORSCHUNGSGEBIET INFORMATIK II RWTH Aachen D-52056 Aachen GERMANY http://programmierung.informatik.rwth-aachen.de LuFG Informatik II Prof.

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

CMSC 132, Object-Oriented Programming II Summer Lecture 6: CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 6: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 6.1 Singly

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

CS Java. Introduction to Java. Andy Mroczkowski Department of Computer Science Drexel University

CS Java. Introduction to Java. Andy Mroczkowski Department of Computer Science Drexel University CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University February 18, 2008 / Lecture 5 Outline Course Status Course Information & Schedule

More information

CompA - Complex Analyzer

CompA - Complex Analyzer CompA - Complex Analyzer Xiping Liu(xl2639), Jianshuo Qiu(jq2253), Tianwu Wang(tw2576), Yingshuang Zheng(yz3083), Zhanpeng Su(zs2329) Septembee 25, 2017 1 Introduction The motivation for writing this language

More information

Take-home Lab 1. Arrays

Take-home Lab 1. Arrays Take-home Lab 1 Arrays Findx 2-Dimensional Array Graded! Submit by Friday 23:59 Find You are given a treasure map by your friend Map is divided into R by C cells Super Marks The Spot You need to find all

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 11:

CMSC 132, Object-Oriented Programming II Summer Lecture 11: CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 11: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 11.1 Recursion

More information

CS Exam 1 Study Guide and Practice Exam

CS Exam 1 Study Guide and Practice Exam CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................

More information

CS 163/164 - Exam 1 Study Guide and Practice Exam

CS 163/164 - Exam 1 Study Guide and Practice Exam CS 163/164 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Strings...................................................

More information

Introduction to functions

Introduction to functions Introduction to functions Comp Sci 1570 Introduction to C++ Outline 1 2 Functions A function is a reusable sequence of s designed to do a particular job. In C++, a function is a group of s that is given

More information

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10 Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays

More information

Lecture 5: Sep. 23 &25

Lecture 5: Sep. 23 &25 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 5: Sep. 23 &25 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Doubly Linked

More information

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CSE 311: Foundations of Computing. Lecture 26: Cardinality CSE 311: Foundations of Computing Lecture 26: Cardinality Cardinality and Computability Computers as we know them grew out of a desire to avoid bugs in mathematical reasoning A brief history of reasoning

More information

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching 1

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching 1 Pattern Matching a b a c a a b 1 4 3 2 Pattern Matching 1 Outline and Reading Strings ( 9.1.1) Pattern matching algorithms Brute-force algorithm ( 9.1.2) Boyer-Moore algorithm ( 9.1.3) Knuth-Morris-Pratt

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 10:

CMSC 132, Object-Oriented Programming II Summer Lecture 10: CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 10: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 10.1 RECURSION

More information

Lisp Introduction. Dr. Neil T. Dantam. Spring CSCI-498/598 RPM, Colorado School of Mines. Dantam (Mines CSCI, RPM) Lisp Spring / 88

Lisp Introduction. Dr. Neil T. Dantam. Spring CSCI-498/598 RPM, Colorado School of Mines. Dantam (Mines CSCI, RPM) Lisp Spring / 88 Lisp Introduction Dr. Neil T. Dantam CSCI-498/598 RPM, Colorado School of Mines Spring 28 Dantam (Mines CSCI, RPM) Lisp Spring 28 / 88 Outline Lisp Common Lisp by Example Implementation Details Typing

More information

Lecture 5: Jun. 10, 2015

Lecture 5: Jun. 10, 2015 CMSC 132, Object-Oriented Programming II Summer 2015 Lecturer: Anwar Mamat Lecture 5: Jun. 10, 2015 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor.

More information

Class versus Instance (Section 5.1)

Class versus Instance (Section 5.1) Class versus Instance (Section 5.1) Hsuan-Tien Lin Department of CSIE, NTU OOP Class, March 22-23, 2010 H.-T. Lin (NTU CSIE) Class versus Instance OOP 03/22-23/2010 0 / 16 Static Variables (1/2) 1 class

More information

Design of Mutant Operators for the AspectJ Language. Fabiano Cutigi Ferrari. Awais Rashid. José Carlos Maldonado

Design of Mutant Operators for the AspectJ Language. Fabiano Cutigi Ferrari. Awais Rashid. José Carlos Maldonado Design of Mutant Operators for the AspectJ Language Technical Report Version 1.0 December/2011 Fabiano Cutigi Ferrari Computing Department Federal University of São Carlos (UFSCar) São Carlos Brazil fabiano@dc.ufscar.br

More information

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching Goodrich, Tamassia

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching Goodrich, Tamassia Pattern Matching a b a c a a b 1 4 3 2 Pattern Matching 1 Brute-Force Pattern Matching ( 11.2.1) The brute-force pattern matching algorithm compares the pattern P with the text T for each possible shift

More information

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course. C PROGRAMMING 1 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2 LITTERATURE 3. 1 FOR C-PROGRAMMING The C Programming Language (Kernighan and

More information

Constructors - Cont. must be distinguished by the number or type of their arguments.

Constructors - Cont. must be distinguished by the number or type of their arguments. Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments.

More information

Thomas Jefferson Invitational Open in Informatics

Thomas Jefferson Invitational Open in Informatics Thomas Jefferson Invitational Open in Informatics Sample Problems (With Solutions) Version 2.01.1 By programmers, For programmers Preface Preface Welcome to the TJ IOI Sample Problems document. Here, you

More information

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010 More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p

More information

CS 61B Asymptotic Analysis Fall 2017

CS 61B Asymptotic Analysis Fall 2017 CS 61B Asymptotic Analysis Fall 2017 1 More Running Time Give the worst case and best case running time in Θ( ) notation in terms of M and N. (a) Assume that slam() Θ(1) and returns a boolean. 1 public

More information

Binary Search Trees. Motivation

Binary Search Trees. Motivation Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying

More information

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version SDS developer guide Develop distributed and parallel applications in Java Nathanaël Cottin sds@ncottin.net http://sds.ncottin.net version 0.0.3 Copyright 2007 - Nathanaël Cottin Permission is granted to

More information

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology Tutorial Graz University of Technology March 22, 2010 Why? is: very readable easy to learn interpreted & interactive like a UNIX shell, only better object-oriented but not religious about it slower than

More information

SFWR ENG/COMP SCI 2S03 Principles of Programming

SFWR ENG/COMP SCI 2S03 Principles of Programming (Slide 1 of 78) Dr. Ridha Khedri Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on Java actually: A Comprehensive Primer in

More information

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 3 Discussion:

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 3 Discussion: German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Mohammed Abdel Megeed Introduction to Computer Programming, Spring Term 2018 Practice Assignment 3 Discussion:

More information

Programming Language Concepts, CS2104 Lecture 3

Programming Language Concepts, CS2104 Lecture 3 Programming Language Concepts, CS2104 Lecture 3 Statements, Kernel Language, Abstract Machine 31 Aug 2007 CS2104, Lecture 3 1 Reminder of last lecture Programming language definition: syntax, semantics

More information

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic

More information

Tricks of the Trade in Combinatorics and Arithmetic

Tricks of the Trade in Combinatorics and Arithmetic Tricks of the Trade in Combinatorics and Arithmetic Zachary Friggstad Programming Club Meeting Fast Exponentiation Given integers a, b with b 0, compute a b exactly. Fast Exponentiation Given integers

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Path Testing and Test Coverage. Chapter 9

Path Testing and Test Coverage. Chapter 9 Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test

More information

Java Programming. Final Examination on December 13, 2015 Fall 2015

Java Programming. Final Examination on December 13, 2015 Fall 2015 Java Programming Final Examination on December 13, 2015 Fall 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (10 points) Multiple choice questions.

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

R: A Quick Reference

R: A Quick Reference R: A Quick Reference Colorado Reed January 17, 2012 Contents 1 Basics 2 1.1 Arrays and Matrices....................... 2 1.2 Lists................................ 3 1.3 Loading Packages.........................

More information

Path Testing and Test Coverage. Chapter 9

Path Testing and Test Coverage. Chapter 9 Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test

More information

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms (2017F) Lecture4: Analysis of Algorithms Daijin Kim CSE, POSTECH dkim@postech.ac.kr Running Time Most algorithms transform input objects into output objects. The running time of an algorithm typically

More information

MiniMat: Matrix Language in OCaml LLVM

MiniMat: Matrix Language in OCaml LLVM Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................

More information

Functions in Python L435/L555. Dept. of Linguistics, Indiana University Fall Functions in Python. Functions.

Functions in Python L435/L555. Dept. of Linguistics, Indiana University Fall Functions in Python. Functions. L435/L555 Dept. of Linguistics, Indiana University Fall 2016 1 / 18 What is a function? Definition A function is something you can call (possibly with some parameters, i.e., the things in parentheses),

More information

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

Specification of Chemical Formulæ in XL with Operator Overloading

Specification of Chemical Formulæ in XL with Operator Overloading Formulæ in with Specification of Formulæ in with University of Göttingen 28 February 2012 Formulæ in with Outline 1 2 3 4 5 Formulæ in with ultimately we want to specify reactions like 2H 2 + O 2 k f kb

More information

DARN: A Matrix Manipulation Language

DARN: A Matrix Manipulation Language DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4

More information

CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices

CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices This lab consists of exercises on real-valued vectors and matrices. Most of the exercises will required pencil and paper. Put

More information

CS325: Analysis of Algorithms, Fall Final Exam

CS325: Analysis of Algorithms, Fall Final Exam CS: Analysis of Algorithms, Fall 0 Final Exam I don t know policy: you may write I don t know and nothing else to answer a question and receive percent of the total points for that problem whereas a completely

More information

Lecture 4: Stacks and Queues

Lecture 4: Stacks and Queues Reading materials Goodrich, Tamassia, Goldwasser (6th), chapter 6 OpenDSA (https://opendsa-server.cs.vt.edu/odsa/books/everything/html/): chapter 9.8-13 Contents 1 Stacks ADT 2 1.1 Example: CharStack ADT

More information

Lecture 20: Analysis of Algorithms

Lecture 20: Analysis of Algorithms Overview Lecture 20: Analysis of Algorithms Which algorithm should I choose for a particular application?! Ex: symbol table. (linked list, hash table, red-black tree,... )! Ex: sorting. (insertion sort,

More information

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name: CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T F : If a child overrides its parent

More information

10: Analysis of Algorithms

10: Analysis of Algorithms Overview 10: Analysis of Algorithms Which algorithm should I choose for a particular application? Ex: symbol table. (linked list, hash table, red-black tree,... ) Ex: sorting. (insertion sort, quicksort,

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

Section Summary. Sequences. Recurrence Relations. Summations Special Integer Sequences (optional)

Section Summary. Sequences. Recurrence Relations. Summations Special Integer Sequences (optional) Section 2.4 Section Summary Sequences. o Examples: Geometric Progression, Arithmetic Progression Recurrence Relations o Example: Fibonacci Sequence Summations Special Integer Sequences (optional) Sequences

More information

Programming Languages

Programming Languages CSE 230: Winter 2010 Principles of Programming Languages Lecture 10: Programming in λ-calculusc l l Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2

More information

Analysis of Algorithms

Analysis of Algorithms Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Analysis of Algorithms Input Algorithm Analysis

More information

Beyond Bird s Nested Arrays III

Beyond Bird s Nested Arrays III Beyond Bird s Nested Arrays III Using the single-argument theta function for expressing ordinals (e.g. θ(1) = ε 0, θ(2) = ζ 0, θ(ω) = Γ 0 ), the most significant separators introduced so far are:- [1]

More information

Designing 1-tape Deterministic Turing Machines

Designing 1-tape Deterministic Turing Machines MCS-265: The Theory of Computation Handout #T1 San Skulrattanakulchai Gustavus Adolphus College April 5, 2011 Designing 1-tape Deterministic Turing Machines A TM corresponds to a computer program. We will

More information

1 Java Night Countdown (30%)

1 Java Night Countdown (30%) Midterm Examination Problem Sheet TIME: 04/18/2009, 19:00 21:00 This is a open-textbook exam. You can use the Absolute Java textbook as your reference during the exam. Any other references are not allowed.

More information

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 5 Discussion: power(m,n) = m n

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 5 Discussion: power(m,n) = m n German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Mohammed Abdel Megeed Introduction to Computer Programming, Spring Term 2018 Practice Assignment 5 Discussion:

More information

Algorithms and Data S tructures Structures Complexity Complexit of Algorithms Ulf Leser

Algorithms and Data S tructures Structures Complexity Complexit of Algorithms Ulf Leser Algorithms and Data Structures Complexity of Algorithms Ulf Leser Content of this Lecture Efficiency of Algorithms Machine Model Complexity Examples Multiplication of two binary numbers (unit cost?) Exact

More information

Data Dependences and Parallelization. Stanford University CS243 Winter 2006 Wei Li 1

Data Dependences and Parallelization. Stanford University CS243 Winter 2006 Wei Li 1 Data Dependences and Parallelization Wei Li 1 Agenda Introduction Single Loop Nested Loops Data Dependence Analysis 2 Motivation DOALL loops: loops whose iterations can execute in parallel for i = 11,

More information

More on Methods and Encapsulation

More on Methods and Encapsulation More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local

More information

Running Time. Overview. Case Study: Sorting. Sorting problem: Analysis of algorithms: framework for comparing algorithms and predicting performance.

Running Time. Overview. Case Study: Sorting. Sorting problem: Analysis of algorithms: framework for comparing algorithms and predicting performance. Running Time Analysis of Algorithms As soon as an Analytic Engine exists, it will necessarily guide the future course of the science. Whenever any result is sought by its aid, the question will arise -

More information

Tou has been released!

Tou has been released! Tou has been released! Shoot- em-up, heavy use of collision detection Much more open-ended than previous projects Easier than previous projects if you work smart Should help those of you combating the

More information

CSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic

CSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equal if they have the same elements A = B x (x A x B) A is a subset of B if every

More information

LAB 1: MATLAB - Introduction to Programming. Objective:

LAB 1: MATLAB - Introduction to Programming. Objective: LAB 1: MATLAB - Introduction to Programming Objective: The objective of this laboratory is to review how to use MATLAB as a programming tool and to review a classic analytical solution to a steady-state

More information

Unit 8: Sequ. ential Circuits

Unit 8: Sequ. ential Circuits CPSC 121: Models of Computation Unit 8: Sequ ential Circuits Based on slides by Patrice Be lleville and Steve Wolfman Pre-Class Learning Goals By the start of class, you s hould be able to Trace the operation

More information

Automatic Code Generation

Automatic Code Generation Automatic Code Generation Several tools allow automatic code generation from high-level control models: Simulink Real-Time Workshop (Mathworks) Scicos (Inria) Lustre/SCADE (Verimag/Esterel-Tecnologies)

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 12

CMSC 132, Object-Oriented Programming II Summer Lecture 12 CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees

More information

CS1150 Principles of Computer Science Loops

CS1150 Principles of Computer Science Loops CS1150 Principles f Cmputer Science Lps Yanyan Zhuang Department f Cmputer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Clrad Springs Review Blean variables Assume x=3, y=1, true r false?!(x3

More information

Searching, mainly via Hash tables

Searching, mainly via Hash tables Data structures and algorithms Part 11 Searching, mainly via Hash tables Petr Felkel 26.1.2007 Topics Searching Hashing Hash function Resolving collisions Hashing with chaining Open addressing Linear Probing

More information

A High Level Programming Language for Quantum Computing

A High Level Programming Language for Quantum Computing QUARK QUantum Analysis and Realization Kit A High Level Programming Language for Quantum Computing Team In lexicographical order: Name UNI Role Daria Jung djj2115 Verification and Validation Jamis Johnson

More information

DNHI Homework 2 Solutions Recursion

DNHI Homework 2 Solutions Recursion Solutions Recursion Problem 1 Part A Write an iterative method that computes a value of x n for a positive integer n and a real number x. The return value of -1 indicates an error condition. 1 public static

More information

Mathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)?

Mathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)? How does discrete math help us Helps create a solution (program) Helps analyze a program How does discrete math help (CS160)? Helps create a solution (program) q Logic helps you understand conditionals

More information

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1 Course Announcements Stars is due tomorrow. Stars grades should be out by next Monday. Javascript lab out today. How you make interactive webby GUIs. Today we re going to cover a bit of a hodge podge.

More information

Top Down Design. Gunnar Gotshalks 03-1

Top Down Design. Gunnar Gotshalks 03-1 Top Down Design 03-1 Top Down Description Top down is also known as step wise refinement and functional decomposition Given an operation, there are only the following three choices for refinement» Sequence

More information

CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community

CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Python basics (a) The programming language Python (circle the best answer): i. is primarily

More information

Topic 17. Analysis of Algorithms

Topic 17. Analysis of Algorithms Topic 17 Analysis of Algorithms Analysis of Algorithms- Review Efficiency of an algorithm can be measured in terms of : Time complexity: a measure of the amount of time required to execute an algorithm

More information

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010 Announcements CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010 Project 1 posted Section materials on using Eclipse will be very useful if you have never used

More information

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

COMP 515: Advanced Compilation for Vector and Parallel Processors. Vivek Sarkar Department of Computer Science Rice University

COMP 515: Advanced Compilation for Vector and Parallel Processors. Vivek Sarkar Department of Computer Science Rice University COMP 515: Advanced Compilation for Vector and Parallel Processors Vivek Sarkar Department of Computer Science Rice University vsarkar@rice.edu COMP 515 Lecture 10 10 February 2009 Announcement Feb 17 th

More information

Hoare Calculus and Predicate Transformers

Hoare Calculus and Predicate Transformers Hoare Calculus and Predicate Transformers Wolfgang Schreiner Wolfgang.Schreiner@risc.uni-linz.ac.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria http://www.risc.uni-linz.ac.at

More information

Data Structures and Algorithms Chapter 2

Data Structures and Algorithms Chapter 2 1 Data Structures and Algorithms Chapter 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

II. BASIC THEORIES A. System of Rigid Body I. INTRODUCTION. B. Decrease and Conquer

II. BASIC THEORIES A. System of Rigid Body I. INTRODUCTION. B. Decrease and Conquer Decrease & Conquer Algorithm to Determine the Center of Mass of a Rigid Body Composition Destra Bintang Perkasa 13511057 Program Studi Teknik Informatika Sekolah Teknik Elektro dan Informatika Institut

More information

COMS 6100 Class Notes

COMS 6100 Class Notes COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Introduction

More information

Ch 01. Analysis of Algorithms

Ch 01. Analysis of Algorithms Ch 01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T.

More information

Extensibility Patterns: Extension Access

Extensibility Patterns: Extension Access Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science

More information

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or

More information

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm CS 7B - Fall 2017 - Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm Write your responses to following questions on separate paper. Use complete sentences where appropriate and write out code

More information

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent

More information