Algorithms and Basics of Programming Tasks

Similar documents
Introduction to programming Tasks

Algorithms and Basics of Programming

PROGRAMMING IN C AND C++:

Unit 2: Accentuate the Negative Name:

Unit 3. Operators. School of Science and Technology INTRODUCTION

1 Elementary number theory

Finite Math - J-term Homework. Section Inverse of a Square Matrix

Examples for Algorithm,Pseduocode,Flowchart

RtI 7. Curriculum (219 topics additional topics)

Algebra 1 Review. Properties of Real Numbers. Algebraic Expressions

TTUSD Math Essential Standards Matrix 4/16/10 NUMBER SENSE

OKLAHOMA SCHOOL TESTING PROGRAM TEST BLUEPRINT MATHEMATICS GRADE 3

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus)

Unit 3: Multiplication and Division Reference Guide pages x 7 = 392 factors: 56, 7 product 392

EXAMPLE 1. Change each of the following fractions into decimals.

1.2 Round-off Errors and Computer Arithmetic

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Chapter 9: Surface Area and Volume CHAPTER 9: ANGLES AND PYTHAGOREAN THEOREM. Date: Lesson: Learning Log Title:

FOURTH GRADE Mathematics Standards for the Archdiocese of Detroit

Chapter 6 Primitive types

Operators and Expressions:

Prepared by: Shraddha Modi

Mathematics. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

UNIT- 3 Introduction to C++

More Programming Constructs -- Introduction

UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS

CS 97SI: INTRODUCTION TO PROGRAMMING CONTESTS. Jaehyun Park

n Group of statements that are executed repeatedly while some condition remains true

MS RtI Tier 3. Curriculum (107 topics + 91 additional topics)

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

Number Sense and Operations Curriculum Framework Learning Standard

12/11/ The TOY Machine II. Data Representation. What We've Learned About TOY. What We Do Today. Adding and Subtracting Binary Numbers

How to Do Word Problems. Study of Integers

Course Outlines. Elementary Mathematics (Grades K-5) Kids and Numbers (Recommended for K-1 students)

Topic 10 Part 2 [474 marks]

5. The TOY Machine II

Loki s Practice Sets for PUBP555: Math Camp Spring 2014

Lecture 19: Functions, Types and Data Structures in Haskell

1 Elementary number theory

Geometry Cheat Sheet

Visual Basic for Applications

no triangle can have more than one right angle or obtuse angle.

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Odd-Numbered Answers to Exercise Set 1.1: Numbers

How to Do Word Problems. Building the Foundation

MCAS/DCCAS Mathematics Correlation Chart Grade 6

YEAR 7 MATHS SCHEMES OF WORK

COMMUNITY UNIT SCHOOL DISTRICT 200

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Math Lesson Plan 6th Grade Curriculum Total Activities: 302

Grades 7 & 8 Pre-Algebra/Course 3,

6th Grade Arithmetic (with QuickTables)

Flow Chart. The diagrammatic representation shows a solution to a given problem.

Operations and Properties

Math Curriculum Kindergarten

Section A Arithmetic ( 5) Exercise A

Mathematics LV 4 (with QuickTables)

UNC Charlotte 2010 Comprehensive


Texas High School Geometry

Section 1.2 Fractions

Montana City School GRADE 5

2.6 BOOLEAN FUNCTIONS

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

TOPICS. Integers Properties of addition and. Rational Numbers Need for rational numbers. Exponents or Powers Introduction to Exponents or

Integers and Mathematical Induction

Mathematics 700 Unit Lesson Title Lesson Objectives 1 - INTEGERS Represent positive and negative values. Locate integers on the number line.

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Indirect measure the measurement of an object through the known measure of another object.

Intermediate Mathematics League of Eastern Massachusetts

Summary of Course Coverage

Dept. of CSE, IIT KGP

EXPLORE MATHEMATICS TEST

5 th Grade Math Curriculum

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

SNS COLLEGE OF ENGINEERING,

Compiler Construction

Math Curriculum Guide PK-8

Assignment: 1. (Unit-1 Flowchart and Algorithm)

Los Angeles Unified School District. Mathematics Grade 6

ABE Math TABE Modules 1-10

Appendix 14C: TIMSS 2015 Eighth Grade Mathematics Item Descriptions Developed During the TIMSS 2015 Benchmarking

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Name Date Grade Mathematics K

Mathematics LV 5 (with QuickTables)

Smarter Balanced Vocabulary (from the SBAC test/item specifications)

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Iron County Schools. Yes! Less than 90 No! 90 No! More than 90. angle: an angle is made where two straight lines cross or meet each other at a point.

PCTI Geometry. Summer Packet

CSc 372 Comparative Programming Languages

Conditionals !

Alignments to SuccessMaker. Providing rigorous intervention for K-8 learners with unparalleled precision

CSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona

Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd

TABLE 2: Mathematics College Readiness Standards for Score Range 13 15

Medium Term Plan Year 6: Autumn Term

Gateway Regional School District VERTICAL ALIGNMENT OF MATHEMATICS STANDARDS Grades 5-8

