ALG ppt

Similar documents
アルゴリズムとデータ構造1

アルゴリズムとデータ構造1

アルゴリズムとデータ構造1

ALG ppt

untitled

Microsoft Word - NonGenTree.doc

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

Java演習(4) -- 変数と型 --

新・明解Java入門

目的 泡立ち法を例に Comparableインターフェイスの実装 抽象クラスの利用 型パラメタの利用 比較 入替 の回数を計測

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

VB.NETコーディング標準

Microsoft PowerPoint - kougi10.ppt

問題1 以下に示すプログラムは、次の処理をするプログラムである

ALG ppt

Microsoft Word - NonGenList.doc

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

55 7 Java C Java TCP/IP TCP/IP TCP TCP_RO.java import java.net.*; import java.io.*; public class TCP_RO { public static void main(string[] a

ALG2012-A.ppt

PowerPoint Presentation

tkk0408nari

JAVA とテンプレート

226

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

intra-mart Accel Platform — イベントナビゲータ 開発ガイド   初版   None

ALG2012-C.ppt

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

Java学習教材

ALG2012-F.ppt

: : : TSTank 2

Microsoft PowerPoint ppt

untitled

「Android Studioではじめる 簡単Androidアプリ開発」正誤表

K227 Java 2

intra-mart Accel Platform — イベントナビゲータ 開発ガイド   初版  

8 if switch for while do while 2

Thread

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

untitled

ジョインポイント写像に基づく ドメイン特化AO機構の開発手法

** 平成 16 年度 FE 午後問題 Java** 示現塾プロジェクトマネージャ テクニカルエンジニア ( ネットワーク ) など各種セミナーを開催中!! 開催日 受講料 カリキュラム等 詳しくは 今すぐアクセス!! 平成 16

Q&A集

presen.gby

1. はじめに 二分木ヒープ 様々なアルゴリズムにおいて ある要素の集合またはリストから 最小 な要素を取り 出す必要がある そのような場合に使われる標準的データ構造が二分木ヒープ (binary heap) である あるオブジェクトO を考える そのオブジェクトは ラベル O. label と値

解きながら学ぶJava入門編

r02.dvi

ohp02.dvi

手書認識 グラフ描画 Step2-2 手書認識 : 認識結果を PaintPanel で描画する < 属性付き文字列 AttributedString> 標準出力では分かりにくいうえに認識結果を使えないので 認識するごとに PaintPanel に文字を描画することにする ここで 数式はただの文字列


明解Javaによるアルゴリズムとデータ構造

アプレットの作成

2. データ構造ヒープに保存するデータは 番号付けられて保存される 従って リスト L として保存することとする 3. アルゴリズム 3.1. 要素の追加新しい要素の追加は リストの終端に置くことで開始する つまり 最下層の一番右 または新たに最下層を生成してその一番左となる この後 この要素を正し

10K pdf

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

SystemC言語概論


GIMP import javafx.application.application; import javafx.scene.scene; import javafx.scene.canvas.canvas; import javafx.scene.canvas.graphicscontext;

untitled

GUIプログラムⅣ

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

二分木ヒープとは 集合 リストから 最小な 要素を取り出す 二分木ヒープは そのための標準的データ構造 二分木ヒープを保存するデータ構造 二分木ヒープの操作のメソッド 対象となるデータクラス 識別のためのlabelフィールド 値を保持するvalueフィールド

H:\Projects2013\MatrixLibrary\MatrixLibrary\MatrixLibrary.cs /* ************************ * * * 行列関係のライブラリ * * * ************************ * * 行列の要素 A.V

LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP : 1

intra-mart Accel Platform — IM-Repository拡張プログラミングガイド   初版  

PowerPoint Presentation

グラフの探索 JAVA での実装

java_servlet2_見本

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav


A B 1: Ex. MPICH-G2 C.f. NXProxy [Tanaka] 2:

I java A

S2DaoでもN:Nできます

JavaCard p.1/41

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

Quick Sort 計算機アルゴリズム特論 :2017 年度 只木進一

動的なデザインパターン

Java (5) 1 Lesson 3: x 2 +4x +5 f(x) =x 2 +4x +5 x f(10) x Java , 3.0,..., 10.0, 1.0, 2.0,... flow rate (m**3/s) "flow

Java - Visual Editor

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

LogisticaTRUCKServer-Ⅱ距離計算サーバ/Active-Xコントロール/クライアント 概略   

TopLink È... 3 TopLink...5 TopLink åø... 6 TopLink å Workbench O/R ~... 8 Workbench À ~... 8 Foundation Library å... 8 TopL

基礎計算機演習 実習課題No6

r3.dvi

2018年度「プログラミング言語」配布資料 (10)

Client client = ClientBuilder.newClient(); WebTarget webtarget = client.target(" " "); Invo

Dolteng Scaffoldに対する機能追加とマスタ-ディテールScaffoldの紹介



2016 VOCALOID Group, Yamaha Corporation 2

(Java/FX ) Java CD Java version Java VC++ Python Ruby Java Java Eclipse Java Java 3 Java for Everyone 2 10 Java Midi Java JavaFX Shape Canvas C

課題

1_cover

Q&A集

Java updated

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲


Transcription:

2012614 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2012/index.html 1

2

2 3

29 20 32 14 24 30 48 7 19 21 31 4

N O(log N) 29 O(N) 20 32 14 24 30 48 7 19 21 31 5

48 32 N O(log N) 30 31 O(N) 24 29 21 19 20 14 7 6

interface Comparable compareto() public int compareto(object o) this public class MyData implements Comparable { public MyData(int anid, Object adata) { this.id = anid; this.data = adata; public int compareto(object atarget) { int targetid = ((MyData)aTarget).getId(); if(this.id == targetid){ return 0; if(this.id > targetid){ return 1; return -1; public Object getdata() { return this.data; public int getid() { return (this.id); public String tostring() { return "(" + this.id + "'" + this.data + ")"; private Object data; // private int id; // 7

public class MyNode { public MyNode(MyData adata) { this.data = adata; public MyData getdata() { return this.data; public MyNode getleft() { return this.left; public MyNode getright() { return this.right; public void setleft(mynode anode) { this.left = anode; public void setright(mynode anode) { this.right = anode; public String tostring() { MyData leftdata = null; MyData rightdata = null; if(null!= this.left){ leftdata = this.left.getdata(); if(null!= this.right){ rightdata = this.right.getdata(); return ("{"+leftdata+","+this.data+","+rightdata+""); private MyData data; private MyNode left; private MyNode right; 8

(73) 29 17 29 17 20 17 20 32 14 17 14 24 30 48 7 19 21 31 19 17 17 9

public class BinarySearchTree { public BinarySearchTree() { this.root = null; private MyNode root; public void insert(mydata adata) { MyNode newnode = new MyNode(aData); if(null == this.root){ this.root = newnode; return; MyNode currentnode = this.root; while(true){ if(0 < currentnode.getdata().compareto(adata)){ if(null == currentnode.getleft()){ currentnode.setleft(newnode); return; currentnode = currentnode.getleft(); else{ if(null == currentnode.getright()){ currentnode.setright(newnode); return; currentnode = currentnode.getright(); 10

public MyNode search(mydata adata) { if(null == this.root){ return null; MyNode currentnode = this.root; while(true){ if(0 == currentnode.getdata().compareto(adata)){ return currentnode; if(0 < currentnode.getdata().compareto(adata)){ if(null == currentnode.getleft()){ return null; currentnode = currentnode.getleft(); else{ if(null == currentnode.getright()){ return null; currentnode = currentnode.getright(); 11

Tail Recursion () public MyNode searchrecursive(mydata adata) { return searchr(adata, this.root); private MyNode searchr(mydata adata, MyNode aroot) { if(null == aroot){ // () return null; int result = aroot.getdata().compareto(adata); if(0 == result){ // return aroot; return searchr(adata, (0 < result)? aroot.getleft(): aroot.getright()); 12

29 20 32 14 24 30 48 7 19 21 31 13

public boolean remove(mydata adata) { if(null == this.root){ return false; MyNode parentnode = this.root; MyNode currentnode = this.root; boolean inleftsubtree = false; while(0!= currentnode.getdata().compareto(adata)){ parentnode = currentnode; if(0 < currentnode.getdata().compareto(adata)){ currentnode = currentnode.getleft(); inleftsubtree = true; else{ currentnode = currentnode.getright(); inleftsubtree = false; if(null == currentnode){ return false; /* / currentnode.setleft(null); currentnode.setright(null); return true; 14

if((null == currentnode.getleft()) && (null == currentnode.getright())){ if(currentnode == this.root){ this.root = null; else if(inleftsubtree){ parentnode.setleft(null); else{ parentnode.setright(null); else if(null == currentnode.getright()){ if(currentnode == this.root){ this.root = currentnode.getleft(); else if(inleftsubtree){ parentnode.setleft(currentnode.getleft()); else{ parentnode.setright(currentnode.getleft()); else if(null == currentnode.getleft()){ if(currentnode == this.root){ this.root = currentnode.getright(); else if(inleftsubtree){ parentnode.setleft(currentnode.getright()); else{ parentnode.setright(currentnode.getright()); /* */ 15

29 20 32 14 24 30 48 7 19 21 31 16

else{ MyNode minimumnode = this.getminimumnode(currentnode.getright()); this.remove(minimumnode.getdata()); minimumnode.setleft(currentnode.getleft()); minimumnode.setright(currentnode.getright()); if(currentnode == this.root){ this.root = minimumnode; else if(inleftsubtree){ parentnode.setleft(minimumnode); else{ parentnode.setright(minimumnode); 1. () 2. private MyNode getminimumnode(mynode alocalrootnode){ if(null == alocalrootnode){ return null; MyNode currentnode = alocalrootnode; while(true){ if(null == currentnode.getleft()){ return currentnode; currentnode = currentnode.getleft(); 17

(pre-order) 1. 2. 3. 14 24 29 20 32 public void printtreepreorder() { System.out.println(this.traversePreOrder(this.root)); 30 private String traversepreorder(mynode alocalrootnode) { if(null == alocalrootnode){ return ""; 7 19 21 31 StringBuffer treerepresentation = new StringBuffer(); treerepresentation.append(alocalrootnode + System.getProperty("line.separator")); treerepresentation.append(this.traversepreorder(alocalrootnode.getleft())); treerepresentation.append(this.traversepreorder(alocalrootnode.getright())); return treerepresentation.tostring(); 18 48

(in-order) 1. 2. 3. 14 24 29 20 32 private String traverseinorder(mynode alocalrootnode) { if(null == alocalrootnode){ return ""; StringBuffer treerepresentation 7 = new 19 StringBuffer(); 21 31 treerepresentation.append(this.traverseinorder(alocalrootnode.getleft())); treerepresentation.append(alocalrootnode +System.getProperty("line.separator")); treerepresentation.append(this.traverseinorder(alocalrootnode.getright())); return treerepresentation.tostring(); 19 30 48

(post-order) 1. 2. 3. 29 14 20 32 public void printtreepostorder() { System.out.println(this.traversePostOrder(this.root)); 24 30 private String traversepostorder(mynode alocalrootnode) { if(null == alocalrootnode){ return ""; 7 19 21 31 StringBuffer treerepresentation = new StringBuffer(); treerepresentation.append(this.traversepostorder(alocalrootnode.getleft())); treerepresentation.append(this.traversepostorder(alocalrootnode.getright())); treerepresentation.append(alocalrootnode + System.getProperty("line.separator")); return treerepresentation.tostring(); 20 48