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: |

The creator of the channel becomes its administrator by default. If you need help managing your channel, you can add more administrators from your subscriber base. You can provide each admin with limited or full rights to manage the channel. For example, you can allow an administrator to publish and edit content while withholding the right to add new subscribers. Each account can create up to 10 public channels How to create a business channel on Telegram? (Tutorial) Write your hashtags in the language of your target audience. During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month.
from us


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