#### Transcript EEM 480 Algorithms and Complexity

```EEM 480 Algorithms and Complexity
by
Assist. Prof. Dr. Emin Germen

Of Course it is about :
Algorithms
Complexity
Any More?
Algorithms + Complexity = Data Structure
Data Structure : Concerns with the representation
and manipulation of data.
All the programs use and manipulate data
IS (Computer Programming == Data Structure)
YES OR NO
What is Data Structure
Designing the program which modifies data
The Key Point
Algorithm




Learning and designing algorithms to
manipulate the data
Comparing criteria of different algorithms
Understand what a good program is
Learning effective utilizations of computer
sources
Syllabus

Review of JAVA






Algoritm Analysis














Arrays, Matrices, Special matrices, Sparse matrices
Stacks
Queues
Trees


Linear lists
Formula based representation
Arrays and Matrices


Necessary math review
Complexity definitions
Running time calculations


Platforms
Classes
Pointers to objects
Templates
Binary trees
Tree traversals
B trees
Hash Tables
Priority Queues
Sorting algorithms
Basic Data Structure Implementations


Path compression
Union/Find Implementations
Reference and Evaluation




Data Structures and Algorithm Analyses in JAVA 2’nd Ed. by
Mark Allen Weiss
Pearson International Ed.
http://java.sun.com/docs/white/langenv/
http://java.sun.com/docs/books/tutorial/getStarted/intro/defi
nition.html
Evaluation:




Mt 1
Mt 2
Projects
Final Exam
10%
20%
30%
40%
Object Oriented Programming





Object
Class
Encapsulation
Inheritance
Polymorphism
Object


An object is a bundle of variables and related
methods.
When an object is mapped into software representation,
it consists of 2 parts:


DATA STRUCTURE
characteristics of data structure are referred to as
ATTRIBUTES
PROCESSES that may correctly change the data structure
processes are referred to as OPERATIONS or METHODS
Class


A class is a blueprint for an object.
Objects with the same data structure (Attributes) and behavior
(Methods or Operations) are grouped together (called a class ).
Encapsulation
Encapsulation is the procedure of covering up
of data and functions into a single unit
Class

Data1
Data2
Procedure1(Data1)
Data2 = Procedure()

Encapsulation hides the implementation away
from the user
Inheritance

As objects do not exist by themselves but are instances
of a CLASS, a class can inherit the features of another
class and add its own modifications. (This could mean
restrictions or additions to its functionality). Inheritance
aids in the reuse of code.
Polymorphism

Polymorphism means the ability to request that
the same Operations be performed by a wide
range of different types of things.
So What???????




What are those things????
How can I use them???????
I have searched OOP in the Internet and find
ABSTRACTION. What does it mean????
I can write good programs using structural
programming techniques? Why should I use
OOP?
Why JAVA


Java technology is both a programming language and a platform.
The Java programming language is a high-level language that can
be characterized by all of the following buzzwords:









Simple
Architecture neutral
Object oriented
Portable
Distributed
High performance
Robust
Dynamic
How JAVA Technology works

In the Java programming language, all source code is first written
in plain text files ending with the .java extension. Those source
files are then compiled into .class files by the javac compiler. A
.class file does not contain code that is native to your processor;
it instead contains bytecodes — the machine language of the Java
Virtual Machine1 (Java VM). The java launcher tool then runs
your application with an instance of the Java Virtual Machine.
How JAVA Technology works
What is necessary to run JAVA
programs




The Java platform has two components:
The Java Virtual Machine
The Java Application Programming Interface (API)
You've already been introduced to the Java Virtual Machine; it's the
base for the Java platform and is ported onto various hardware-based
components that provide many useful capabilities. It is grouped into
libraries of related classes and interfaces; these libraries are known as
packages.
What is necessary to run JAVA
programs

The Total Solution is JRE (?)
The Java Runtime Environment (JRE) is a set of library files and the java executable
that is kicked off in order to run any java program.
The Java Virtual Machine (JVM) is created, like a separate program, whenever a java
program is executed. The JVM essentially runs between the computer and the java
program. Java is designed so that any java program can run on any machine. This is
because the JVM will interpret the Operating System independent java code and
execute the commands needed for the particular Operating System you are trying to
run the program on at the time.
Java Program --- Execute some command ---> JVM --- Translate the command for
this computer ---> Computer
Where do I write my programs
Write the code
Compile and
RUN

Compile and Run the code
Where do I write my programs

Use IDE (Integrated DevelopmentEnvironment)
NetBeans (We will use it)
 Eclipse
 Jikes
 JBuilder Foundation
 JCreator LE
 etc. etc.

NetBeans
Do Practice

Follow
http://www.netbeans.org/kb/60/java/quickstart.html
Intoduction to OOP with JAVA

Object Oriented Programming

Class
The structure which keeps data and function


Inheritance
Inheritance is also called derivation. The new class inherits
the functionality of an existing class. The existing class is
called the base class, and the new class is called the derived
class. A similar inheritance can be derived for animals,
mammals, and dogs.
Ability to have more than one function with the same name that differ
in their parameter lists.
Program 1
Every program has its class
public class program1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("This is my first program!");
// TODO code application logic here
}
}
The main class is the
beginning portion of
Program 2
Defining Class in Java



Almost same as defining Struct in C language
Insert Functions into the Struct
Some important functions
Constructor
 Destructor (2 -3 weeks later )

public class CCircle {
private float area;
print_area(area);
}
public CCircle() {
}
String instr;
CONSTRUCTOR
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
CCircle mycircle = new CCircle(10);
CCircle yourcircle = new CCircle();
yourcircle.print_area();
mycircle.print_area();
}
try {
} catch(IOException ie) {
System.err.println("IO Exception has occured ");
}
}
public void calc_area(){
}
public void print_area(float area) {
System.out.println(Float.toString(area));
}
public void print_area() {
calc_area();
System.out.println(Float.toString(area));
}
}
}
POLYMORPHISM
Inheritance
public class CSphere extends CCircle {
public void display_area(){
float SphereArea;
System.out.println(" The area of the sphere :"
+ Float.toString(SphereArea));
}
}
public static void main(String[] args) {
CCircle mycircle = new CCircle(10);
CCircle yourcircle = new CCircle();