1 CS100J 31 October 2006 Arrays: searching & sorting. Reading: 8.5 Merry Christmas!! On Halloween? Searching and sorting algorithms are on the course website.

Slides:



Advertisements
Similar presentations
SORTING Lecture 12B CS2110 – Spring InsertionSort 2 pre: b 0 b.length ? post: b 0 b.length sorted inv: or: b[0..i-1] is sorted b 0 i b.length sorted.
Advertisements

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY Lecture 9 CS2110 – Spring 2015 We may not cover all this material.
DNA Notes.
1 CS100J 13 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
CS100J Nov 04, 2003 Arrays --sorting. Reading: 8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are generous kind.
1 CS100J 27 March 2007 Algorithms on arrays Reading: 8.3–8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are generous.
1 CS100J October 06, 2005 For Loops Reading: Secs Quote for the Day: Perhaps the most valuable result of all education is the ability to make yourself.
CS 1110 Prelim III: Review Session 1. Info My name: Bruno Abrahao – We have two other TA’s in the room to help you individually Beibei Zhu Suyong Zhao.
1 Teaching the development of algorithms Teach skill, not only facts David Gries Computer Science Department Cornell University November 2004 DrJava is.
1 CS211, Lecture 20 Priority queues and Heaps Readings: Weiss, sec. 6.9, secs When they've got two queues going, there's never any queue!
1 Recitation 7. Developing loops Introduction. This recitation concerns developing loops using their invariants and bound functions. Your recitation instructor.
1 Assignment 6. Developing Loops Due on Tuesday, 30 October, by midnight (submitted electronically). Note that each question will be graded on the following.
1 CS100J 25 October 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
DNA Structure. DNA – Deoxyribonucleic Acid DNA - the thread of life DNA – the genetic carrier.
1 CS100J 29 March 2007 Arrays: searching & sorting. Reading: 8.5 Why did I get a Christmas Card on Halloween? Searching and sorting algorithms are on the.
DNA. All living things contain a blueprint for the entire organism inside a special molecule known as _____. DNA stands for _____________________. A DNA.
Nucleic Acids Nucleic Acid Basics Contain instructions to build proteins 2 types: – DNA – RNA Composed of smaller units called nucleotides – Monomer:
DNA (Deoxyribonucleic Acid) General information: Genetic code of life determining how an organism looks and acts Determines the structure of proteins Packaged.
1 CS100J 16 March 2006 Arrays Reading: You are responsible for: Secs 8.1, 8.2, 8.3, 8.4 A decimal point I'm a dot in placeSlot machines Cash lost in 'em.
Unit 2 – PART A Inside the Nucleus DNA Sturcture.
DNA The molecule of heredity. The molecules of DNA is the information for life (determine an organism’s traits) DNA achieves its control by determining.
What is this DNA you speak of?  DNA stands for deoxyribonucleic acid - Found in nucleus of eukaryotic cells - Found in cytoplasm of protists.
Nucleic Acids.
National 5 Biology Course Notes Part 4 : DNA and production of
CS 100Lecture 131 Announcements Exam stats P3 due on Thursday.
CS November 2010 Developing array algorithms. Reading: Haikus (5-7-5) seen on Japanese computer monitors Yesterday it worked. Today it is.
1 CS November 2010 insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill. Practice.
1 CS100J 18 October 2005 Arrays Reading: You are responsible for: Secs 8.1, 8.2, 8.3, 8.4 A decimal point I'm a dot in placeSlot machines Cash lost in.
1 CS April 2009 Sorting: insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill.
Have Your DNA and Eat It Too I will be able to describe the structure of the DNA molecule I will be able to explain the rules of base pairing I will understand.
CS100A, Fall Review of loops 1 CS100A, Fall 1998, Review of Loops and Loop Invariants Some students are still having trouble understanding loop invariants.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
1 CS April 2010 insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill. Practice.
1 CS Oct 2008 Arrays. Reading: Secs 8.1, 8.2, 8.3 Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long, and.
DNA and RNA Structure and Function Chapter 12 DNA DEOXYRIBONUCLEIC ACID Section 12-1.
1 CS100J 21 March 2006 Arrays: searching & sorting. Reading: 8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are.
DNA
The Structure of DNA. DNA is a nucleic acid. There are two types of nucleic acids: __________ or deoxyribonucleic acid __________ or ribonucleic acid.
DNA: The Molecule of Heredity
Prokaryotic and Eukaryotic Cells: What do all cells have in common?
CS100J 30 October 2007 Algorithms on arrays Reading: 8.3–8.5
DNA and The Genome Structure and Organisation of DNA
Developing Loops from Invariants
Announcements P2 is due tomorrow Prelim on Monday
DNA Deoxyribonucleic Acid
Notes: DNA Structure Topic 2.
AIM: How are DNA molecules structured
Notes - DNA, Genes, and Chromosomes
Unit 4 Notes: DNA Structure
CS100A Lecture 15, 17 22, 29 October 1998 Sorting
Asymptotic complexity Searching/sorting
DNA Vocabulary.
Additional info: Genes & DNA
Binary Search and Loop invariants
Asymptotic complexity
DNA STRUCTURE AND FUNCTION
CS November 2010 Developing array algorithms. Reading:
Sorting and Asymptotic Complexity
Searching and Sorting Hint at Asymptotic Complexity
CS100A Lecture 15, 17 22, 29 October 1998 Sorting
Searching and Sorting Hint at Asymptotic Complexity
Developing loops from invariants
Linear and Binary Search
GENETICS DNA Basics.
CS100J Nov 04, 2003 Arrays. Reading: 8
Deoxyribonucleic Acid
Developing Loops from Invariants
Searching and Sorting Hint at Asymptotic Complexity
Searching and Sorting Hint at Asymptotic Complexity
A Quick Review! What determines a proteins function?
Presentation transcript:

