PROBLEM SOLVING TECHNIQUES SECTION - A. 1. Answer any ten of the following

Similar documents
Unit 1: Introduction to Algorithms

Assertions & Verification & Example Loop Invariants Example Exam Questions

Assertions & Verification Example Exam Questions

09/28/2015. Problem Rearrange the elements in an array so that they appear in reverse order.

Algorithms 4. Odd or even Algorithm 5. Greatest among three numbers Algorithm 6. Simple Calculator Algorithm

Module 2: Classical Algorithm Design Techniques

Loops / Repetition Statements

MAT 243 Test 2 SOLUTIONS, FORM A

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Lab Manual. Program Design and File Structures (P): IT-219

Subject: Computer Science

Prof. Sushant S Sundikar 1

Bulgarian Math Olympiads with a Challenge Twist

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

COP 4516: Math for Programming Contest Notes

Gujarat University M. Sc. Computer Science [S. F.] Semester-1 Syllabus Gujarat Arts & Science College, Ahmedabad.

PROGRAMMING IN C AND C++:

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Number Theory Open, Round 1 Test #101

Question Bank Subject: Advanced Data Structures Class: SE Computer

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Interactive Math Glossary Terms and Definitions

WHOLE NUMBER AND DECIMAL OPERATIONS

COE428 Lecture Notes Week 1 (Week of January 9, 2017)

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

Foundation. Scheme of Work. Year 9. September 2016 to July 2017

COMPUTER SCIENCE TRIPOS

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Computers Programming Course 6. Iulian Năstac

Questions Bank. 14) State any four advantages of using flow-chart

3 The L oop Control Structure

Two Approaches to Algorithms An Example (1) Iteration (2) Recursion

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

UCT Algorithm Circle: Number Theory

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

UNIT 5. Sorting and Hashing

YEAR 8 SCHEME OF WORK

CSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions. User Defined Functions

Answers. 1. (A) Attempt any five : 20 Marks

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols.

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

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

Alphanumeric Divisibility

INSTITUTE OF AERONAUTICAL ENGINEERING

Hegarty Maths Clip Numbers List

VARIABLE, OPERATOR AND EXPRESSION [SET 1]

! Addition! Multiplication! Bigger Example - RSA cryptography

KS3 - Year 8 & 9 Course Outline: Mathematics

Birkdale High School - Higher Scheme of Work

UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS

VALLIAMMAI ENGINEERING COLLEGE

Data Structure and Algorithm Midterm Reference Solution TA

Lab 1: Cipher Fundamentals

COMP3121/3821/9101/ s1 Assignment 1

SECTION 5.1. Sequences

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

Problem Solving (Computing) Array and Pointer

Lab 1: Cipher Fundamentals

Component 02. Algorithms and programming. Sorting Algorithms and Searching Algorithms. Matthew Robinson

If a b or a c, then a bc If a b and b c, then a c Every positive integer n > 1 can be written uniquely as n = p 1 k1 p 2 k2 p 3 k3 p 4 k4 p s

AXIOMS FOR THE INTEGERS

PROGRAM DESIGN TOOLS. Algorithms, Flow Charts, Pseudo codes and Decision Tables. Designed by Parul Khurana, LIECA.

Structured Program Development in C

Hash Functions. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK

Mathematics Background

COMPUTER ARITHMETIC (Part 1)

q To develop recursive methods for recursive mathematical functions ( ).

( ) n 3. n 2 ( ) D. Ο

q To develop recursive methods for recursive mathematical functions ( ).

TABLES AND HASHING. Chapter 13

Number Algebra Geometry and Measure Statistics. Aspect 1 Aspect 2 Aspect 3 Aspect 4 Work out the upper. Calculate area of and lower bounds of

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

Invariants and Algorithms

A Survey of Mathematics with Applications 8 th Edition, 2009

CS 2412 Data Structures. Chapter 10 Sorting and Searching

Montana City School GRADE 5

Engineering program development. Edited by Péter Vass

PURPLE COMET MATH MEET April 2011 HIGH SCHOOL - PROBLEMS. The ratio of 3 to the positive number n is the same as the ratio of n to 192. Find n.

11.3 Function Prototypes

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS

Midterm Exam 2B Answer key

CS Data Structures and Algorithm Analysis

Chapter 3 Structured Program Development

Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

Recursive Functions. Biostatistics 615 Lecture 5

Algorithm classification

C- PROGRAMMING (3:0:0) Sub code : CS1C01/CS2C01 CIE : 50%Marks Hrs/week : 03 SEE : 50%Marks SEE Hrs : 03 Hours Max. Marks: 100 Course Outcomes:

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

ANNA UNIVERSITY: CHENNAI B.E./B.Tech. DEGREE EXAMINATIONS, JAN Regulations First Semester (Common to All Branches )

The Ultimate Maths Vocabulary List