College Readiness (597 topics) Course Name: College Prep Math Spring 2014 Course Code: ARTD4-3N6XJ

APS Sixth Grade Math District Benchmark Assessment NM Math Standards Alignment

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Transcription:

Algorithms and Basics of Programming Tasks Imre Varga University of Debrecen, Faculty of Informatics For internal use only! 01 September 2017

Time Learn what does time mean. Learn to use watch/clock. Be on time. Arrive to the lesson in correct time. When does this class start? A B D C E F 2

Number systems: conversion What is the equivalent value? 986 10 =? 2 3.14 10 =? 2 1011011.01 2 =? 10 100101011010 2 =? 16 1BE 16 =? 2 986 10 =? 16 135 16 =? 10 Sort the following numbers into increasing order: 100 2, 100 16, 100 10, 10000000000 2, 1000 10, 3FF 16, 150 8 3

Number systems: arithmetic What is the result of the following operations: 10010101 2 + 1110100 2 =? 1011 2 + 101 2 + 1001 2 +1010 2 =? 100101.01 2 + 11.01001 2 =? 10101101 2 1010110 2 =? 1001010 2 * 101 2 =? 10111010110 2 / 110 2 =? 1101 =? 4

Algorithm: using public coin phone Start pick up receiver put in coins dial the number talk put down receiver End Problems: Not complete Ambiguous Modification: Generalizing Extending Foolproofing Completing Create a more detailed algorithm. 5

Using public coin phone wait Start pick up receiver put in coins is line? local call? talk dial area code continue? dial local number enough money? engaged? wait is more coin? answer? put in coins put down get coins back put down again? End 6

Flowchart exercises and examples What is the output, if the user gives a=3, b=9, c=5? What is the output, if the user gives a=5, b=2, c=7? Start in: a, b, c a>c a>b b>c R=a R=b R=c What does this algorithm do? out: R End 7

Flowchart exercises and examples How do the values of x, yand schange during the process, if x=5 and y=4? What is the output in this case? How many times will the condition evaluated? What does this algorithm do? How can you modify it to calculate the product of xand y? out: s End Start in: x, y s=x y>0 s=s+1 y=y-1 8

Flowchart exercises and examples How do the values of xand ychange during the process, if the input is 10? What is the output, if the input is 60? What does this algorithm do? Is it work, if x=1? If the input is 24, how many iterations will be executed? How can it faster? Legend: % is modulo operation out: y x=x/y x%y=0 Start in: x y=2 y<=x y=y+1 End 9

Flowchart exercises and examples This flowchart describes the algorithm of calculation of the remain of a division. Complete it. Start a<=b a<0 b<=0 a=a-b in: a, b out: error out: a End 10

Flowchart exercises Create flowcharts to the following problems Leap year Raising to power Calculating factorial Solving first degree equation Fibonacci sequence 3 values into increasing order Sum of all integers between MINand MAX Conversion of decimal number to binary Incrementation of binary numbers Addition of binary numbers Searching in ordered binary tree 11

Pseudocode exercises input a if a<0 then b=-1*a else b=a endif output b Whatistheoutput ifa=10? Whatistheoutput ifa=-4? What does the algorithm do? What does this algorithm do? input a if a<0 then a=-1*a endif output a 12

Pseudocode exercises input a input b Do the pseudocode and the flowchart describe the same algorithm? c=a if b>0 then Start b=b-1 c=c-1 in: a, b else c=a output c endif b>0 out: c b=b-1 End c=c-1 13

Pseudocode exercises input a input b c=a while b>0 do b=b-1 c=c-1 enddo output c How do the values ofa,band c change during the process, ifa=7andb=3? Whatistheoutput inthiscase? How many times will the condition evaluated? What does this algorithm do? Convert it to flowchart. 14

Pseudocode exercises input N R=0 while N>0 do R=R*10+N%10 N=[N/10] enddo output R How do the values of N and R change during the process, if N=73251 initially? Whatistheoutput inthiscase? What does this algorithm do? Legend: %: modulo operation (reminder after division) [ ]: integer part (ignore fractional part) 15

Pseudocode exercises input N input B R=0 P=1 while N<>0 do R=R+(N%B)*P P=P*10 N=[N/B] enddo output R Whatistheoutput, ifn=15, B=2? Whatistheoutput, ifn=16, B=2? Whatistheoutput, ifn=10, B=2? Whatistheoutput, ifn=5, B=2? Whatistheoutput, ifn=30, B=3? Whatistheoutput, ifn=20, B=3? Whatistheoutput, ifn=64, B=8? What does this algorithm do? 16

Pseudocode exercises input A input B while B>0 do C=B B=A%B A=C enddo output A HowdothevaluesofA,BandC change during the process, if A=24 and B=18 initially? Whatistheoutput inthiscase? TryitwithA=30andB=105. TryitwithA=165 andb=48. What does this algorithm do? (Euclidean algorithm: Greatest Common Divisor) 17

Pseudocode exercises input A input B while A<>B do if A>B then A=A-B else B=B-A endif enddo output B HowdothevaluesofA,BandC change during the process, if A=24 and B=18 initially? Whatistheoutput inthiscase? TryitwithA=30andB=105. TryitwithA=165 andb=48. What does this algorithm do? Create a flowchart for this algorithm. 18

