Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8-mong3125 #32

Merged
merged 1 commit into from
Mar 19, 2024
Merged

8-mong3125 #32

merged 1 commit into from
Mar 19, 2024

Conversation

mong3125
Copy link
Collaborator

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

DFS์™€ BFS

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

2์‹œ๊ฐ„

์ด๊ฒƒ๋„ ๋ฌธ์ œ๋ฅผ ๋‹ค ํ•ด๊ฒฐํ–ˆ๋Š”๋ฐ ์‹ค์ˆ˜ ํ•˜๋‚˜ ๋•Œ๋ฌธ์— ์˜ค๋ž˜๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค.
๊ผผ๊ผผํ•จ์ด ๋ถ€์กฑํ•ด์„œ ๊ณ„์† ์‹œ๊ฐ„์ด ์˜ค๋ž˜๊ฑธ๋ฆฌ๋„ค์š”..

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์—ฃ์ง€ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ด์ฐจ์› ๋ฐฐ์—ด๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. (๋ฐฐ์—ด x ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„ํ•ด์„œ ๋…ธ๋“œ๋Š” ๋ฐฐ์—ด๋กœ ๋“ค์–ด์˜ค๋Š” ์—ฃ์ง€๋Š” ๋ฆฌ์ŠคํŠธ๋กœ appendํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์–ด์š”)

DFS์™€ BFS๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๋˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
DFS๋Š” ์žฌ๊ท€๋กœ ๊ตฌํ˜„์„ ํ–ˆ๊ณ  BFS๋Š” queue๋ฅผ ์ด์šฉํ•ด์„œ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

dfs() {
    ๊ฒฐ๊ณผ์— ์ถ”๊ฐ€
    ๋ฐฉ๋ฌธ ์ฒดํฌ
    ํ˜„์žฌ ๋…ธ๋“œ์˜ ์—ฐ๊ฒฐ ๋…ธ๋“œ ์ค‘ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋กœ DFS ์‹คํ–‰ํ•˜๊ธฐ
}

bfs() {
    ํ ์ž๋ฃŒ๊ตฌ์กฐ์— ์‹œ์ž‘ ๋…ธ๋“œ ์‚ฝ์ž…
    ๋ฐฉ๋ฌธ ์ฒดํฌ
    while (ํ๊ฐ€ ๋นŒ๋•Œ๊นŒ์ง€) {
        ํ์—์„œ ๋…ธ๋“œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ณ  ์‚ญ์ œ
        ๊ฐ€์ ธ์˜จ ๋…ธ๋“œ๋ฅผ ๊ฒฐ๊ณผ์— ์ถ”๊ฐ€
        ํ˜„์žฌ ๋…ธ๋“œ์˜ ์—ฐ๊ฒฐ ๋…ธ๋“œ์ค‘์—์„œ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋ฅผ ํ์— ์‚ฝ์ž…ํ•˜๊ณ  ๋ฐฉ๋ฌธ ์ฒดํฌ
    }
}

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

  • DFS๋‚˜ BFS๋กœ ํƒ์ƒ‰์„ ํ•  ๋•Œ, ์ •๋ ฌ๋œ ์ƒํƒœ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํƒ์ƒ‰์„ ํ•˜๋”๊ตฐ์š”. ์–ด๋””์„œ๋“  ์ •๋ ฌ์„ ์ž˜ ๋ฐฐ์›Œ์•ผ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • java์˜ ํ๋Š” LinkedList ์ž๋ฃŒํ˜•์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • ์ˆซ์ž๋ฅผ n๊นŒ์ง€ ์‚ฌ์šฉํ•˜๋ฉด n+1์˜ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ ์„ ์–ธํ•˜๊ฒŒ๋œ๋‹ค. ์ด๋•Œ ์ •๋ ฌ๊ฐ™์ด ์ „์ฒด ํ•„๋“œ๋ฅผ ์ž‘์—…ํ• ๋•Œ for๋ฌธ์—์„œ i<n+1๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€๋ง์ž!

@mong3125 mong3125 requested review from rivkms, YIM2UL2ET and kjs254 March 10, 2024 10:12
@mong3125 mong3125 self-assigned this Mar 10, 2024
@mong3125 mong3125 changed the title BOJ1260_DFS์™€BFSํ”„๋กœ๊ทธ๋žจ java solution 8-mong3125 Mar 10, 2024
@tgyuuAn
Copy link
Member

tgyuuAn commented Mar 10, 2024

์ฝ”๋“œ ๋ธ”๋Ÿญ ``` ์˜†์— java ๋ถ™์ด์‹œ๋ฉด java ์ฝ”๋“œ๋กœ ํ•˜์ด๋ผ์ดํŒ… ๋œ๋‹ต๋‹ˆ๋‹ค !

@mong3125
Copy link
Collaborator Author

์ฝ”๋“œ ๋ธ”๋Ÿญ ``` ์˜†์— java ๋ถ™์ด์‹œ๋ฉด java ์ฝ”๋“œ๋กœ ํ•˜์ด๋ผ์ดํŒ… ๋œ๋‹ต๋‹ˆ๋‹ค !

