Coding Interview Problem - Critical Connections In Network

  Рет қаралды 319

Knapsack

Knapsack

Күн бұрын

Пікірлер: 9
@subee128
@subee128 9 ай бұрын
Thank you
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
Why do we need current time in DFS? Why can't we just set the time stamp of node 0 to some value and then in DFS, before we call DFS on the neighbour, just set the time stamp of the neighbour to 1 + time stamp of the current node. Basically, why do we need current_time when we can use time_stamp[current_node]?
@KnapsackLabs
@KnapsackLabs 2 жыл бұрын
Hi, this is a good question. Because timestamp[v] can be updated in the function call, it is not always true that timestamp[v] == current_timestamp. You are right that you don't necessarily need to store a current_timestamp variable, you could use timestamp[parent] + 1; however, you can't use timestamp[v]. I used it for convenience and code readability.
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
@@KnapsackLabs i am still confused. Timestamp[parent] would also be updated right? Then why can we use that but not timestamp [v]? I am having trouble visualising it
@KnapsackLabs
@KnapsackLabs 2 жыл бұрын
@@anonymoussloth6687 Actually yeah you are right timestamp[parent] can also get updated. Hmm not too sure, but I still don't think that it changes the fact that you can't rely on timestamp[v] or timestamp[parent]. I think then it is required that you use a variable to store current_timestamp. Feel free to try using your method instead saving a current_timestamp though to see if it works! It personally didn't work for me, but maybe I am implementing it wrong.
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
@@KnapsackLabs lol it didn't work for me either which is why i asked. But i think i get it now. Timestamp values get updated so we need to use the current time value in the DFS call. But what about that min operation? Why isn't that part of the if statement? Why is it outside?
@KnapsackLabs
@KnapsackLabs 2 жыл бұрын
@@anonymoussloth6687 The goal of the min operation is to set timestamps[v] = timestamps[neigh] when timestamps[neigh] < timestamps[v]. This happens when the connection between v and neigh is non-critical. The if statement holds true when timestamps[neigh] > curr_timestamp, meaning the connection between v and neigh is critical. Therefore if we move the min operation into the if statement it would not get to run when timestamps[neigh] < timestamps[v] which would lead to a incorrect answer.
@blasttrash
@blasttrash 2 жыл бұрын
You jumped straight into the "idea" of using timestamps? Whats the reasoning behind this? Did you just see the solution posted by someone else and make a video? Or was there a natural thought process to this? You explained the thought process and stuff very naturally until you made a huge logical leap and jumped and into using timestamps without giving any insight into why you did so.
Coding Interview Problem - Hand Of Straights
21:37
Knapsack
Рет қаралды 375
Coding Interview Problem - Car Fleet
14:39
Knapsack
Рет қаралды 915
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 87 МЛН
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Google Coding Interview With A Facebook Software Engineer
49:59
Clément Mihailescu
Рет қаралды 945 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 834 М.
Coding Interview Problem - Asteroid Collision
11:24
Knapsack
Рет қаралды 323
Coding Interview Problem - Longest String Chain
21:04
Knapsack
Рет қаралды 339
Critical Connections in a Network - Leet Code Hard Problem
19:42
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 87 МЛН