PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
|
|
- Elfreda Sparks
- 5 years ago
- Views:
Transcription
1 (A CHRISITIAN MINORITY INSTITUTION) JAISAKTHI EDUCATIONAL TRUST ACCREDITED BY NATIONAL BOARD OF ACCREDITATION (NBA) AN ISO 9001:2000 CERTIFIED INSTITUTION Bangalore Trunk Road,Varadharajapuram,Nasarathpettai, Poonamallee, Chennai DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY I YEAR I SEMESTER
2 EX.NO LIST OF PROGRAMS PROGRAM TO COMPUTE THE GCD OF TWO NUMBERS PROGRAM TO FIND THE SQUARE ROOT OF A NUMBER ( NEWTON S METHOD ) PROGRAM FOR FINDING EXPONENTIATION ( POWER OF A NUMBER ) PROGRAM TO FIND THE MAXIMUM NUMBER IN THE LIST 5 (A) PROGRAM FOR LINEAR SEARCH 5 (B) PROGRAM FOR BINARY SEARCH 6 (A) PROGRAM FOR SELECTION SORT 6 (B) PROGRAM FOR INSERTION SORT 7 PROGRAM FOR MERGE SORT 8 PROGRAM TO FIND THE FIRST N TERMS PRIME NUMBERS 9 PROGRAM FOR MATRIX MULTIPLICATION PROGRAM FOR COMMAND LINE ARGUMENTS (WORD COUNT ) FIND THE MOST FREQUENT WORDS IN A TEXT READ FROM A FILE 12 STIMULATE ELLIPTICAL ORBITS IN PYGAME 13 STIMULATE BOUNCING BALL USING PYGAME
3 EX.NO LIST OF LLUSTRATIVE PROGRAMS PROGRAM TO EXCHANGE THE VALUES OF TWO VARIABLES PROGRAM TO CIRCULATE THE VALUES OF N VARIABLES PROGRAM TO FIND THE DISTANCE BETWEEN TWO POINTS 4 PROGRAM FOR SUM OF AN ARRAY OF NUMBERS 5 PROGRAM TO CREATE A HISTOGRAM FROM A LIST OF INTEGERS 6 PROGRAM FOR COPY FILE
4 NOTE x = 54 OR x = int ( input ( "enter number " ) ) a=[15,-8,-1,4,36,1] OR a=eval(input("enter the list")) OR a = input ( "Enter list : " ). split() a = list ( map (int,a) )
5 EX.NO : 1 PROGRAM TO COMPUTE THE GCD OF TWO NUMBERS x = 24 y = 54 while y!= 0 : print ( x ) 6 x, y = y, x % y
6 EX.NO : 2 PROGRAM TO FIND THE SQUARE ROOT OF A NUMBER ( NEWTON S METHOD ) def newton ( n, times ) : approx = 0.5 * n for i in range ( times ): return approx approx = 0.5 * ( approx + n / approx ) print ( newton (36,4) ) print ( newton (36,7) )
7 EX.NO : 3 PROGRAM FOR FINDING EXPONENTIATION ( POWER OF A NUMBER ) def power ( base, exp ) : if ( exp == 1 ): return ( base ) else: return ( base * power ( base, exp - 1 ) ) print ( "result = ", power ( 6, 3 ) ) result = 216
8 EX.NO : 4 (A) PROGRAM FOR LINEAR SEARCH a=[-4,10, 25, 15, 3] search = int ( input ( " Enter search number " ) ) for i in a : if search == i: print( search," found ") break else: print ( "Not Found" ) >>> Enter search number found >>> Enter search number 22 Not Found
9 EX.NO : 4 (B) a=[ 15, 5, 21, -5, 32, 9 ] a. sort () PROGRAM FOR BINARY SEARCH search = int ( input ( "Enter Search Number " ) ) start = 0 stop = len(a) - 1 while ( start <= stop ) : mid = ( start + stop ) // 2 if ( search == a [mid] ): print( search, "element found at the position", mid) break elif ( search < a[mid] ): stop = mid - 1 else: start = mid + 1 else: print ( "element not found" )
10 Enter Search Number 5 5 element found at the position 1 Enter Search Number 22 element not found
11 EX.NO : 5 PROGRAM TO FIND THE FIRST N TERMS PRIME NUMBERS upto = int ( input ( "enter upto" ) ) count = 0 for n in range ( 2, 1000 ) : for i in range ( 2, n ) : if n % i == 0 : break else: count = count + 1 if ( count <= upto ) : print( n ) enter upto
12 EX.NO : 6 PROGRAM TO FIND THE MAXIMUM OF A LIST OF NUMBERS a=[25, 9, -3, 12, 5] max=0 for i in a: if( max < i): max = i print( "maximum number = ", max ) maximum number = 25
13 EX.NO : 7 (A) PROGRAM FOR SELECTION SORT a = [ 16,10,-1,369,5 ] for i in range( len (a) ): small = min ( a[ i: ] ) index = a.index ( small ) a[ i ], a [ index ] = a [ index ], a[ i ] print ( a ) [-1, 5, 10, 16, 369]
14 EX.NO : 7 (B) PROGRAM FOR INSERTION SORT a = [ 16,10,-1,369,5 ] for i in a : j = a.index ( i ) while j > 0 : if a[ j -1 ] > a[j] : a [ j - 1 ], a [ j ] = a [ j ], a [ j - 1 ] else: break j = j - 1 print ( a ) [-1, 5, 10, 16, 369]
15 EX.NO : 8 def mergesort ( seq ): PROGRAM FOR MERGE SORT mid = len( seq ) // 2 lft, rgt = seq [ :mid ], seq [ mid: ] if len ( lft ) > 1 : lft = mergesort ( lft ) if len ( rgt ) > 1 : rgt = mergesort ( rgt ) res = [] while lft and rgt : if lft [ -1 ] >= rgt [ -1 ] : res.append ( lft.pop ( ) ) else: res.append ( rgt.pop ( ) ) res.reverse() return ( lft or rgt ) + res a = [ 54,26,93,-17,1 ] print ( mergesort ( a ) ) [-17, 1, 26, 54, 93]
16 EX.NO : 9 PROGRAM FOR MATRIX MULTIPLICATION a = [ [ 2, 2 ], [ 2, 2 ] ] b = [ [ 3, 3 ], [ 3, 3 ] ] c = [ [ 0, 0 ], [ 0, 0 ] ] for i in range ( len ( a ) ): for j in range ( len ( b [ 0 ] ) ): for k in range ( len ( c ) ): c [ i ] [ j ] = a [ i ][ k ] * b [ k ][ j ] + c [ i ] [ j ] print(c) [[12, 12], [12, 12]]
17 EX.NO : 10 PROGRAM FOR COMMAND LINE ARGUMENTS ( WORD COUNT ) from sys import argv from collections import Counter f = open( argv[1]," r ") c = Counter ( f.read( ). split( ) ) print( " Number of words in the file : ", c ) INPUT (ex.txt) panimalar anna panimalar anna panimalar annauniversity sam@syse:~$ python cmd.py ex.txt ('Number of words in the file :', Counter({'panimalar': 3, 'anna': 2, 'annauniversity': 1}))
18 EX.NO : 11 PROGRAM TO FIND MOST FREQUENT WORDS IN A TEXT READ FROM A FILE from collections import Counter f=open( "ex.txt", "r" ) c=counter( f.read( ). split( ) ) print("number of words in the file :",c) INPUT (ex.txt ) panimalar anna panimalar anna panimalar annauniversity sam@syse:~$ python coun.py ('Number of words in the file :', Counter({'panimalar': 3, 'anna': 2, 'annauniversity': 1}))
19 EX.NO : 12 import pygame import math from time import * pygame.init() SIMULATE ELLIPTICAL ORBITS IN PYGAME screen = pygame.display.set_mode((700, 700)) black = (0, 0, 0) yellow = (255, 255, 0) blue = (0, 0, 255) ex = 50 ey = 350 oe = 0 a=1 while a==1: screen.fill(black) ex = math.cos(oe) * ey = -math.sin(oe) * oe +=.002 pygame.draw.circle(screen, yellow, (350,350), 50) pygame.draw.circle(screen, blue, (int(ex), int(ey)), 15) pygame.display.flip() sleep(.010)
20 for event in pygame.event.get(): if event.type == pygame.quit: a = 0 pygame.quit()
21 EX.NO : 13 import pygame from time import * SIMULATE BOUNCING BALL USING PYGAME pygame.init() screen = pygame.display.set_mode((500, 400)) black = (0, 0, 0) blue = (0, 0, 255) x = 1 y = 0 a = 1 while a ==1: screen.fill(black) pygame.draw.circle(screen, blue, (250,y), 10) y += x if y >= 400: x = -1 elif y <= 0: x = 1 pygame.display.flip() sleep(.005) for event in pygame.event.get(): if event.type == pygame.quit: a=0 pygame.quit()
22
23 LLUSTRATIVE PROGRAMS ( UNIT 2 ) 1. PROGRAM FOR EXCHANGE THE VALUE OF 2 VARIABLES x = int ( input("enter value of x: ") ) y = int ( input("enter value of y: ") ) print("before swapping: ", x, " and ", y ) x, y = y, x print("after swapping: ", x, " and ", y ) : Enter value of x: 15 Enter value of y: 21 Before swapping : 15 and 21 After swapping : 21 and 15
24 LLUSTRATIVE PROGRAMS ( UNIT 2 ) 2. PROGRAM FOR CIRCULATE THE VALUES OF N VARIABLES a=[14, -1, 59, -100, 21] for i in range ( len (a) ): print( a [ i: ] + a [ :i ] ) : [14, -1, 59, -100, 21] [-1, 59, -100, 21, 14] [59, -100, 21, 14, -1] [-100, 21, 14, -1, 59] [21, 14, -1, 59, -100]
25 LLUSTRATIVE PROGRAMS ( UNIT 2 ) 3. PROGRAM FOR DISTANCE BETWEEN TWO POINTS x1=int(input("enter x1 :")) x2=int(input("enter x2 :")) y1=int(input("enter y1 :")) y2=int(input("enter y2 :")) calx=(x2-x1)**2 caly=(y2-y1)**2 point=calx-caly print("distance Between Two Points = ", point) enter x1 : 2 enter x2 : 8 enter y1 : 8 enter y2 : 10 Distance Between Two Points = 32
26 LLUSTRATIVE PROGRAMS ( UNIT 3 ) 4. PROGRAM FOR SUM AN ARRAY OF NUMBERS a=[11,22,33] print("given List = ", a) sum=0 for i in a: sum=sum+i print("sum an array of numbers = ", sum) : Given List = [11, 22, 33] sum an array of numbers = 66
27 LLUSTRATIVE PROGRAMS ( UNIT 4 ) 5. TO CREATE A HISTOGRAM FROM A LIST OF INTEGERS a=[5,15,9,6,20,2] for i in a: sum='' while(i>0): sum=sum+'*' i=i-1 print(sum) ***** *************** ********* ****** ******************** **
28 LLUSTRATIVE PROGRAMS ( UNIT 5 ) 6. PROGRAM FOR COPY FILE f1=open("r1.txt","r") f2=open("r2.txt","w") for i in f1: f2.write(i) f1.close() f2.close() INPUT (r1.txt ) panimalar anna panimalar anna panimalar annauniversity (r2.txt ) panimalar anna panimalar anna panimalar annauniversity
COMPUTE THE GCD OF TWO NUMBERS. Date: Aim: To compute the GCD of two numbers
Ex. No 1 Date: COMPUTE THE GCD OF TWO NUMBERS. Aim: To compute the GCD of two numbers Algorithm: 1. Read two input values using input function 2. Convert them into integers 3. Define a function to compute
More informationThere s already a ton of code written called libraries that we can use by importing. One that we use often is random
There s already a ton of code written called libraries that we can use by importing. One that we use often is random import random print random.randint(2, 22) Random frequently used methods Name Use random.randint(a,
More informationDhanalakshmi College of Engineering Manimangalam, Tambaram, Chennai
Dhanalakshmi College of Engineering Manimangalam, Tambaram, Chennai 601 301 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING I SEMESTER - R 2017 GE8161 PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY LABORATORY
More informationPYTHON NOTES (drawing.py and drawstuff.py)
PYTHON NOTES (drawing.py and drawstuff.py) INTRODUCTION TO PROGRAMMING USING PYGAME STEP 1: Importing Modules and Initialization All the Pygame functions that are required to implement features like graphics
More informationCS 140 Final Exam Review Problems
This is a cumulative final exam, so please review all of the practice problems as well as your quizzes and exam. There is some material that you haven t been tested on yet (images, strings, and lists),
More informationPyGame Unit ?
PyGame Unit 1 1.1 1.? 1.1 Introduction to PyGame Text Book for Python Module Making Games With Python and PyGame By Al Swiegert Easily found on the Internet: http://inventwithpython.com/pygame/chapters
More information***********PYTHON PROGRAMS FOR CLASS XI ******************** """ Program to Calculate Simple Interest """ p = eval(input("enter Principle?
***********PYTHON PROGRAMS FOR CLASS XI ******************** 1. """ Program to Calculate Simple Interest """ p = eval(input("enter Principle? ")) r = eval(input("enter Rate? ")) t = eval(input("enter Time?
More informationAlgorithms 4. Odd or even Algorithm 5. Greatest among three numbers Algorithm 6. Simple Calculator Algorithm
s 4. Odd or even Step 3 : If number divisible by 2 then Print "Number is Even" Step 3.1 : else Print "Number is Odd" Step 4 : Stop 5. Greatest among three numbers Step 2 : Read values of a, b and c Step
More informationslide 1 gaius Python Classes you can use theclass keyword to create your own classes here is a tiny example of a class
Python Classes slide 1 you can use theclass keyword to create your own classes here is a tiny example of a class Python Classes slide 2 tinyclass.py #!/usr/bin/python import math class vector: def init
More information""" idea.py simplest possible pygame display demonstrates IDEA / ALTER model Andy Harris, 5/06 """
""" idea.py simplest possible pygame display demonstrates IDEA / ALTER model Andy Harris, 5/06 """ #I - Import and initialize import pygame pygame.init() #D - Display configuration screen = pygame.display.set_mode((640,
More information(b) If a heap has n elements, what s the height of the tree?
CISC 5835 Algorithms for Big Data Fall, 2018 Homework Assignment #4 1 Answer the following questions about binary tree and heap: (a) For a complete binary tree of height 4 (we consider a tree with just
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Administrivia and Motivation Administrative Matters: Review of course design and course policies Motivation: Two Algorithms
More informationOutline. 1 If Statement. 2 While Statement. 3 For Statement. 4 Nesting. 5 Applications. 6 Other Conditional and Loop Constructs 2 / 19
Control Flow 1 / 19 Outline 1 If Statement 2 While Statement 3 For Statement 4 Nesting 5 Applications 6 Other Conditional and Loop Constructs 2 / 19 If Statement Most computations require different actions
More informationStatements 2. a operator= b a = a operator b
Statements 2 Outline Note: i=i+1 is a valid statement. Don t confuse it with an equation i==i+1 which is always false for normal numbers. The statement i=i+1 is a very common idiom: it just increments
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 20 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E I SEMESTER GE85- Problem Solving and Python Programming Regulation 207 Academic
More informationTeach A level Compu/ng: Algorithms and Data Structures
Teach A level Compu/ng: Algorithms and Data Structures Eliot Williams @MrEliotWilliams Course Outline Representa+ons of data structures: Arrays, tuples, Stacks, Queues,Lists 2 Recursive Algorithms 3 Searching
More informationIntroduction to Game Programming Lesson 4 Lecture Notes
Introduction to Game Programming Lesson 4 Lecture Notes Learning Objectives: Following this lecture, the student should be able to: Define frame rate List the factors that affect the amount of time a game
More informationLecture 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 informationHacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018
Hacettepe University Computer Engineering Department Programming in BBM103 Introduction to Programming Lab 1 Week 4 Fall 2018 Install PyCharm Download Link : https://www.jetbrains.com/pycharm-edu/download/#section=windows
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 3: Background in Algorithms Cho-Jui Hsieh UC Davis April 13, 2017 Time Complexity Analysis Time Complexity There are always many ways
More informationTwo Approaches to Algorithms An Example (1) Iteration (2) Recursion
2. Recursion Algorithm Two Approaches to Algorithms (1) Iteration It exploits while-loop, for-loop, repeat-until etc. Classical, conventional, and general approach (2) Recursion Self-function call It exploits
More informationPROBLEM SOLVING TECHNIQUES SECTION - A. 1. Answer any ten of the following
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
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 2: Background in Algorithms Cho-Jui Hsieh UC Davis April 5/April 10, 2017 Time Complexity Analysis Time Complexity There are always many
More informationMultiple-choice (35 pt.)
CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need
More informationLists How lists are like strings
Lists How lists are like strings A Python list is a new type. Lists allow many of the same operations as strings. (See the table in Section 4.6 of the Python Standard Library Reference for operations supported
More informationAlgorithms Programming for Engineers Winter Andreas Zeller, Saarland University
Algorithms Programming for Engineers Winter 2015 Andreas Zeller, Saarland University Today s Topics Algorithms Search and Sort Complexity Sounds! An Algorithm unambiguous instruction to solve a problem
More informationCSc 110, Spring 2017 Lecture 39: searching
CSc 110, Spring 2017 Lecture 39: searching 1 Sequential search sequential search: Locates a target value in a list (may not be sorted) by examining each element from start to finish. Also known as linear
More informationLecture 6: Divide-and-Conquer
Lecture 6: Divide-and-Conquer COSC242: Algorithms and Data Structures Brendan McCane Department of Computer Science, University of Otago Types of Algorithms In COSC242, we will be looking at 3 general
More informationProblem 1 (a): List Operations
Problem 1 (a): List Operations Task 1: Create a list, L1 = [1, 2, 3,.. N] Suppose we want the list to have the elements 1, 2, 10 range(n) creates the list from 0 to N-1 But we want the list to start from
More informationPriority queues. Priority queues. Priority queue operations
Priority queues March 30, 018 1 Priority queues The ADT priority queue stores arbitrary objects with priorities. An object with the highest priority gets served first. Objects with priorities are defined
More informationIntroduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1
Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables
More informationESc101 : Fundamental of Computing
ESc101 : Fundamental of Computing I Semester 2008-09 Lecture 37 Analyzing the efficiency of algorithms. Algorithms compared Sequential Search and Binary search GCD fast and GCD slow Merge Sort and Selection
More informationCS 323 Lecture 1. Design and Analysis of Algorithms. Hoeteck Wee
{ CS 323 Lecture 1 } Design and Analysis of Algorithms Hoeteck Wee hoeteck@cs.qc.cuny.edu http://cs323.qwriting.org/ Algorithmic ideas are pervasive APPLICATIONS. Economics, auctions and game theory Biology,
More informationCOS 226 Algorithms and Data Structures Fall Midterm Solutions
1 COS 226 Algorithms and Data Structures Fall 2010 Midterm Solutions 1. Analysis of algorithms. (a) For each expression in the left column, give the best matching description from the right column. B.
More informationSorting Goodrich, Tamassia Sorting 1
Sorting Put array A of n numbers in increasing order. A core algorithm with many applications. Simple algorithms are O(n 2 ). Optimal algorithms are O(n log n). We will see O(n) for restricted input in
More informationSorting and Searching
Sorting and Searching Sorting o Simple: Selection Sort and Insertion Sort o Efficient: Quick Sort and Merge Sort Searching o Linear o Binary Reading for this lecture: http://introcs.cs.princeton.edu/python/42sort/
More information24. Sorting a List. Topics: Selection Sort. Merge Sort
24. Sorting a List Topics: Selection Sort Merge Sort Our examples will highlight the interplay between functions and lists Sorting a List of Numbers Before: x --> 50 40 10 80 20 60 After: x --> 10 20 40
More informationReview Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts
Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Simple Data Types There are a number of data types that are considered primitive in that they contain only a single value. These data
More informationsomedata = { } somedata[ cheese ] = dairy somedata[ Cheese ] = dairy items = ( ( 3, 2 ), ( 5, 7 ), ( 1, 9 ), 0, ( 1 ) )
Structuring State 4 Self-Review Questions Self-review 4.1 What are the values of the variables a, b, c and d after the following statements have been executed? a = 1 b = 2 c = a + b d = a + c a will be
More informationSyllabus of Diploma Engineering. Computer Engineering. Semester: II. Subject Name: Computer Programming. Subject Code: 09CE1104
Semester: II Subject Name: Computer Programming Subject Code: 09CE1104 Objective: This Course will help to develop programming skills in the students, using a structured programming language `C'. Students
More informationCompSci 105. Sorting Algorithms Part 2
Shell Sort another n 2 (or better!) sorting algorithm Merge Sort an n log(n) sorting algorithm Textbook: Chapter 5 CompSci 105 Sorting Algorithms Part 2 Note: we do not study quicksort in CompSci 105 Remember:
More informationFinal Exam(sample), Fall, 2014
Final Exam(sample), Fall, 2014 Date: Dec 4 th, 2014 Time: 1.25 hours (1.00 a.m. 2:15 p.m.) Total: 100 points + 20 bonus Problem 1 T/F 2 Choice 3 Output Points 16 16 48 4 Programming 20 5 Bonus 20 Total
More informationBiostatistics 615/815 Lecture 5: Divide and Conquer Algorithms Sorting Algorithms
Biostatistics 615/815 Lecture 5: Algorithms Algorithms Hyun Min Kang September 20th, 2011 Hyun Min Kang Biostatistics 615/815 - Lecture 5 September 20th, 2011 1 / 30 Recap - An example C++ class #include
More informationPython Programming Exercises 3
Python Programming Exercises 3 Notes: These exercises assume that you are comfortable with the contents of the two previous sets of exercises including variables, types, arithmetic expressions, logical
More informationTHE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists
THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September 2016 COMP1730 / COMP6730 Programming for Scientists Study Period: 15 minutes Time Allowed: 2 hours Permitted Materials: One A4 page
More informationPython review. 1 Python basics. References. CS 234 Naomi Nishimura
Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not
More informationGETTING STARTED WITH RASPBERRY PI
GETTING STARTED WITH RASPBERRY PI Workshop Handout Created by Furtherfield Commissioned by Southend Education Trust GETTING STARTED WITH RASPBERRY PI INTRODUCTION Introduce Raspberry Pi and answer some
More informationg(n) time to computer answer directly from small inputs. f(n) time for dividing P and combining solution to sub problems
.2. Divide and Conquer Divide and conquer (D&C) is an important algorithm design paradigm. It works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until
More informationPYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s
PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,
More informationData 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 information15110 Principles of Computing, Carnegie Mellon University - CORTINA. Binary Search. Required: List L of n unique elements.
UNIT 5B Binary Search 1 Binary Search Required: List L of n unique elements. The elements must be sorted in increasing order. Result: The index of a specific element (called the key) or None if the key
More informationCPSC 217 Midterm (Python 3 version)
CPSC 217 Midterm (Python 3 version) Duration: 60 minutes 7 March 2011 This exam has 81 questions and 14 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance
More informationRun Times. Efficiency Issues. Run Times cont d. More on O( ) notation
Comp2711 S1 2006 Correctness Oheads 1 Efficiency Issues Comp2711 S1 2006 Correctness Oheads 2 Run Times An implementation may be correct with respect to the Specification Pre- and Post-condition, but nevertheless
More informationIntroduction to Game Programming Lesson 5 Lecture Notes, Part 1: The draw Module
Introduction to Game Programming Lesson 5 Lecture Notes, Part 1: The draw Module Learning Objectives: Following this lecture, the student should be able to: Draw a line with pygame, using all parameters
More informationModule 08: Searching and Sorting Algorithms
Module 08: Searching and Sorting Algorithms Topics: Searching algorithms Sorting algorithms 1 Application: Searching a list Suppose you have a list L. How could you determine if a particular value is in
More informationCS 170 Exam 2. Section 004 Fall Name (print): Instructions:
CS 170 Exam 2 Section 004 Fall 2013 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationS1) It's another form of peak finder problem that we discussed in class, We exploit the idea used in binary search.
Q1) Given an array A which stores 0 and 1, such that each entry containing 0 appears before all those entries containing 1. In other words, it is like {0, 0, 0,..., 0, 0, 1, 1,..., 111}. Design an algorithm
More informationIntroduction to programming using Python
Introduction to programming using Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ Session 5 1 Objectives To come back on the definition of functions To invoke value-returning
More informationQ1 Q2 Q3 Q4 Q5 Q6 Total
Name: SSN: Computer Science Foundation Exam May 5, 006 Computer Science Section 1A Q1 Q Q3 Q4 Q5 Q6 Total KNW KNW KNW ANL,DSN KNW DSN You have to do all the 6 problems in this section of the exam. Partial
More informationSubject: Computer Science
Subject: Computer Science Topic: Data Types, Variables & Operators 1 Write a program to print HELLO WORLD on screen. 2 Write a program to display output using a single cout statement. 3 Write a program
More informationDesign and Analysis of Algorithms - - Assessment
X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise.
More informationCS 1110: Introduction to Computing Using Python Loop Invariants
CS 1110: Introduction to Computing Using Python Lecture 21 Loop Invariants [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements Prelim 2 conflicts due by midnight tonight Lab 11 is out Due
More informationECE264 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 informationFundamentals of Programming. Week 5 - Lecture 2: Efficiency continued. Merge sort. Sets. Dictionaries.
15-112 Fundamentals of Programming Week 5 - Lecture 2: Efficiency continued. Merge sort. Sets. Dictionaries. February 11, 2016 Measuring running time How to properly measure running time > Input length/size
More informationData Structures CHAPTER 11. Review Questions. Multiple-Choice Questions. Exercises. (Solutions to Odd-Numbered Problems)
CHAPTER 11 Data Structures (Solutions to Odd-Numbered Problems) Review Questions 1. Arrays, records, and linked lists are three types of data structures discussed in this chapter. 3. Elements of an array
More informationData Structures And Algorithms
Data Structures And Algorithms Hashing Eng. Anis Nazer First Semester 2017-2018 Searching Search: find if a key exists in a given set Searching algorithms: linear (sequential) search binary search Search
More informationBegin to code with Python Obtaining MTA qualification expanded notes
Begin to code with Python Obtaining MTA qualification expanded notes The Microsoft Certified Professional program lets you obtain recognition for your skills. Passing the exam 98-381, "Introduction to
More informationCS103 Unit 8. Recursion. Mark Redekopp
1 CS103 Unit 8 Recursion Mark Redekopp 2 Recursion Defining an object, mathematical function, or computer function in terms of itself GNU Makers of gedit, g++ compiler, etc. GNU = GNU is Not Unix GNU is
More informationCSc 110 Sample Midterm Exam #2
1. Collections Mystery Consider the following function: CSc 110 Sample Midterm Exam #2 def mystery(m): s = set() for key in m.keys(): if (m[key]!= key): s.add(m[key]) else: s.add(m[key][0]) print(s) Write
More informationUnit-2 Divide and conquer 2016
2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of
More informationUnit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION
DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing
More informationSpring 2017 CS 1110/1111 Exam 2
Spring 2017 CS 1110/1111 Exam 2 Bubble in your computing ID in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly. If you have a shorter ID, leave some rows blank.
More informationFundamentals of Programming (Python) Getting Started with Programming
Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationEXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING. The examination contains 5 questions. You must answer ALL questions
EXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING Time allowed: Instructions: THREE HOURS The examination contains 5 questions. You must answer ALL questions Each question is worth 36 marks. The
More informationLab Manual. Program Design and File Structures (P): IT-219
Lab Manual Program Design and File Structures (P): IT-219 Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical / program Lab
More informationBiostatistics 615/815 Lecture 5: More on STLs, and Divide and Conquer Algorithms
Biostatistics 615/815 Lecture 5: More on s, and Algorithms Hyun Min Kang Januray 20th, 2011 Hyun Min Kang Biostatistics 615/815 - Lecture 5 Januray 20th, 2011 1 / 28 Announcements Homework #1 is due, late
More informationpygame Lecture #5 (Examples: fruitgame)
pygame Lecture #5 (Examples: fruitgame) MOUSE INPUT IN PYGAME I. Detecting Mouse Input in pygame In addition to waiting for a keyboard event to precipitate some action, pygame allows us to wait for a mouse
More information1 # Says hello to someone 2 3 s = input() 4 print(f"hello, {s}") input.py
1 # Says hello to someone 3 s = input() 4 print(f"hello, {s}") input.py 1 # A program 3 4 def main(): 5 print("hello, world") 6 7 8 if name == " main ": 9 main() main.py speller/dictionary.py 1 class Dictionary:
More informationUEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter
UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter What you will learn from Lab 7 In this laboratory, you will understand how to use typical function prototype with
More informationHere n is a variable name. The value of that variable is 176.
UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence
More informationIntroduction to Computer Programming in Python Dr. William C. Bulko. Data Types
Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have
More informationComputer Programming
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Merge Sort in C++ and Its Analysis Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,
More informationGE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING
GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 03 / 25 / 2013 Instructor: Michael Eckmann Today s Topics Comments/Questions? More on Recursion Including Dynamic Programming technique Divide and Conquer techniques
More information100 points total. CSE 3353 Homework 2 Spring 2013
Name: 100 points total CSE 3353 Homework 2 Spring 2013 Assignment is due at 9:30am on February 28. Submit a hard copy of the assignment, including a copy of your code and outputs as requested in the assignment.
More informationCS103 Unit 8. Recursion. Mark Redekopp
1 CS103 Unit 8 Recursion Mark Redekopp 2 Recursion Defining an object, mathematical function, or computer function in terms of itself GNU Makers of gedit, g++ compiler, etc. GNU = GNU is Not Unix GNU is
More informationSprites and collisions
Sprites and collisions slide 1 sprites are created and normally placed into a list and referred to as a group you can then test for a collision between another sprite by: spritecollide(sprite, group, dokill)
More informationProgramming Training
Programming Training Main Points: - Working with Functions in Python - Problems with Numbers. - Discuss some important algorithms - Primality - Digits - Greatest Common Divisor Python Repetitions. while
More informationParallel Sorting Algorithms
CSC 391/691: GPU Programming Fall 015 Parallel Sorting Algorithms Copyright 015 Samuel S. Cho Sorting Algorithms Review Bubble Sort: O(n ) Insertion Sort: O(n ) Quick Sort: O(n log n) Heap Sort: O(n log
More informationSorting is a problem for which we can prove a non-trivial lower bound.
Sorting The sorting problem is defined as follows: Sorting: Given a list a with n elements possessing a total order, return a list with the same elements in non-decreasing order. Remember that total order
More informationRecursive Functions. Biostatistics 615 Lecture 5
Recursive Functions Biostatistics 615 Lecture 5 Notes on Problem Set 1 Results were very positive! (But homework was time-consuming!) Familiar with Union Find algorithms Language of choice 50% tried C
More informationCSCE 110: Programming I
CSCE 110: Programming I Sample Questions for Exam #1 February 17, 2013 Below are sample questions to help you prepare for Exam #1. Make sure you can solve all of these problems by hand. For most of the
More informationThe float type and more on variables FEB 6 TH 2012
The float type and more on variables FEB 6 TH 2012 The float type Numbers with decimal points are easily represented in binary: 0.56 (in decimal) = 5/10 + 6/100 0.1011 (in binary) = ½+0/4 + 1/8 +1/16 The
More informationDM550/DM857 Introduction to Programming. Peter Schneider-Kamp
DM550/DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ Project Qualification Assessment first assessment
More informationFunctions. Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein
Functions Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein Dictionaries: key:value pairs A quick review a.k.a. hash tables, lookup tables Examples: Word and definition
More informationPractice Question. Omar Khan / Atif Alvi. October 10, 2016
Practice Question Omar Khan / Atif Alvi October 10, 2016 1 Chapter 1 Loops 1.1 While Loop Iterating through a string 1. Print the first 10 integers 1 i = 0 2 n = 10 3 while i
More informationColumns A[0] A[0][0] = 20 A[0][1] = 30
UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always
More informationCS150 - Sample Final
CS150 - Sample Final Name: Honor code: You may use the following material on this exam: The final exam cheat sheet which I have provided The matlab basics handout (without any additional notes) Up to two
More informationChapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52
Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments
More informationMultimedia-Programmierung Übung 5
Multimedia-Programmierung Übung 5 Ludwig-Maximilians-Universität München Sommersemester 2009 Ludwig-Maximilians-Universität München Multimedia-Programmierung 5-1 Today Sprite animations in Advanced collision
More information