์•Œ๊ณ ๋ฆฌ์ฆ˜

[Algorithm] ์ˆœ์ฐจ ํƒ์ƒ‰ (Sequential Search)

jjingle 2024. 2. 7. 15:03

์ˆœ์ฐจ ํƒ์ƒ‰ (Sequential Search) ?

- ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ ์ค‘์—์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์•„๋‚ด๋Š” ๊ฒƒ์„ ์˜๋ฏธ
- ๋ฐ์ดํ„ฐ๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ์•ž์—์„œ๋ถ€ํ„ฐ ํ•˜๋‚˜์”ฉ ๋น„๊ตํ•ด์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ๋Š” ๋ฐฉ๋ฒ•

 

 

data = list()

for num in range(10):
  data.append(randint(1, 100))  #random ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  
def sequencial(data, search_data):
  for index in range(len(data)):
    if data[index] == search_data:
      return index
  return -1
  
sequencial(data, 4)