GOLANG_INTERVIEW Telegram 246
👣 Какая сложность у следующего
алгоритма?

func reverse(n []int) {
length := len(n)

for i := 0; i < length / 2; i++ {
other := length - i - 1
temp := n[i]

n[i] = n[other]
n[other] = temp
}
}

func reverse(n []int) {
for n / 2 раз
}


Думаете O(log n)? Казалось бы да, но нет.

Ответ: O(n/2), т.к. мы просто один раз берем половину элементов массива и итерируем их, скажем было 100 элементов взяли половину - 50, для Big O это все те же n элементов, следовательно сложность алгоритма O(n)


@golang_interview
Please open Telegram to view this post
VIEW IN TELEGRAM
👎21👍6🤡42🔥1



tgoop.com/golang_interview/246
Create:
Last Update:

👣 Какая сложность у следующего
алгоритма?

func reverse(n []int) {
length := len(n)

for i := 0; i < length / 2; i++ {
other := length - i - 1
temp := n[i]

n[i] = n[other]
n[other] = temp
}
}

func reverse(n []int) {
for n / 2 раз
}


Думаете O(log n)? Казалось бы да, но нет.

Ответ: O(n/2), т.к. мы просто один раз берем половину элементов массива и итерируем их, скажем было 100 элементов взяли половину - 50, для Big O это все те же n элементов, следовательно сложность алгоритма O(n)


@golang_interview

BY Golang вопросы собеседований




Share with your friend now:
tgoop.com/golang_interview/246

View MORE
Open in Telegram


Telegram News

Date: |

Step-by-step tutorial on desktop: There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”. End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” Co-founder of NFT renting protocol Rentable World emiliano.eth shared the group Tuesday morning on Twitter, calling out the "degenerate" community, or crypto obsessives that engage in high-risk trading.
from us


Telegram Golang вопросы собеседований
FROM American