์˜ค.. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์•ž์œผ๋กœ ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ์ข‹๊ฒ ๋„ค์š”! ์ €๊ฑด ์ž๋ฐ”์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ๊ณ  ์ˆ˜๋„์ฝ”๋“œ๋ผ์„œ ๊ทธ๋ƒฅ ๋‘˜๊ฒŒ์š”

Copy link
Collaborator

@YIM2UL2ET YIM2UL2ET left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFS๋Š” ์Šคํƒ์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ• ๋ฐ–์—๋Š” ์—†์„ ์ค„ ์•Œ์•˜๋Š”๋ฐ, ์žฌ๊ท€๋กœ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ ๋ณด๊ณ  ์•„์ด๋””์–ด ํ•˜๋‚˜ ์–ป์–ด๊ฐ‘๋‹ˆ๋‹ค. ๊ฐœ์ธ์ ์œผ๋กœ BFS์™€ DFS๋ฅผ ์ฒ˜์Œ์— ์—ฐ์Šตํ•˜๊ธฐ ๋”ฑ ์ข‹์€ ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐ๋˜๋„ค์š”. ๋‚˜์ค‘์— ํ•œ๋ฒˆ ํ’€์–ด ๋ณด์•„์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator

@rivkms rivkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ„๋‹จ? ํ•˜๋ฉด์„œ๋„ DFS, BFS์˜ ๊ฐœ๋…์„ ํ™•์‹คํ•˜๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
JAVA๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ณต๋ถ€ํ•˜์ง€ ์•Š์•„ ์ฝ”๋“œ๋ฅผ ์ฝ๋Š”๋ฐ ์•ฝ๊ฐ„์˜ ์‹œ๊ฐ„์€ ๊ฑธ๋ ธ์ง€๋งŒ, ๋ฐฐ์—ด์„ ์ด์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜์‹  ๋‚ด์šฉ์€ ์ž˜ ์ฝ์„ ์ˆ˜ ์žˆ์—ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.๐Ÿ˜

Copy link
Member

@kjs254 kjs254 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFS์— ๋น„ํ•ด ์ƒ๋Œ€์ ์œผ๋กœ BFS๊ฐ€ ์‰ฝ๊ฒŒ ๋Š๊ปด์ง€๋„ค์š”.

์•„๋งˆ ์Šคํƒ์ด ์•„๋‹ˆ๋ผ ์žฌ๊ท€๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™์€๋ฐ DFS, BFS ๋‘˜ ๋‹ค ์Šคํƒ ์ž๋ฃŒ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์žฌ๋ฐŒ์–ด ๋ณด์ž…๋‹ˆ๋‹ค

@mong3125
Copy link
Collaborator Author

DFS์— ๋น„ํ•ด ์ƒ๋Œ€์ ์œผ๋กœ BFS๊ฐ€ ์‰ฝ๊ฒŒ ๋Š๊ปด์ง€๋„ค์š”.

์•„๋งˆ ์Šคํƒ์ด ์•„๋‹ˆ๋ผ ์žฌ๊ท€๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™์€๋ฐ DFS, BFS ๋‘˜ ๋‹ค ์Šคํƒ ์ž๋ฃŒ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์žฌ๋ฐŒ์–ด ๋ณด์ž…๋‹ˆ๋‹ค

BFS๋„ ์Šคํƒ์„ ํ™œ์šฉํ•ด์„œ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ๊ฐ€์š”?

@mong3125 mong3125 merged commit 78e6d12 into main Mar 19, 2024
1 check passed
@mong3125 mong3125 deleted the 8-mong3125 branch March 19, 2024 09:57
@tgyuuAn
Copy link
Member

tgyuuAn commented Mar 19, 2024

DFS์— ๋น„ํ•ด ์ƒ๋Œ€์ ์œผ๋กœ BFS๊ฐ€ ์‰ฝ๊ฒŒ ๋Š๊ปด์ง€๋„ค์š”.
์•„๋งˆ ์Šคํƒ์ด ์•„๋‹ˆ๋ผ ์žฌ๊ท€๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™์€๋ฐ DFS, BFS ๋‘˜ ๋‹ค ์Šคํƒ ์ž๋ฃŒ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์žฌ๋ฐŒ์–ด ๋ณด์ž…๋‹ˆ๋‹ค

BFS๋„ ์Šคํƒ์„ ํ™œ์šฉํ•ด์„œ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ๊ฐ€์š”?

DFS๊ฐ€ ์Šคํƒ, BFS๊ฐ€ ํ๊ฐ€ ์ •์„์ด๊ธด ํ•ฉ๋‹ˆ๋‹ค๋งŒ.

@kjs254 ํ˜น์‹œ ๊ฐ€๋Šฅํ•œ๊ฐ€์š”????????????????????????????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants