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

Similar documents
( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

O(N) ( ) log 2 N

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

double float

新・明解Javaで学ぶアルゴリズムとデータ構造

main

Taro-最大値探索法の開発(公開版

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

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

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

Java

超初心者用

a n a n ( ) (1) a m a n = a m+n (2) (a m ) n = a mn (3) (ab) n = a n b n (4) a m a n = a m n ( m > n ) m n 4 ( ) 552

untitled

解きながら学ぶC++入門編

Taro-再帰関数Ⅱ(公開版).jtd

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v


() / (front end) (back end) (phase) (pass) 1 2

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

C言語によるアルゴリズムとデータ構造

untitled

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

ALG ppt

( ) ( ) lex LL(1) LL(1)

Microsoft PowerPoint - 5.pptx

本文/扉1

プログラム


平成20年5月 協会創立50年の歩み 海の安全と環境保全を目指して 友國八郎 海上保安庁 長官 岩崎貞二 日本船主協会 会長 前川弘幸 JF全国漁業協同組合連合会 代表理事会長 服部郁弘 日本船長協会 会長 森本靖之 日本船舶機関士協会 会長 大内博文 航海訓練所 練習船船長 竹本孝弘 第二管区海上保安本部長 梅田宜弘

Program

aphp37-11_プロ1/ky869543540410005590


日本内科学会雑誌第96巻第11号

Œ{Ł¶/1ŒÊ −ªfiª„¾ [ 1…y†[…W ]

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

PowerPoint Presentation

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –


PDF

( ) FAS87 FAS FAS87 v = 1 i 1 + i

C B

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

BW BW


01

Taro-2分探索木Ⅱ(公開版).jtd

PowerPoint プレゼンテーション

P05.ppt

ランダムウォークの確率の漸化式と初期条件

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

Taro-リストⅢ(公開版).jtd

:30 12:00 I. I VI II. III. IV. a d V. VI

DA13

tuat1.dvi

:30 12:00 I. I VI II. III. IV. a d V. VI

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

PowerPoint プレゼンテーション

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D



UX-V503CL/UX-V503CW

Microsoft PowerPoint - algo ppt [互換モード]

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

comment.dvi

新・明解C言語 ポインタ完全攻略

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

I J

‚æ2›ñ C„¾„ê‡Ìš|

Microsoft Word - 13


P06.ppt

DF-200

橡Pro PDF

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

Battle Ship

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

新版明解C言語 実践編

Microsoft Word - no15.docx

I 2 tutimura/ I 2 p.1/??

Microsoft Word - 第5回 基本データ構造2(連結リスト).doc

Taro-2分探索木Ⅰ(公開版).jtd

‚æ4›ñ

Microsoft Word - Cプログラミング演習(10)

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

Condition DAQ condition condition 2 3 XML key value

thesis.dvi

Microsoft PowerPoint - kougi10.ppt

2017 p vs. TDGL 4 Metropolis Monte Carlo equation of continuity s( r, t) t + J( r, t) = 0 (79) J s flux (67) J (79) J( r, t) = k δf δs s( r,

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

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

さくらの個別指導 ( さくら教育研究所 ) a a n n A m n 1 a m a n = a m+n 2 (a m ) n = a mn 3 (ab) n = a n b n a n n = = 3 2, = 3 2+

新・明解C言語 実践編

Transcription:

2005 11 14 1 1.1 2 1.2 (search:) [1] () 2 (linear search) (sequential search) 1

2.1 2.1.1 List 2-1(p.37) 1 1 13 n<num&&a[n]!=x n () n/2 n O(n) 2.1.2 List 2-1(p.37) 1 1 2

1: 2.1.3 1 List 2-1(p.37-38) 3

1: 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 #define NOT FOUND ( 1) 6 #define N ( 1 0 ) 7 8 int l i n e a r s e a r c h ( int x, int a, int num) 9 { 10 int n=0; 11 12 / / 13 while ( n<num&&a [ n ]!= x ) 14 n++; 15 16 i f ( n<num) 17 return n ; 18 19 return NOT FOUND; 20 } 21 22 int main ( void ) 23 { 24 int i, r, array [N ] ; 25 26 srand ( ( unsigned int ) time (NULL) ) ; 27 28 / / 29 p r i n t f ( array ) ; 30 for ( i =0; i <N; i ++) 31 p r i n t f ( [%d ]:% d, i, array [ i ]= rand ()%20); 32 33 p r i n t f ( \ n : ) ; 34 s c a n f ( %d,& i ) ; 35 36 r=l i n e a r s e a r c h ( i, array,n) ; 37 38 i f ( r==not FOUND) 39 p r i n t f ( % d \n, i ) ; 40 else 41 p r i n t f ( %d %d \n, i, r ) ; 42 43 return EXIT SUCCESS ; 44 } 2.2 2.2.1 1 1 13 2 (n<num a[n]!=x) () n<num a[n]!=x] 4

O(n) 2.2.2 List 2-2(p.38-39) 2 2 5

2: 2.2.3 2 List 2-2(p.38-39) 6

2: 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 #define NOT FOUND ( 1) 6 #define N ( 1 0 ) 7 8 int s e a r c h ( int x, int a, int num) 9 { 10 int n=0, t ; 11 12 / x / 13 t=a [ num 1]; 14 a [ num 1]=x ; 15 16 / / 17 while ( a [ n ]!= x ) 18 n++; 19 20 a [ num 1]= t ; / / 21 i f ( n<num 1) 22 return n ; / / 23 i f ( x==t ) 24 return n ; / / 25 26 return NOT FOUND; 27 } 28 29 int main ( void ) 30 { 31 int i, r, array [N ] ; 32 33 srand ( ( unsigned int ) time (NULL) ) ; 34 35 / / 36 p r i n t f ( array ) ; 37 for ( i =0; i <N; i ++) 38 p r i n t f ( [%d ]:% d, i, array [ i ]= rand ()%20); 39 40 p r i n t f ( \ n : ) ; 41 s c a n f ( %d,& i ) ; 42 43 r=s e a r c h ( i, array,n) ; 44 i f ( r==not FOUND) 45 p r i n t f ( % d \n, i ) ; 46 else 47 p r i n t f ( %d %d \n, i, r ) ; 48 49 return EXIT SUCCESS ; 50 } 3 7

1/2 1 1 n/2 1 3.1 3.1.1 [left, right] a[left] a[right] n a[0] a[n-1] [0, n 1] mid = (left + right)/2 x a[mid] x x mid a[mic] x [mid + 1, right] x a[mic] x [left, mid 1] x 1 3 12 22 1/2 α 1 n ( ) α 1 n = 1 (1) 2 α α = log 2 n (2) O(log 2 n) 3.1.2 List 2-3(p.41-42) 3 3 8

3: 9

3.1.3 3 List 2-3(p.41-42) 3: 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 #define NOT FOUND ( 1) 6 #define N ( 1 0 ) 7 8 int b i n a r y s e a r c h ( int x, int a, int l e f t, int r i g h t ) 9 { 10 int mid ; 11 12 while ( l e f t <=r i g h t ) 13 { 14 mid=( l e f t+r i g h t ) / 2 ; 15 i f ( a [ mid]==x ) 16 return mid ; 17 18 i f ( a [ mid]<x ) 19 l e f t=mid+1; / m i d x / 20 else 21 r i g h t=mid 1; / m i d x / 22 } 23 24 / / 25 return NOT FOUND; 26 } 27 28 int main ( void ) 29 { 30 int i, r, array [N ] ; 31 32 srand ( ( unsigned int ) time (NULL) ) ; 33 34 / / 35 p r i n t f ( array ) ; 36 p r i n t f ( [ 0 ] : % d, array [0]= rand ( ) %3); 37 for ( i =1; i <N; i ++) 38 p r i n t f ( [%d ]:% d, i, array [ i ]= array [ i 1]+rand ()%3); 39 40 p r i n t f ( \ n : ) ; 41 s c a n f ( %d,& i ) ; 42 43 r=b i n a r y s e a r c h ( i, array, 0,N 1); 44 45 i f ( r==not FOUND) 46 p r i n t f ( % d \n, i ) ; 47 else 48 p r i n t f ( %d %d \n, i, r ) ; 49 50 return EXIT SUCCESS ; 51 } 10

3.2 3.2.1 3 3 4 3.2.2 List 2-4(p.44-45) 4 4 11

4: 12

3.2.3 4 List 2-4(p.44-45) 4: 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 #define NOT FOUND ( 1) 6 #define N ( 1 0 ) 7 8 int b i n a r y s e a r c h ( int x, int a, int l e f t, int r i g h t ) 9 { 10 int mid ; 11 12 while ( l e f t <r i g h t ) 13 { 14 mid=( l e f t+r i g h t ) / 2 ; 15 i f ( a [ mid]<x ) 16 l e f t=mid+1; 17 else 18 r i g h t=mid ; 19 } 20 i f ( a [ l e f t ]==x ) 21 return l e f t ; 22 23 / / 24 return NOT FOUND; 25 } 26 27 int main ( void ) 28 { 29 int i, r, array [N ] ; 30 31 srand ( ( unsigned int ) time (NULL) ) ; 32 33 / / 34 p r i n t f ( array ) ; 35 p r i n t f ( [ 0 ] : % d, array [0]= rand ( ) %3); 36 for ( i =1; i <N; i ++) 37 p r i n t f ( [%d ]:% d, i, array [ i ]= array [ i 1]+rand ()%3); 38 39 p r i n t f ( \ n : ) ; 40 s c a n f ( %d,& i ) ; 41 42 r=b i n a r y s e a r c h ( i, array, 0,N 1); 43 44 i f ( r==not FOUND) 45 p r i n t f ( % d \n, i ) ; 46 else 47 p r i n t f ( %d %d \n, i, r ) ; 48 49 return EXIT SUCCESS ; 50 } 13

4 4.1 4.1.1 752 778 608 239 956 244 535 840 629 353 [ 1] 1 535 [ 2] 1 643 [ 3] 2 535 [ 4] 2 643 4.1.2 239 244 353 535 608 629 752 752 752 956 [ 1] 3 650 [ 2] 3 752 [ 3] 4 650 [ 4] 4 752 4.2 11 21 ( ) AM 10:40 A4 1 2E 2 14

[1].. ( ), 2004. 15