Abstraction and Abstract Data Types



Similar documents
Section IV.1: Recursive Algorithms and Recursion Trees

Sample Questions Csci 1112 A. Bellaachia

Conditionals (with solutions)

Stacks. Linear data structures

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

1.3 Algebraic Expressions

Lesson 3.1 Factors and Multiples of Whole Numbers Exercises (pages )

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

Accentuate the Negative: Homework Examples from ACE

Fractions and Linear Equations

Data Structures and Algorithms

Data Structures and Algorithms Lists

So let us begin our quest to find the holy grail of real analysis.

CS170 Lab 11 Abstract Data Types & Objects

Training Manual. Pre-Employment Math. Version 1.1

THE BINARY NUMBER SYSTEM

In this Chapter you ll learn:

Chapter 2: Elements of Java

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

The Interface Concept

COLLEGE ALGEBRA 10 TH EDITION LIAL HORNSBY SCHNEIDER 1.1-1

J a v a Quiz (Unit 3, Test 0 Practice)

Algebra Practice Problems for Precalculus and Calculus

COMPSCI 210. Binary Fractions. Agenda & Reading

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Ordered Lists and Binary Trees

Sect Least Common Multiple

RULE 1: Additive Identity Property

TECHNICAL UNIVERSITY OF CRETE DATA STRUCTURES FILE STRUCTURES

Data Structures and Algorithms

COMPUTER SCIENCE. Paper 1 (THEORY)

Recursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.

CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association

Supplemental Worksheet Problems To Accompany: The Pre-Algebra Tutor: Volume 1 Section 9 Order of Operations

Adding and Subtracting Positive and Negative Numbers

FRACTIONS COMMON MISTAKES

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Chapter 8: Bags and Sets

Definition 8.1 Two inequalities are equivalent if they have the same solution set. Add or Subtract the same value on both sides of the inequality.

Algorithms and Data Structures

Compiler Construction

Properties of Real Numbers

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Online EFFECTIVE AS OF JANUARY 2013

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Chapter 2: Linear Equations and Inequalities Lecture notes Math 1010

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Factoring Polynomials

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

12-6 Write a recursive definition of a valid Java identifier (see chapter 2).

Linear Equations in One Variable

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

Unit 6. Loop statements

3 cups ¾ ½ ¼ 2 cups ¾ ½ ¼. 1 cup ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼

FRACTIONS OPERATIONS

1 Abstract Data Types Information Hiding

Grade 7/8 Math Circles Fall 2012 Factors and Primes

4.1. COMPLEX NUMBERS

Software Engineering Techniques

Calculation Policy Fractions

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Chapter 8 Integers 8.1 Addition and Subtraction

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Continued Fractions and the Euclidean Algorithm

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright /6/11 12:33 PM!

Preliminary Mathematics

Part I. Multiple Choice Questions (2 points each):

Paramedic Program Pre-Admission Mathematics Test Study Guide

1.4. Arithmetic of Algebraic Fractions. Introduction. Prerequisites. Learning Outcomes

Adding and Subtracting Fractions. 1. The denominator of a fraction names the fraction. It tells you how many equal parts something is divided into.

Example of a Java program

Number Representation

Lecture 12: Abstract data types

Activity 1: Using base ten blocks to model operations on decimals

26 Integers: Multiplication, Division, and Order

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Chapter 7D The Java Virtual Machine

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Algebra Cheat Sheets

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

The resulting tile cannot merge with another tile again in the same move. When a 2048 tile is created, the player wins.

CONTENTS 1. Peter Kahn. Spring 2007

Fibonacci Numbers and Greatest Common Divisors. The Finonacci numbers are the numbers in the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,...

Fractions to decimals

Section 4.1 Rules of Exponents

Numerator Denominator

Boolean Algebra Part 1

Transcription:

Abstraction and Abstract Data Types Abstraction: o Whatever is visible to the user? Examples: Variable names & real numbers. o How real numbers are implemented? o How arrays are implemented? The abstraction is rectangular arrays The implementation is one-dimensional array. Given the following algorithm: S = set of persons. X in S; smallest-age = X; S = S-{X; While S is not empty do Y in S; S = S-{Y; If age(y) < age(x) Then smallest = Y; Endwhile; o What do you need to implement such a problem? ADT, A. Bellaachia Page 1

o For a given implementation, we need to make the following assumptions: 1. The data we are dealing with are of some data types. 2. A construct to store the data types: Data Structures 3. The set of operations on the data types defined in(1). o (1) & (3) =====> Abstract Data Types (ADT). o (2) =====> A way to implement the ADT. Data Types: (1) o Definition: The data type of a variable determines the set of values the variable can take. o Simple data types: Integer, real, character, enumeration types, etc. o Structured data types: arrays, records, files, and sets. Data Structures: (2) o Definition: A data structure (D. S.) is a construct that you can define within a programming language to store a collection of data types. Examples: o All structured data types are D.S. o Trees, Linked lists, etc. ADT, A. Bellaachia Page 2

Abstract Data Types (ADT): (3) o Definition: An abstract data type (ADT) is characterized by the following properties: - It exports a type, called domain. - It exports a set of operations. This set is called interface. - Operations of the interface are the one and only access mechanism to the type's data structure. - Axioms and preconditions define the application domain of the type. ADT Data Types Interface: Operations - The first property allows the creation of more than one instance of an ADT object. - The second property defines the only possible operations on the ADT object. - The third property prevents using other operations different from the ones defined in the interface. - Finally, the application domain is defined by the semantical meaning of provided operations. Axioms and preconditions include statements such as: o The denominator of a fraction is different from zero. o An empty list is a list.' ADT, A. Bellaachia Page 3

OOP and ADT: o A class is an actual representation of an ADT. o It provides implementation details for the data structure used and operations. o OOP supports the implementation of an ADT using information hiding. o Information hiding is used to hide the implementation details Prevent users from directly accessing data members (private access modifier). ADT, A. Bellaachia Page 4

Example: o ADT: Fraction Data type: - numerator: integer; - denominator: integer; Data structure: data types Operations: - Add, multiply, equal, reduce, divide, etc. Axioms and preconditions: - The denominator should be different from zero. o Java Implementation: //Fraction ADT public class Fraction { private int numerator; private int denominator; public Fraction(){ numerator = 0; denominator = 1; public Fraction(int num, int deno){ numerator = num; denominator = deno; if (denominator == 0){ throw new IllegalArgumentException("Denominator cannot be zero"); public void reducef(){ int n = numerator; int d = denominator; while (d!= 0) { int t = d; d = n % d; n = t; numerator /= n; denominator /= n; ADT, A. Bellaachia Page 5

public int getnumerator() { return this.numerator; public int getdenominator() { return this.denominator; public Fraction add(fraction f1, Fraction f2){ Fraction f = new Fraction(); f.numerator = f1.numerator * f2.denominator + f1.denominator * f2.numerator; f.denominator = f1.denominator * f2.denominator; f.reducef(); return(f); public Fraction sub(fraction f1, Fraction f2){ //Implement this function. public Fraction multiply(fraction f1, Fraction f2){ //Implement this function. public Fraction divide (Fraction f1, Fraction f2){ //Implement this function. public boolean equals(fraction f2){ return getnumerator()*f2.getdenominator() == f2.getnumerator()*getdenominator(); public void printf(fraction f){ System.out.println (f.numerator + "/" + f.denominator) ; o Programming Assignment: Design and implement the missing operations in the Fraction ADT: - Subtraction: - Multiplication: - Division a + c b d Test your implementation. a c = ac b d bd = ad + bc bd a c = ad b d bc ADT, A. Bellaachia Page 6