EEM 480 Algorithms and Complexity

jetmorebrisketSoftware and s/w Development

Aug 15, 2012 (5 years and 4 months ago)

313 views

EEM 480 Algorithms and Complexity

by

Assist. Prof. Dr. Emin Germen

What is this Course About


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

What is this Course About


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


Platforms


Classes


Encapsulation, Overloading, Inheritance, Overriding


Pointers to objects


Templates


Algoritm Analysis


Necessary math review


Complexity definitions


Running time calculations


Arrays and Linked Lists


Linear lists


Formula based representation


Linked representations


Indirect addressing and pointers


Arrays and Matrices


Arrays, Matrices, Special matrices, Sparse matrices


Stacks


Queues


Trees


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


10%


Mt 2


20%


Projects


30%


Final Exam

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


Multithreaded


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 Machine
1

(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
platforms. The API is a large collection of ready
-
made software
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


Notepad (WHHHHHAAAAAAT??????)

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.


Polymorphism Overloading

Ability to have more than one function with the same name that differ
in their parameter lists.


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


}


}

Program 1

Every program has its class

Comments

The main class is the
beginning portion of
your program

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 radius;


private float area;


public CCircle(float rad){


area = rad * rad * (float) 3.14;


print_area(area);


}


public CCircle() {


radius = (float) 20.0;


}


public void get_radius(){


String instr;


BufferedReader inputstr = new BufferedReader(


new InputStreamReader(System.in));




System.out.print("Enter the radius : ");


try {


instr = inputstr.readLine();


radius = Float.parseFloat(instr);


} catch(IOException ie) {


System.err.println("IO Exception has occured ");


}


}


public void calc_area(){


area = radius * radius * (float) 3.14;


}


public void print_area(float area) {


System.out.println(Float.toString(area));


}


public void print_area() {


calc_area();


System.out.println(Float.toString(area));


}


}

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.get_radius();


yourcircle.print_area();


mycircle.get_radius();


mycircle.print_area();


}


}

CONSTRUCTOR

POLYMORPHISM

Inheritance

public class CSphere extends CCircle {


public void display_area(){


float SphereArea;


SphereArea = (float) 4 * (float) 3.14 * getRadius()*getRadius();


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();


yourcircle.get_radius();


yourcircle.print_area();


mycircle.get_radius();


mycircle.print_area();




CSphere mysphere = new CSphere();


System.out.println("Now sphere time ");


mysphere.get_radius();


mysphere.display_area();


}


}

OOP in
Java