30
EEM 480 Algorithms and EEM 480 Algorithms and Complexity Complexity by by Assist. Prof. Dr. Emin Assist. Prof. Dr. Emin Germen Germen

EEM 480 Algorithms and Complexity

  • Upload
    avak

  • View
    93

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: EEM 480 Algorithms and Complexity

EEM 480 Algorithms and EEM 480 Algorithms and ComplexityComplexity

byby

Assist. Prof. Dr. Emin GermenAssist. Prof. Dr. Emin Germen

Page 2: EEM 480 Algorithms and Complexity

What is this Course What is this Course AboutAbout

Of Course it is about :Of Course it is about :

AlgorithmsAlgorithms

ComplexityComplexity

Page 3: EEM 480 Algorithms and Complexity

Any More?Any More?

Algorithms + Complexity = Data StructureAlgorithms + Complexity = Data Structure

Data Structure : Concerns with the Data Structure : Concerns with the representation and manipulation of data.representation and manipulation of data.

All the programs use and manipulate dataAll the programs use and manipulate data

IS (Computer Programming == Data IS (Computer Programming == Data Structure) Structure)

YES OR NOYES OR NO

Page 4: EEM 480 Algorithms and Complexity

What is Data StructureWhat is Data Structure

Designing the program which modifies Designing the program which modifies datadata

The Key PointThe Key Point

AlgorithAlgorithmm

Page 5: EEM 480 Algorithms and Complexity

What is this Course What is this Course AboutAbout

Learning and designing algorithms Learning and designing algorithms to manipulate the datato manipulate the data

Comparing criteria of different Comparing criteria of different algorithmsalgorithms

Understand what a good program isUnderstand what a good program is Learning effective utilizations of Learning effective utilizations of

computer sourcescomputer sources

Page 6: EEM 480 Algorithms and Complexity

SyllabusSyllabus Review of JAVAReview of JAVA

PlatformsPlatforms ClassesClasses Encapsulation, Overloading, Inheritance, OverridingEncapsulation, Overloading, Inheritance, Overriding Pointers to objectsPointers to objects TemplatesTemplates

Algoritm AnalysisAlgoritm Analysis Necessary math reviewNecessary math review Complexity definitionsComplexity definitions Running time calculationsRunning time calculations

Arrays and Linked ListsArrays and Linked Lists Linear listsLinear lists Formula based representationFormula based representation Linked representationsLinked representations Indirect addressing and pointersIndirect addressing and pointers

Arrays and MatricesArrays and Matrices Arrays, Matrices, Special matrices, Sparse matricesArrays, Matrices, Special matrices, Sparse matrices

StacksStacks QueuesQueues TreesTrees

Binary treesBinary trees Tree traversalsTree traversals B treesB trees

Hash TablesHash Tables Priority QueuesPriority Queues Sorting algorithmsSorting algorithms Basic Data Structure ImplementationsBasic Data Structure Implementations

Path compressionPath compression Union/Find ImplementationsUnion/Find Implementations

Review of JAVAReview of JAVA PlatformsPlatforms ClassesClasses Encapsulation, Overloading, Inheritance, OverridingEncapsulation, Overloading, Inheritance, Overriding Pointers to objectsPointers to objects TemplatesTemplates

Algoritm AnalysisAlgoritm Analysis Necessary math reviewNecessary math review Complexity definitionsComplexity definitions Running time calculationsRunning time calculations

Arrays and Linked ListsArrays and Linked Lists Linear listsLinear lists Formula based representationFormula based representation Linked representationsLinked representations Indirect addressing and pointersIndirect addressing and pointers

Arrays and MatricesArrays and Matrices Arrays, Matrices, Special matrices, Sparse matricesArrays, Matrices, Special matrices, Sparse matrices

StacksStacks QueuesQueues TreesTrees

Binary treesBinary trees Tree traversalsTree traversals B treesB trees

Hash TablesHash Tables Priority QueuesPriority Queues Sorting algorithmsSorting algorithms Basic Data Structure ImplementationsBasic Data Structure Implementations

Path compressionPath compression Union/Find ImplementationsUnion/Find Implementations

Page 7: EEM 480 Algorithms and Complexity

Reference and Reference and EvaluationEvaluation

