CS1101X: Programming Methodology Recitation 6 Arrays I.

Slides:



Advertisements
Similar presentations
Binomial Expansion and Maclaurin series Department of Mathematics University of Leicester.
Advertisements

EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Mathematical Induction
Pascal’s Triangle Row
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
PASCAL’S TRIANGLE Unit 1, Day 10. Pascal’s Wager “If God does not exist, one will lose nothing by believing in Him, while if he does exist, one will lose.
the fourth iteration of this loop is shown here
June Searching CE : Fundamental Programming Techniques 16 Searching1.
15 Sorting1June Sorting CE : Fundamental Programming Techniques.
Building Java Programs
Set, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides.
1 Assignment 8. Implementing type integer Due on Tuesday, 4 December, by midnight (submitted electronically). Download class List and a skeleton of class.
CHAPTER 8: RIGHT TRIANGLES Watch the follow clip about the Sunshine Skyway Bridge. Think about the design and construction. Do you recognize any right.
The Fundamentals: Algorithms, the Integers & Matrices.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
The Complex Numbers The ratio of the length of a diagonal of a square to the length of a side cannot be represented as the quotient of two integers.
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
Recursion & Collections API Recursion Revisited Programming Assignments using the Collections API.
Rev.S08 MAC 1140 Module 12 Introduction to Sequences, Counting, The Binomial Theorem, and Mathematical Induction.
MATH 224 – Discrete Mathematics
CS1101: Programming Methodology Aaron Tan.
Programming Arrays. Example 1 Write a program that reads 3 numbers from the user and print them in reverse order. How many variables do we need to store.
CS1101X: Programming Methodology Recitation 7 Arrays II.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
The Binomial Theorem.
Chapter 1 Equations, Inequalities, and Mathematical Models
Programming Principles II Lecture Notes 5 Recursion Andreas Savva.
Chapter 14 Searching and Sorting Section 1 - Sequential or Linear Search Section 2 - Binary Search Section 3 - Selection Sort Section 4 - Insertion Sort.
24/3/00SEM107 - © Kamin & ReddyClass 16 - Searching - 1 Class 16 - Searching r Linear search r Binary search r Binary search trees.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Additional Problems.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
Copyright © 2007 Pearson Education, Inc. Slide 8-1.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
Copyright © Cengage Learning. All rights reserved. 8 Sequences, Series, and Probability.
CS1101X: Programming Methodology Recitation 6 Arrays I.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CS1101: Programming Methodology Preparing for Practical Exam (PE)
2-6 Binomial Theorem Factorials
Copyright © Cengage Learning. All rights reserved. CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF ELEMENTARY NUMBER THEORY AND METHODS OF PROOF.
Insertion Sort while some elements unsorted: Using linear search, find the location in the sorted portion where the 1 st element of the unsorted portion.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
CS1101: Programming Methodology Preparing for Practical Exam (PE)
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Agenda 9/27 DO NOW (3 parts) ◦Prove the following: 1.The length of a square is 5 cm. What is the measure of its width? How can you be sure? 2.What is the.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 4 GEORGE KOUTSOGIANNAKIS Copyright: 2016 Illinois Institute of Technology/George Koutsogiannakis 1.
Recursion in Java The answer to life’s greatest mysteries are on the last slide.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
Basic concepts of C++ Presented by Prof. Satyajit De
Sequences, Series, and Probability
Objectives Find entries in Pascal’s triangle.
Pascal’s Triangle Permission Pending By. Ms. Barnes.
The Binomial Theorem Objectives: Evaluate a Binomial Coefficient
Alg2_1c Extra Material for Alg2_1
Ch 4.2: Adding, Subtracting, and Multiplying Polynomials
Boolean Bingo!.
Pascal’s Triangle MDM 4U Lesson 5.1.
Java Programming Control Structures Part 1
Section 4.2 Expanding Binomials Using Pascal’s Triangle
Example. Sort {5, 1, 12, -5, 16, 2, 12, 14} using selection sort. Complexity analysis.
The Binomial Theorem OBJECTIVES: Evaluate a Binomial Coefficient
Section 6.3 Combinations with Pascal’s Triangle
Presentation transcript:

CS1101X: Programming Methodology Recitation 6 Arrays I

CS1101X Recitation #62 Task 1: Learning-by-mistake (1/3) A program NonNegativeArray.java to test whether a list of integers contains a negative number is given. The method isNonNegative() returns true if the array contains all non-negative values; it returns false otherwise true –3 2 6 false

CS1101X Recitation #63 Task 1: Learning-by-mistake (2/3) Which of the following is/are correct? // version 1 public static boolean isNonNegative (int[] arr) { boolean flag = true; for (int i = 0; i < arr.length; ++i) { flag = arr[i] >= 0; } return flag; } // version 2 public static boolean isNonNegative (int[] arr) { boolean flag = true; for (int i = 0; i < arr.length; ++i) { if (arr[i] < 0) flag = false; } return flag; }

CS1101X Recitation #64 Task 1: Learning-by-mistake (3/3) Which of the following is/are correct? // version 3 public static boolean isNonNegative (int[] arr) { for (int i = 0; i < arr.length; ++i) { if (arr[i] >= 0) return true; } return false; } // version 4 public static boolean isNonNegative (int[] arr) { for (int i = 0; i < arr.length; ++i) { if (arr[i] < 0) return false; } return true; }

CS1101X Recitation #65 Task 2: isSorted A program IsSortedArray.java to test whether a list of integers in sorted in non-decreasing order. The method isSorted() returns true if the array is sorted; it returns false otherwise true false

CS1101X Recitation #66 Task 3: Second largest Given a list of integers, determine the second largest value in the list. (Assuming that the list contains at least 2 values.)

CS1101X Recitation #67 Task 4: Pascal’s Triangle (1/3) Blaise Pascal was a scientist, mathematician par excellence who lived in the 17 th century. Some of his mathematical work was fundamental to the theory of probability. There is also a programming language named after him (though in no real sense related to him). More of him in this website (for those who are interested):

CS1101X Recitation #68 Task 4: Pascal’s Triangle (2/3) In this problem, you are asked to generate Pascal's Triangle. Pascal's Triangle is useful in many areas from probability to polynomials to setting programming questions. It is a triangle of integers with 1 on top and down the sides. Any number in the interior equals the sum of the two numbers above it. For example, here are the first 5 rows of the triangle

CS1101X Recitation #69 Task 4: Pascal’s Triangle (3/3) Write a program to generate a Pascal ’ s Triangle as shown. It should be observed that the next row of the Pascal ’ s triangle can be generated from the previous row. Thus, using an array to store the values of the previous rows seems appropriate Output for n (number of rows) = 6.

CS1101X Recitation #610 To be continued… More problems on arrays (including array of objects) at the next recitation.

CS1101X Recitation #611 End of Recitation #6