1 CS100J 31 October 2006 Arrays: searching & sorting. Reading: 8.5 Merry Christmas!! On Halloween? Searching and sorting algorithms are on the course website. Decimal Octal Binary Decimal Octal Binary Decimal Octal Binary

2 Decimal 5482: 5* * * *10 0 Octal 3726: 3* * * *10 0 Binary 1011: 1* * * *2 0 /** = a string that contains the binary representation of n. Precondition: n >= 0 */ public static String binary(int n) { if (n <= 1) return “” + n; return binary(n/2) + (n%2); }

3 Decimal 5482: 5* * * *10 0 Octal 3726: 3* * * *10 0 Binary 1011: 1* * * *2 0 /** = a string that contains the binary representation of n. Precondition: n >= 0 */ public static String binary(int n) { if (n == 0) return “0”; String res= “”; int k= n; // binary repr of n = binary repr of k + res; while ( k > 0) { res= (k%2) + res; k= k / 2; } // binary repr of n = res return res; }

4 Getting an invariant as picture: Combine pre- and post-condition ? 0 n pre: reds whites blues 0 n post: reds whites ? blues 0 h k j n inv: ? 0 n pre: x is the min of this 0 n post: x is the min of this ? 0 k n inv: Dutch national flag Finding the minimum value of an array

5 Binary search: Find a position in sorted array b that satifies b[0..k] <= x and b[k+1..b.length-1] ? 0 b.length pre: b x 0 k b.length post: b What invariant can you use?

6 Linear search.Vague spec.: find first occurrence of v in b[h..k-1]. Better spec.: Store an integer in i to truthify: postcondition: (0) v is not in b[h..i-1] (1) Either i= k or v = b[k] invariant: v is not in b[h..i-1] Finding the min. Vague spec.: Find the min of b[h..k] Better spec.: Precondition: h <= k (because an empty set of values has no min) Store in i to truthify: postcondition: b[m] is the min of b[h..k] (and it is first occurrence of the min) invariant: b[m] is the min of b[h..t-1] (and it is first occur. of the min) Binary search: Vague spec: Look for v in sorted array segment b[h..k]. Better spec: Precondition: b[h..k] is sorted (in ascending order). Store in i to truthify: postcondition: b[h..i] <= v and v < b[i+1..k] invariant: b[h..i] <= v and v < b[j..k]

7 Dutch national flag.Vague spec.: b[0..n-1] contains only red, white, blue balls. Sort it using only swaps. Better spec.: Precondition: n >= 0 Permute b[0..n–1] to truthify: postcondition: b[0..h–1] are red balls b[h..k–1] are white balls b[k..n–1] are blue balls precondition: postcondition: invariant : reds whites ? blues 0 h k j n ? 0 n reds whites blues 0 h k n

8 Sorting: ? h k pre: sorted h k post: sorted ? h i k Four possible invariants: Write the algorithm using each one. b b b sorted ? h i k b ? sorted h i k b ? sorted h i k b

9 Sorting: ? h k pre: sorted h k post: ≤ b[i..k], sorted ≥ b[h..i-1], ? h i k selectionsort inv: sorted ? h i k insertionsort inv: The invariant for algorithm selection sort adds another property to each segment: the first segment contains the smaller values.

10 Deoxyribonucleic acid (DNA) is the building block of all life. Each DNA strand consists of two strings of bases twisted together to form a double helix. The 4 possible bases are represented by G, A, T and C. In a helix, A and T bond together, as do C and G. The two sequences in a helix are complements. For example, these two sequences are complements of each other: sequence 1:ACGTTAC sequence 2:TGCAATG Paired bases meet at an angle. DNA is a very large molecule; the image shows only a tiny fraction of the typical molecule. For the bacterium Escherichia coli, the image would be 80 kilometers long. For a typical piece of DNA from an eukaryote cell, the image would stretch from Dallas to Washington, D. C.! DNA is not fully stretched out inside a cell but is wound around proteins, which protect the DNA. Taken from