Data Structures and Algorithm Analyses in JAVA Data Structures and Algorithm Analyses in JAVA 2’nd Ed. by Mark Allen Weiss2’nd Ed. by Mark Allen WeissPearson International Ed.Pearson International Ed.

http://http://java.sun.com/docs/white/langenvjava.sun.com/docs/white/langenv// http://java.sun.com/docs/books/tutorial/http://java.sun.com/docs/books/tutorial/

getStarted/intro/definition.htmlgetStarted/intro/definition.html

Evaluation:Evaluation: Mt 1 Mt 1 10%10% Mt 2 Mt 2 20%20% Projects Projects 30%30% Final ExamFinal Exam 40%40%

Page 8: EEM 480 Algorithms and Complexity

Object Oriented Object Oriented ProgrammingProgramming

ObjectObject ClassClass EncapsulationEncapsulation InheritanceInheritance PolymorphismPolymorphism

Page 9: EEM 480 Algorithms and Complexity

ObjectObject

An An objectobject is a bundle of is a bundle of variablesvariables and and related related methodsmethods..

When an object is mapped into software When an object is mapped into software representation, it consists of 2 parts: representation, it consists of 2 parts: DATA STRUCTURE DATA STRUCTURE

characteristics of data structure are referred characteristics of data structure are referred to as to as ATTRIBUTES ATTRIBUTES

PROCESSES that may correctly change the PROCESSES that may correctly change the data structuredata structureprocesses are referred to as processes are referred to as OPERATIONSOPERATIONS or or METHODSMETHODS

Page 10: EEM 480 Algorithms and Complexity

ClassClass A class is a blueprint for an object.A class is a blueprint for an object. Objects with the same data structure Objects with the same data structure (Attributes) (Attributes) and behavior and behavior

(Methods or Operations) (Methods or Operations) are grouped together (called a are grouped together (called a class class ). ).

Page 11: EEM 480 Algorithms and Complexity

EncapsulationEncapsulation

Encapsulation is the procedure of Encapsulation is the procedure of covering up of data and functions into covering up of data and functions into a single unit a single unit

ClassClassData1Data1Data2Data2Procedure1(Data1)Procedure1(Data1)Data2 = Procedure()Data2 = Procedure()

Encapsulation hides the Encapsulation hides the implementation away from the user implementation away from the user

Page 12: EEM 480 Algorithms and Complexity

InheritanceInheritance As objects do not exist by themselves but are As objects do not exist by themselves but are

instances of a instances of a CLASSCLASS, a class can inherit the , a class can inherit the features of another class and add its own features of another class and add its own modifications. (This could mean restrictions or modifications. (This could mean restrictions or additions to its functionality). additions to its functionality). Inheritance aids in Inheritance aids in the reuse of code.the reuse of code.

Page 13: EEM 480 Algorithms and Complexity

PolymorphismPolymorphism Polymorphism means the ability to request Polymorphism means the ability to request

that the same that the same Operations Operations be performed by be performed by a wide range of different types of things. a wide range of different types of things.

Page 14: EEM 480 Algorithms and Complexity

So What???????So What???????

What are those things????What are those things???? How can I use them???????How can I use them??????? I have searched OOP in the Internet I have searched OOP in the Internet

and find ABSTRACTION. What does and find ABSTRACTION. What does it mean????it mean????

I can write good programs using I can write good programs using structural programming techniques? structural programming techniques? Why should I use OOP?Why should I use OOP?

Page 15: EEM 480 Algorithms and Complexity

Why JAVAWhy JAVA Java technology is both a programming language Java technology is both a programming language

and a platform. and a platform. The Java programming language is a high-level The Java programming language is a high-level

language that can be characterized by all of the language that can be characterized by all of the following buzzwords: following buzzwords: SimpleSimple Architecture neutralArchitecture neutral Object orientedObject oriented PortablePortable DistributedDistributed High performanceHigh performance MultithreadedMultithreaded RobustRobust DynamicDynamic

Page 16: EEM 480 Algorithms and Complexity

How JAVA Technology How JAVA Technology worksworks

In the Java programming language, all source In the Java programming language, all source code is first written in plain text files ending with code is first written in plain text files ending with the .java extension. Those source files are then the .java extension. Those source files are then compiled into .class files by the javac compiler. A compiled into .class files by the javac compiler. A .class file does not contain code that is native to .class file does not contain code that is native to your processor; it instead contains your processor; it instead contains bytecodesbytecodes — — the machine language of the Java Virtual the machine language of the Java Virtual MachineMachine11 (Java VM). The java launcher tool then (Java VM). The java launcher tool then runs your application with an instance of the Java runs your application with an instance of the Java Virtual Machine. Virtual Machine.

