728x90

https://www.reddit.com/r/leetcode/comments/w26u7o/could_someone_please_explain_the_difference_in/ https://www.reddit.com/r/MLQuestions/comments/wz7s5h/can_someone_explain_time_complexity_and_what_doe/

 

r/MLQuestions on Reddit: Can someone explain time complexity and what doe sit has to do with data structures like LinkedList and

Posted by u/Important-Asparagus9 - 1 vote and 4 comments

www.reddit.com

 

Could someone please explain the difference in run time? : r/leetcode

 

www.reddit.com

Time Complexity

- ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„๊ณผ ์ž…๋ ฅ์˜ ํ•จ์ˆ˜ ๊ด€๊ณ„๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค.

์ปดํ“จํ„ฐ๊ณผํ•™์—์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ์ž…๋ ฅ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด ๊ธธ์ด์˜ ํ•จ์ˆ˜๋กœ์„œ ์ž‘๋™ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ทจํ•ด ์‹œ๊ฐ„์„ ์ •๋Ÿ‰ํ™”ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ์ฃผ๋กœ ๋น…-์˜ค ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ์ด ๋น…-์˜ค ํ‘œ๊ธฐ๋ฒ•์€ ๊ณ„์ˆ˜์™€ ๋‚ฎ์€ ์ฐจ์ˆ˜์˜ ํ•ญ์„ ์ œ์™ธ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ ํ‘œํ˜„ํ•  ๋•Œ, (์˜ˆ๋ฅผ ๋“ค๋ฉด, ์ž…๋ ฅ ํฌ๊ธฐ๋ฅผ ๋ฌดํ•œ๋Œ€๋กœ ์ž…๋ ฅํ•˜์—ฌ) ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์ ๊ทผ์ ์œผ๋กœ ๋ฌ˜์‚ฌํ•œ๋‹ค๊ณ  ๋งํ•œ๋‹ค. (wiki)

 

Time complexity is how long it will take a piece of code to solve a problem. This is almost always based on how much data we give the code to solve (known as n). If I ask someone how much money is in his wallet it might be a time complexity of (1) if he remembers how much he's put in there. It's time (n) if he forgot and has to count all of the bills in his wallet (and he has n of them). It's time ( n2 ) if his kids like sneaking photo copies of bills into his wallet so each one he looks at he decides to look at all the others to make sure they aren't duplicates of the one he's holding.

Time complexity in computing is looking at the code and figuring out how long it's going to take to run for an arbitrarily sized data set. We're often interested in average run time, and worst case run time.

 

* ์ง€๊ฐ‘์— ๋ˆ์ด ์–ผ๋งˆ์ธ์ง€ ๊ณ„์‚ฐํ•œ๋‹ค๋ฉด O(1), ์–ผ๋งˆ์žˆ๋Š”์ง€ ์žŠ์–ด๋ฒ„๋ ธ๋‹ค๋ฉด ๋‹ค์‹œ ์ง€๊ฐ‘์„ n๋ฒˆ(ํ™•์ธํ• ๋•Œ๋งˆ๋‹ค) ์ˆ˜ํ–‰ O(n),  ๋งŒ์•ฝ ์ง€๊ฐ‘์— ์œ„์กฐ ์ง€ํ๊ฐ€ ๋“ค์–ด ์žˆ์–ด ์ง€ํ๋ฅผ ๊ฒ€์ˆ˜ ์ž‘์—…์ด ์ถ”๊ฐ€๋œ๋‹ค๋ฉด O(n^2)

* ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” ์ž„์˜ ๋ฐ์ดํ„ฐ์…‹์— ๋Œ€ํ•œ ์ ‘๊ทผ์‹œ ์ˆ˜ํ–‰ ์ž‘์—…์˜ ๊ณ„์‚ฐ ํšŸ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.

 

Reply 

- ์ผ๋ฐ˜์ ์œผ๋กœ ์ž˜ ์•Œ๋ ค์ง„ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์ •๋‹ต์ด๋ผ๊ณ  ํ•  ์ˆ˜์žˆ๋Š” ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.(ํ˜„ ๊ธฐ์ค€) ๋”ฐ๋ผ์„œ ๋„ˆ๋ฌด ์ตœ์ ํ™”์— ์ง‘์ค‘ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ์˜๊ฒฌ์ด ๋‹ค์ˆ˜

- reddit, ์ปดํ“จํŒ…์— ์‚ฌ์šฉ๋˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋Š” ๋ฆฌ์†Œ์Šค๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์ข‹์€ ์ง€ํ‘œ์ด๋‹ค. ์ด ๋ฌธ์ œ๋Š” CS(Computer Science)์—์„œ ์ฃผ๋กœ ๋‹ค๋ฃฌ๋‹ค. ML part์—์„œ๋Š” ๊ธฐ์ˆ ์ ์œผ๋กœ ์•Œํ•„์š”๋Š” ์—†๋‹ค๋Š” ์˜๊ฒฌ

- ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ์ž˜ ์ดํ•ดํ•˜๋ฉด ๋” ๋‚˜์€ ์ „์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์ถ• ๊ฐ€๋Šฅ

- Gradient Descent๊ฐ€ ์ž˜์•Œ๋ ค์ง„ neural network์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ตœ์ ํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ‘œ๋ณธ

- Non use loop O(1) , using loop O(n) using loop in loop O(n^2)

 

 

  

 

 

 

๋ฐ˜์‘ํ˜•

'๐Ÿข One step' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[leetcode-5] Longest Palindrome Substring  (0) 2023.03.04
[leetcode-49] Group Anagrams  (0) 2023.03.02
[leetcode-819] Most Common Word  (0) 2023.03.02
[leetcode-937] Reorder_Data_in_LogFile  (0) 2023.03.01
[leetcode-344] ReverseString  (0) 2023.02.27
๋‹คํ–ˆ๋‹ค