AP Search and Sort Review

Slides:



Advertisements
Similar presentations
1 11/27/06CS150 Introduction to Computer Science 1 Searching Arrays.
Advertisements

Array Must declare a variable to reference the array double [] mylist; // cannot double list[20]; Or double mylist[]; The declaration doesn’t allocate.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Search Algorithms Sequential Search It does not require an ordered list. Binary Search It requires an ordered.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
AP CS Workshop ArrayList It is very common for applications to require us to store a large amount of data. Array lists store large amounts of data.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Searching Dr. Jose Annunziato. Linear Search Linear search iterates over an array sequentially searching for a matching element int linearSearch(int haystack[],
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
XII CBSE Previous Year Question Paper QUESTION NO 3 (a) 3 Marks.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Arrays and ArrayLists. int numbers[] = new int[10]; numbers Other ways to declare the same array 1) int[] numbers = new.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
CSC 142 Q 1 CSC 142 Sorting [Reading: chapter 11].
ARRAY AND LOOPS REVIEW Mr. Crone. What will the code below print? int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]);
CSII Final Review. How many bits are in a byte? 8.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Unit 6 Analysis of Recursive Algorithms
Using recursion for Searching and Sorting
Java for Beginners Level 6 University Greenwich Computing At School
Lecture 3 Linear Search and Binary Search ArrayLists
CompSci 230 S Programming Techniques
Two Dimensional Array Mr. Jacobs.
The Sequential Search (Linear Search)
Lesson 5-15 AP Computer Science Principles
COP 3503 FALL 2012 Shayan Javed Lecture 8
Alg2_1c Extra Material for Alg2_1
RECITATION 1 ANALYSIS OF ALGORITHMS
Chapter 8 Arrays Objectives
Sorting Data are arranged according to their values.
An Introduction to Java – Part I
Data Structures Array - Code.
Methods & Functions.
Topic 14 Searching and Simple Sorts
ㅎㅎ Fourth step for Learning C++ Programming Two functions
Visual Basic .NET BASICS
Sorting Given a[0], a[1], ..., a[n-1] reorder entries so that
An Introduction to Java – Part I, language basics
CS Week 9 Jim Williams, PhD.
كلية المجتمع الخرج البرمجة - المستوى الثاني
Chapter 8 Arrays Objectives
Sorting Data are arranged according to their values.
HKOI 2005 Intermediate Training
Data Structures Array - Code.
Data Structures (CS212D) Week # 2: Arrays.
Topic 14 Searching and Simple Sorts
Code Refresher Test #1 Topics:
CS 200 Objects and ArrayList
1D Arrays and Lots of Brackets
§ § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
Chapter 8 Arrays Objectives
Arrays in Java.
Revision of C++.
Algorithms Assessment (Computer Science) Date :
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
List Interface ArrayList class implements the List Interface
Agenda Packages and classes Types and identifiers Operators
The Sequential Search (Linear Search)
CS 200 Objects and ArrayList
The Sequential Search (Linear Search)
Introduction to java Part I By Shenglan Zhang.
First Semester Review.
Searching.
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
Presentation transcript:

AP Search and Sort Review Mr. Crone

ArrayList<Integer> arry = new ArrayList<Integer>(); arry ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); What does arry.get(3) return?

ArrayList<Integer> arry = new ArrayList<Integer>(); arry ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); // 0 1 2 3 What does arry.get(3) return? // Returns 10

ArrayList<Integer> arry = new ArrayList<Integer>(); arry ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); What does arry.indexOf(7) return?

ArrayList<Integer> arry = new ArrayList<Integer>(); arry ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); // 0 1 2 3 What does arry.indexOf(7) return? // Returns 2

What does the following code print What does the following code print? ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); arry.remove(2); System.out.println(arry);

What does the following code print What does the following code print? ArrayList<Integer> arry = new ArrayList<Integer>(); arry.add(4); arry.add(5); arry.add(7); arry.add(10); arry.remove(2); System.out.println(arry); // Prints [4, 5, 10]

The linear search method is coded below The linear search method is coded below. What should be placed in the <missing statement> line. public static int linearSearch(int[] arry, int target){ for(int i = 0; i < arry.length; i ++){ if(arry[i] == target) <missing statement> } return -1;

The linear search method is coded below The linear search method is coded below. What should be placed in the <missing statement> line. public static int linearSearch(int[] arry, int target){ for(int i = 0; i < arry.length; i ++){ if(arry[i] == target) return i; } return -1;

The sequential search method is coded below The sequential search method is coded below. What relational operator should be placed in the while loop condition to ensure that every element is checked? public static int linearSearch(int[] arry, int target){ int c = 0; while (c <missing operater> arry.length-1){ if(arry[ c] == target) return c; <missing Line> } return -1;

The sequential search method is coded below The sequential search method is coded below. What relational operator should be placed in the while loop condition to ensure that every element is checked? public static int linearSearch(int[] arry, int target){ int c = 0; while (c <=arry.length-1){ if(arry[ c] == target) return c; <missing Line> } return -1;

The sequential search method is coded below The sequential search method is coded below. What code can replace the <missing Line> to ensure that the method works correctly? public static int linearSearch(int[] arry, int target){ int c = 0; while (c <=arry.length-1){ if(arry[ c] == target) return c; <missing Line> } return -1;

The sequential search method is coded below The sequential search method is coded below. What code can replace the <missing Line> to ensure that the method works correctly? public static int linearSearch(int[] arry, int target){ int c = 0; while (c <=arry.length-1){ if(arry[ c] == target) return c; c++ } return -1;

Which search algorithm will be most efficient on the following array of numbers when looking for the target value of 3? [2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 9, 10, 11, 11, 12, 13, 13, 13]

Which search algorithm will be most efficient on the following array of numbers when looking for the target value of 3? [2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 9, 10, 11, 11, 12, 13, 13, 13] Sequential Search

The numbers below are sorted using the bubble sort The numbers below are sorted using the bubble sort. What is the next step in the bubble sort algorithm? 2 5 1 1 3 7 2 1 5 1 3 7 2 1 1 5 3 7 2 …..

The numbers below are sorted using the bubble sort The numbers below are sorted using the bubble sort. What is the next step in the bubble sort algorithm? 2 5 1 1 3 7 2 1 5 1 3 7 2 1 1 5 3 7 2 1 1 3 5 7 // Answer

Is the code below an example of declaration or initialization? int num;

Is the code below an example of declaration or initialization Is the code below an example of declaration or initialization? int num; Declaration

How many bits are in a byte?

How many bits are in a byte? 8

What is the concatenation operator?

What is the concatenation operator? \\ Answer +

What does the following code print. System. out What does the following code print? System.out.println(“1” + new Integer(2) + 3);

What does the following code print. System. out What does the following code print? System.out.println(“1” + new Integer(2) + 3); // 123

What does the following code print. System. out What does the following code print? System.out.println(“Nums ” + 7+ 3);

What does the following code print. System. out What does the following code print? System.out.println(“Nums ” + 7+ 3); Nums 73

Which of the following is not a method of java.util.ArrayList? add(Object x);  remove(Object x);  insert(int i, Object x);  contains(Object x);  set(int i, Object x)

Which of the following is not a method of java.util.ArrayList? add(Object x);  remove(Object x);  insert(int i, Object x); // Not a method  contains(Object x);  set(int i, Object x)

What will the following code print What will the following code print? int[][] arry = new int[3][4]; System.out.println(arry.length);

What will the following code print What will the following code print? int[][] arry = new int[3][4]; System.out.println(arry.length); // 3

What will the following code print What will the following code print? int n = 2005; for (int i = 0; i < 50; i++) n = (n + 3) / 2; System.out.println(n);

What will the following code print What will the following code print? int n = 2005; for (int i = 0; i < 50; i++) n = (n + 3) / 2; System.out.println(n); // 3