Page 17: EEM 480 Algorithms and Complexity

How JAVA Technology How JAVA Technology worksworks

Page 18: EEM 480 Algorithms and Complexity

What is necessary to run What is necessary to run JAVA programsJAVA programs

The Java platform has two components: The Java platform has two components: The The Java Virtual MachineJava Virtual Machine The The Java Application Programming InterfaceJava Application Programming Interface (API) (API) You've already been introduced to the Java Virtual You've already been introduced to the Java Virtual

Machine; it's the base for the Java platform and is Machine; it's the base for the Java platform and is ported onto various hardware-based platforms. The ported onto various hardware-based platforms. The API is a large collection of ready-made software API is a large collection of ready-made software components that provide many useful capabilities. It components that provide many useful capabilities. It is grouped into libraries of related classes and is grouped into libraries of related classes and interfaces; these libraries are known as interfaces; these libraries are known as packagespackages..

Page 19: EEM 480 Algorithms and Complexity

What is necessary to run What is necessary to run JAVA programsJAVA programs

The Total Solution is JRE (?) 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

Page 20: EEM 480 Algorithms and Complexity

Where do I write my Where do I write my programsprograms Notepad Notepad

(WHHHHHAAAAAAT??????)(WHHHHHAAAAAAT??????)

Write the codeWrite the code

Compile andCompile and

RUNRUN

Compile and Run the code

Page 21: EEM 480 Algorithms and Complexity

Where do I write my Where do I write my programsprograms

Use IDE (Integrated Use IDE (Integrated DevelopmentEnvironment)DevelopmentEnvironment) NetBeans (We will use it)NetBeans (We will use it) EclipseEclipse JikesJikes JBuilder FoundationJBuilder Foundation JCreator LEJCreator LE etc. etc. etc. etc.

Page 22: EEM 480 Algorithms and Complexity

NetBeansNetBeans

Page 23: EEM 480 Algorithms and Complexity

Do PracticeDo Practice

Follow Follow http://www.netbeans.org/kb/60/java/quickhttp://www.netbeans.org/kb/60/java/quickstart.htmlstart.html

Page 24: EEM 480 Algorithms and Complexity

Intoduction to OOP with Intoduction to OOP with JAVAJAVA

Object Oriented ProgrammingObject Oriented Programming ClassClass

The structure which keeps data and functionThe structure which keeps data and function InheritanceInheritance

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 OverloadingPolymorphism OverloadingAbility to have more than one function with the same

name that differ in their parameter lists.

Page 25: EEM 480 Algorithms and Complexity

public class program1 {public class program1 {

/**/** * @param args the command line arguments* @param args the command line arguments */*/ public static void main(String[] args) {public static void main(String[] args) { System.out.println("This is my first program!");System.out.println("This is my first program!"); // TODO code application logic here// TODO code application logic here }}

}}

Program 1Program 1Every program has its class

Comments

The main class is the beginning portion of your

program

Page 26: EEM 480 Algorithms and Complexity

Program 2Program 2

Page 27: EEM 480 Algorithms and Complexity

Defining Class in Defining Class in JavaJava

Almost same as defining StructAlmost same as defining Struct in C in C languagelanguage

Insert Functions into the StructInsert Functions into the Struct Some important functions Some important functions

ConstructorConstructor Destructor (2 -3 weeks later )Destructor (2 -3 weeks later )

Page 28: EEM 480 Algorithms and Complexity

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

Page 29: EEM 480 Algorithms and Complexity

InheritanceInheritancepublic class CSphere extends CCircle {public class CSphere extends CCircle { public void display_area(){public void display_area(){ float SphereArea;float SphereArea; SphereArea = (float) 4 * (float) 3.14 * SphereArea = (float) 4 * (float) 3.14 *

getRadius()*getRadius();getRadius()*getRadius(); System.out.println(" The area of the sphere :" System.out.println(" The area of the sphere :" + Float.toString(SphereArea));+ 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();

}

}

Page 30: EEM 480 Algorithms and Complexity

OOP in OOP in JavaJava