๋ชฉ๋กbinary search (1)

YS's develop story

์ˆœ์ฐจ ํƒ์ƒ‰, ์ด์ง„ ํƒ์ƒ‰ ์ •๋ฆฌ

๐Ÿ‘ฉ‍๐Ÿ’ป ์ˆœ์ฐจ ํƒ์ƒ‰(Sequential Search)๊ณผ ์ด์ง„ ํƒ์ƒ‰(Binary Search) ์ •๋ฆฌ ๐Ÿฅ˜ ์ˆœ์ฐจ ํƒ์ƒ‰(Sequential Search) ๋ฐ์ดํ„ฐ๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ์•ž์—์„œ๋ถ€ํ„ฐ ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด์•„์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ๐Ÿ€ ์ˆœ์ฐจ ํƒ์ƒ‰ ์ฝ”๋“œ def sequentialSearch(list, search): for index in range(len(list)): if list[index] == search: return True return False โ˜˜๏ธ ์ˆœ์ฐจ ํƒ์ƒ‰ ์‹œ๊ฐ„ ๋ณต์žก๋„ ์ฐพ๊ณ ์ž ํ•˜๋Š” ๊ฐ’์ด ๋ฆฌ์ŠคํŠธ์˜ ๋งจ ๋งˆ์ง€๋ง‰์— ์žˆ์„ ๋•Œ, ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๋งŒํผ ๋ฐ์ดํ„ฐ๋ฅผ ๋น„๊ตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(n)์ž…๋‹ˆ๋‹ค. ๐Ÿณ ์ด์ง„ ํƒ์ƒ‰ (Binary Search) ํƒ์ƒ‰ํ•  ๋ฐ์ดํ„ฐ๋ฅผ ์ •ํ™•ํžˆ ๋ฐ˜์œผ๋กœ ๋‚˜๋ˆ„์–ด ํ•œ์ชฝ์—..

Algorithm 2021. 8. 1. 09:18