CS 280 Data Structures Professor John Peterson. Examples N copies?

Slides:



Advertisements
Similar presentations
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
Advertisements

Haskell Lets review some of the Haskell concepts you have been learning on your own. The answers are included, but try it yourself first.
The ArrayList Class and the enum Keyword
For(int i = 1; i
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
Exercises – don’t use built in functions for these as we want the practice Write a recursive function to add up all the numbers in a list "flatten" a list.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
5/2/2015 Good Java Programming 1 Bigram: group/word of 2 letters java.util.Set: A collection that contains no duplicate elements.  sets contain no pair.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
CS 280 Data Structures Professor John Peterson. Quiz Wrapup interface Comparable { public boolean gtr(T x, T y); } class Student { public int studentNumber;
CS 280 Data Structures Professor John Peterson. Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu.
CS 280 Data Structures Professor John Peterson. Merge Sorting Questions?
CS 280 Data Structures Professor John Peterson. Project “Tree 1” Questions? Let’s look at my test cases.
CS 280 Data Structures Professor John Peterson. Phase 2 We’re moving on from array-based to link- based structures. You already have experience with links.
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
CS 280 Data Structures Professor John Peterson. Test #1 We’ll do a test next week on Wednesday. It will take the entire period. You can have 1 page of.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Exercise Exercise Exercise Exercise
Exercise Exercise Exercise Exercise
CS 280 Data Structures Professor John Peterson. Test #1 We’ll do a test next week on Wednesday. It will take the entire period. You can have 1 page of.
CS 280 Data Structures Professor John Peterson. Example: log(N) This is where things get hairy! How would you compute Log 10 (N) in a very approximate.
CS 280 Data Structures Professor John Peterson. Next Project YET ANOTHER SORT! We’ll do Quicksort using links instead of arrays. Wiki time.
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
CS 280 Data Structures Professor John Peterson. Log Complexity int j = n; while (j > 0) { System.out.println(j); j = j / 2; /* Integer division! */ }
CS 280 Data Structures Professor John Peterson. Next Project Merge Sort Time! IS280/f07/project_8.
CS 280 Data Structures Professor John Peterson. Exam 1 Stuff O(Log(n)) + O(n) = ? for (int i = n; i>0; i=i/2) for (int j = 0; j < i; j++) print(j); n*log(n)
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
CS 280 Data Structures Professor John Peterson. Project 9 Questions? IS280.
CS 280 Data Structures Professor John Peterson. Grading the Projects Boo-boos: Not allowing bubble sort to exit soon enough Mistakes in the heapify, especially.
CS 280 Data Structures Professor John Peterson. Example 5 null 7 ab Link Data.
Iterators CS 367 – Introduction to Data Structures.
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
1 The Map ADT © Rick Mercer. 2 The Map ADT  A Map is an abstract data type where a value is "mapped" to a unique key  Also known as Dictionary  Need.
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.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
1-6 Subtracting Integers Warm Up Warm Up Lesson Presentation Lesson Presentation Problem of the Day Problem of the Day Lesson Quizzes Lesson Quizzes.
Pre-Algebra 2-2 Subtracting Integers Today’s Learning Goal Assignment Learn to subtract integers.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Peyman Dodangeh Sharif University of Technology Spring 2014.
Pre-Algebra 2-2 Subtracting Integers 2-2 Subtracting Integers Pre-Algebra Warm Up Warm Up Problem of the Day Problem of the Day Lesson Presentation Lesson.
©SoftMoore ConsultingSlide 1 Generics “Generics constitute the most significant change in the Java programming language since the 1.0 release.” – Cay Horstmann.
A: A: double “4” A: “34” 4.
int [] scores = new int [10];
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Asserting Java © Rick Mercer Chapter 7 The Java Array Object.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
Recursion repetition without loops. Recursion  definition solving a problem in terms of a smaller version of itself  form of a recursive solution: base.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Professor John Peterson
ML: a quasi-functional language with strong typing
2-2 Subtracting Integers Warm Up Problem of the Day

Make Your Own Quiz.
A Bag Implementation that Links Data
Review Operation Bingo
Advanced Programming in Java
COMPUTER 2430 Object Oriented Programming and Data Structures I
The numbers 3,6,and 9 have been placed to guide you.
Chapter 7 The Java Array Object © Rick Mercer.
Magic Fractions nRich – cannot find url.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Binary Search Trees Chapter 9 2/24/2019 B.Ramamurthy.
BIT116: Scripting Functions.
Warm Up Problem of the Day Lesson Presentation Lesson Quizzes.
Warm Up Add. 1. – –6 + (–28) 2. –12 + (–9) (–87) (–19) 6. –18 + (–24)
COMPUTER 2430 Object Oriented Programming and Data Structures I
Presentation transcript:

CS 280 Data Structures Professor John Peterson

Examples N copies?

Examples LI copies(int n, int v) { if (n <= 0) return null; return new LI(v, copies(n-1, v)) Let’s use LI to mean Link

Examples upto?

Examples LI upto(int n) { return upto1(1,n);} LI upto1(int i, int n) { if (i > n) return null; return new LI(i, upto1(i+1, n)) }

Exercises We’ll do these on the board in pairs. Sum a list of integers: int sumLI(LI l) Search a list of integers for a given value: boolean searchLI(int v, LI l) As above, except return the position: whereLI – use “-1” as the magic cookie for “not found”. int whereLI(int v, LI l); Compare two lists of integers: boolean equalsLI(LI 1, LI 2) Append two lists, destructive: LI appendLId(LI x, LI y) Append two lists, non-destuctive: LI appendLI(LI x, LI y)

Returning Two Values We’ll be creating functions that return more than one value. We could create a custom “pairing” class that is specific to the classes we need to return, but there’s a better way. How can we use a class to return a pair? How can we make this generic?

Generic Pairs We’re going to need a new Generic function class: public class Pair { public T first; public S second; public Pair(T first, S second) { this.first = first; this.second = second; }}

Quiz