PITSCO Math Individualized Prescriptive Lessons (IPLs)

Transcription:

PROBLEM SOLVING TECHNIQUES SECTION - A 1. Answer any ten of the following a. Define an algorithm. An algorithm is a finite set of instructions that if followed, accomplishes a particular task. b. Define a program. A program is a set of instructions to solve a particular problem by the computer language. c. What is a verification condition (VC)? Symbolic executing enables us to transform the verification procedure into proving that the input assertion with symbolic values substituted for all input variables implies the output assertion with final symbolic values substituted for all variables. A proposition phrased in this way is referred to as a Verification Condition (VC). d. What is Fibonacci series? The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,... The next number is found by adding up the two numbers before it. e. Given a number 189 10 convert it to octal equivalent. 275 8 f. What is the error condition (fixed error) that might be used to terminate square root algorithm? 1 x 10-6 or 0.0000001 g. What are prime numbers? Write first 10 prime numbers. Prime number is a number which is not divisible by any other number other then 1 and itself. First 10 prime numbers are 2,3,5,7,11,13,17,19,23,29. h. Find the GCD of 18 and 30. 6 i. What is longest monotone subsequence? A monotone increasing subsequence is a subset of numbers which are strictly increasing from left to right. This definition does not require that the numbers be adjacent in the original set or that the longest sequence is unique. For example: j. In which applications removing duplicates from an array algorithm is used? Data Compression and text processing problems k. What is sorting? Sorting is any process of arranging items systematically l. What is hashing? Hash searching is used to index and retrieve items in a list using a shorter fixed-length value because it is faster to find the item using the shorter hashed key than to find it using the original value.

SECTION - B Answer any four of the following 2. What is a flowchart? Draw and explain various symbols used in flowchart. Flowchart can be defined as a diagrammatic representation of and algorithm. Symbol Used Geometrical Name Oval Uses Parallellogram Input Rectangle Start and Stop Output Processing and 4. Write and explain the expression and parameters used for generating random numbers using Linear Congruential Method. where the parameters a, b, m and x0 must be carefully chosen in advance according to certain criteria. The parameters a, b, and m are referred to as the multiplier, increment, and modulus respectively. All parameters should be integers greater than or equal to zero and m should be greater than x 0,a and b. Parameter x 0 : The parameter x 0 can be chosen arbitrarily within the range 0--x 0 <m. Parameter m: The value of m should e greater than or Arrows Small Circle Rhombus Hexagon Connectors Connector Decision Making Repetition or Looping equal to the length of the random sequence required. In addition it must be possible to do the computation (a*x)+b mod m without roundoff. Further requirements on a are that it should be larger than m and less than m- m, (a-1) should be a multiple of every prime dividing into m, and if m is a multiple of 4 then (a-1) should also be a multiple of 4. These conditions together with the requirements that b should relatively prime to m are needed to guarantee that the sequence has a period of m. Parameter a: The choice of a depends on the choice of m. If m is a power of 2 then a should satisfy the condition: a mod 8 = 5 If m is a power of 10, then a should be chosen such that: a mod 200 = 21 3. Write the algorithm to exchange the values of two variables. PROBLEM STATEMENT: Given two variables, a and b, exchange the values assigned to them. INPUT: a as integer, b as integer OUTPUT: new value of a must be old value of b, new value of b must be old value of a. ALGORITHM exchange(a,b) t <-- a; a <-- b; b <-- t; Paramter b: The constant b should be odd and not a multiple of 5. When a, b, and m are chosen according to the conditions outlined above a sequence of m pseudorandom numbers in the range 0 to (m-1) can be generated before the sequence begins to repeat. 5. Write the algorithm to compute nth Fibonacci number. ALGORITHM fibonacci(n) //PROBLEM STATEMENT: Algorithm to print the first n fibonacci numbers.

//INPUT: n - numbers to be generated of the series. preceding term term a - as number before the b - as number preceding c - new term // OUTPUT: fibonacci series a <-- 0; b <-- 1; i <-- 2; write (a); write (b); while i < n do return; a <-- a + b; b <-- a + b; write (a); write (b); i <-- i + 2; 6. Explain how you rearrange the elements in an array so that they appear in reverse order. The problem of reversing the order of an array of numbers appears to be completely straightforward. We start the design of this algorithm by careful examination of the array before and after it has been reversed; for example, In terms of suffixes the exchanges are : Examining the effects of these exchanges we discover that after step 3 the array is completely reversed. In setting up our algorithm we need a pair of suffixes that model this increasingdecreasing behavior. Our increasing suffix can be the variable i which is incremented by1.for our decreasing suffix we might try n-i since this decreases by 1 with each increase in i by 1.This means that when i=1 we find that n-i is equal to n- 1 rather than n. We can correct this by adding 1. So the suffix n-i-1 can be used at other end rather than using n-i. 7. Write a short note on Two way merge. Merging two or more sets of data is a task that is frequently performed in computing. It is simpler than sorting because it is possible to take advantage of the partial order in the data. Examination of two ordered arrays should help to discover the essential of a suitable merging procedure. Consider the two arrays: A little though reveals that the merged result should be as indicated below: What we observe from our diagram is that the first element ends up in the last position. Carrying this process through we get the following set of exchanges. The origins are written above each element in the c array. What we see here is c is longer than a and b. In fact c must contain a number of elements corresponding to the sum of the elements in a and b (i.e., a+b). To see how this might be done let us consider the smallest merging problem. To merge the two one dimensional array all we need to do is select