Pseudocode exercises Describe this flowchart by pseudocode. Start in: x x=0 y=0 y=+1 x>0 y=-1 out: y End 19

Pseudocode exercises Describe this flowchart by pseudocode. What does it do? How can you modify it to get the result quicker? Start in: x s=0 out: s x>=0 s=s+x End x=x-1 20

Pseudocode exercises Describe this flowchart by pseudocode! Start in: x x=0 out: x x>0 End x=x-1 x=x+1 21

Pseudocode exercises Verbal represented algorithm: 1. Get a number. 2. Check that it is larger then one or not. 3. If it is larger, subtract two and continue with Step 2. 4. Otherwise check it zero or not. 5. If it is zero, write E. 6. Else write O. Write this algorithm with flowchart. Write this algorithm in pseudocode. 22

Pseudocode exercises Write the following algorithms with pseudocode Absolute value Sum of numbers from 10 to 20 Raising to power Solution of first degree equation Calculating factorial Prime or not Prime factorization f(i)<100 elements of sequence: f(1)=1; f(i)=f(i-1)+i Fibonacci sequence 23

Pseudocode exercises Write the following algorithms with pseudocode Leap year Day of year Triangle inequality Equilateral triangle Isosceles triangle a a b Maximum of given 3 numbers Right-angled triangle (Pythagorean theorem) Distance of 2 planar points 24

Pseudocode exercises Average of an array Finding a value in (ordered) list with guard Minimum/maximum search Finding the place of maximum/minimum Replacement of two values Selection sort Insertion sort Bubble sort 25

Subroutine exercises function CHANGE ( a ) return 1-a end function What does this algorithm do? What is the role of the function? input Max i=0 j=0 while j<=max do i = CHANGE (i) j=j+i output j enddo 26

Subroutine exercises procedure NUMS ( N ) while N>0 do output N N=N-1 enddo output NEWLINE end function NUMS (3) NUMS (4) NUMS (5) NUMS (4) NUMS (3) Legend What is the output of the algorithm? NEWLINE: is special thing to create a new line (line feed + carriage return) on the output 27

Subroutine exercises Write an algorithm in pseudocode containing a function to determine average of two values (given as parameters). Write an algorithm in pseudocode containing a procedure to write the NxN multiplication table. For example if N=4: 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 28

Testing strategy Seating order: Chairs are placed as a square grid in a rectangular area. Each row contains W chairs. How many rows we need minimum for M people? M=10 W=4 input M input W R = M/W output R R=3 Create a testing strategy to the following algorithm. Which values of M and W are acceptable? (When the algorithm gives expected output?) 29

Testing strategy Seating order: Chairs are placed as a suqare grid in a rectangular area. Each row contains W chairs. How many rows we need minimum for M people? M=10 R=3 W=4 Create a testing strategy to the following algorithm. input M input W if W>0 then if M%W=0 then R = M/W else R = [M/W]+1 endif output R endif 30

Testing strategy Number system conversion Create a testing strategy to the following algorithm. Which values of N and B are acceptable? (When the algorithm gives expected output?) input N input B R=0 P=1 while N<>0 do R=R+(N%B)*P P=P*10 N=[N/B] enddo output R 31

Syntax and semantics Find syntactic and semantic errors of the following algorithm written in pseudocode to determine the not negative integer (E) power of the base (B). input B R=0 wihle E>=0 R=R*B E-1=E endo output R 32

Data representation Represent the (human) population of the Earth with 32-bit fixed-point representation. Represent the -1 value in 32-bit fixed-point form. Which 4 bytes long bit series means the fixed-point representation of 15908? Which 4 bytes long bit series means the fixed-point representation of -666? What is the meaning(s) of the following bit series in case of fixed-point representation? 10000000 00000000 00000010 01001001 33

Data representation Which bitseries means greater value in case of signed/unsigned fixed-point representation? 00000000 00000000 00000000 10000000 11111111 11111111 11111111 00000000 Give a 32 bit long series which means 0.0 by the standard floating point representation method. What is the meaning of the following bit series in case of floating point representation? 11000000 11000000 00010000 00000000 34

Expressions What is the value of the following infix expression? 9+2*6/3>8-7 What is the value of the following infix expression? 2>3&&3*5-6/2>=11%2 What is the value of the following prefix expressions? * + 1 2 9 6 + 1 - * 2 13 / 25 5 What is the value of the following prefix expressions and convert it into infix form? 30 2 15 4 6 + - * / 1 2 13 * 25 5 / - + 35

Pythonprogramming language Find examples in this Pythoncode part for the different occurrence of the following concepts. Keyword Comment Identifier Constant Variable Operator Expression Instruction # some calculation Sum=0 for i in range(n): Sum+=i if(sum==0): print( Total +Sum) else: z=10%2+n/n+cos(90) #return z 36

Integrated Development Environment Open and trya real IDE. Frequently used IDEs: Code::Blocks Dev-C++ NetBeans Eclipse MS Visual Studio Jbuilder MPLAB PyCharm 37