the smaller of the a and b elements and place it in c.the larger element is then placed in c. 8 is less than 15 so 8 will take c[1] place and 15 c[2] place. In the same way we start merging arrays of lengths m and n.the comparison between a[1] and b[1] SECTION - C Answer any four of the following 8. a. Explain various characteristics of an algorithm. INPUT: An algorithm may accept zero or more quantities. OUTPUT : An algorithm must produce atleast one quantity. DEFINITENESS: Each instruction is clear, precise and well defined. There should not be any ambiguity. FINITENESS: The algorithm must have finite number of instructions. Thus it terminate after a finite number of steps. must EFFECTIVENESS: Every instruction must be basic so that it must be carried out, in principle, by a person using only pencil and paper. allows us to set c[1]. After placing 8 in c[1] we need a way of deciding which element must be placed next in the c array. In the general case the next element to be placed into c is always going to be the smaller of the first elements in the unmanaged parts of arrays a and b. To keep track of the yet to be merged parts of both the a and b arrays two index pointers i and j will be needed. As an element is selected from either a or b the appropriate pointer must be incremented /decremented by 1. a set of more precisely defined subtasks. These subtasks should more accurately describe how the final goal is to be reached. With each splitting of a task into subtasks it is essential that the way in which the subtasks need to interact with each other be precisely defined. Only in this way is it possible to preserve the overall structure of the solution to the problem. Preservation of the overall structure in the solution to a problem is important both for making the algorithm comprehensible and also for making it possible to prove the correctness of the solution. The process of repeatedly breaking a task down into subtasks and then each subtask into still smaller subtasks must continue until we eventually end up with subtasks that can be implemented as program statements. 9. Write the algorithm and description of sine function computation. Algorithm Description b. What is top-down design? Explain how you break a problem in sub problems. A technique for algorithm design that tries to accommodate this human limitation is known as top-down design or stepwise refinement. Topdown design provides us with a way of handling the inherent logical complexity and details, frequently encountered in computer algorithms. Breaking a problem into subproblems Top-down design suggests that we take the general statements that we have about the solution, one at a time, and break them down into Algorithm ALGORITHM sin(x) //PROBLEM STATEMENT : Given a value x generate an algorithm to evaluate the function sin(x) as defined by the series expansion sin(x) = x/1!- x3/3! + x5/5! - x7/7!+... //INPUT : x as real //OUTPUT: to generate sin(x)

//error is termination d <- 3; condition while (n mod d = 0) AND (d < r) error <-- 1.0* e-6; i <-- 1; x2 <-- x * x; term <-- x; tsin <-- x; while abs(term) > error do (i* (i-1)); i <-- i + 2; term <-- -term * x2 / do d <- d + 2; if n mod d = 0 then sdivisor <- d; else sdivisor <- 1; tsin <-- tsin + term; return tsin; 10. a. Write the algorithm to find GCD of two numbers. ALGORITHM gcd(n,m) PROBLEM STATEMENT: Given two positive non-zero integers n and m design an algorithm for finding their greatest common divisor (GCD). INPUT: n, m as integers whose gcd is to be sought OUTPUT: gcd of n, m integers //r :integer variable to store the remainder repeat r <--n mod m; n <-- m; m <-- r; until r=0 return m; b. Write the algorithm to find smallest divisor of an integer. ALGORITHM smallestdivisor(n) if NOT odd(n) then sdivisor <- 2; else r <- trun(sqrt(n));

11. Write short notes on a. Finding maximum in a set. b. Array Counting or Histogramming. b. Given an element x and a set of data that is in ascending order, write an Binary Search algorithm to find whether or not x is present in the set. //PROBLEM STATEMENT: Algorithm to find an element using binary search method. //INPUT: a: integer array n : integer variable to hold upper limit 12. a. Given a set of numbers below, sort them into non decreasing order using insertion sort 20 35 18 8 14 41 3 39 element key: integer variable, key //OUTPUT: position of the element found. Algorithm BinarySearch(a,n,key) bottom = 1; do top = n; mid = (bottom + top) / 2; if (item < a[mid]) top = mid - 1; else if (item > a[mid]) bottom = mid + 1; while (item!= a[mid] && bottom <= top); if (item == a[mid]) return mid+1; else return -1;