• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 23:25
CEST 05:25
KST 12:25
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team TLMC #5: Winners Announced!0[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5TL.net Map Contest #21 - Finalists4Team TLMC #5: Vote to Decide Ladder Maps!0
Community News
5.0.15 Patch Balance Hotfix (2025-10-8)18Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition245.0.15 Balance Patch Notes (Live version)118$2,500 WardiTV TL Map Contest Tournament 152
StarCraft 2
General
5.0.15 Patch Balance Hotfix (2025-10-8) 5.0.15 Balance Patch Notes (Live version) The New Patch Killed Mech! Weekly Cups (Sept 29-Oct 5): MaxPax triples up Team TLMC #5: Winners Announced!
Tourneys
Tenacious Turtle Tussle Sea Duckling Open (Global, Bronze-Diamond) $2,500 WardiTV TL Map Contest Tournament 15 RSL Offline Finals Dates + Ticket Sales! Stellar Fest
Strategy
Custom Maps
External Content
Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More Mutation # 491 Night Drive
Brood War
General
Question regarding recent ASL Bisu vs Larva game [BSL21] - How to Qualify to Each League ? ASL20 General Discussion BW General Discussion RepMastered™: replay sharing and analyzer site
Tourneys
[Megathread] Daily Proleagues [ASL20] Ro8 Day 4 Small VOD Thread 2.0 [ASL20] Ro8 Day 3
Strategy
Current Meta TvZ Theorycraft - Improving on State of the Art Proposed Glossary of Strategic Uncertainty 9 hatch vs 10 hatch vs 12 hatch
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread The Games Industry And ATVI
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts The Automated Ban List BarCraft in Tokyo Japan for ASL Season5 Final
Blogs
What your "aura" says about…
Peanutsc
Mental Health In Esports: Wo…
TrAiDoS
Try to reverse getting fired …
Garnet
[ASL20] Players bad at pi…
pullarius1
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1217 users

Logic/Programming Interview Questions - Page 3

Blogs > Oracle
Post a Reply
Prev 1 2 3 All
BottleAbuser
Profile Blog Joined December 2007
Korea (South)1888 Posts
June 27 2011 14:05 GMT
#41
Frigo, the O(1) space requirement implies that the additional space we need isn't dependent on how large the input is. If you are using 1 extra bit for every node, that could theoretically be 2^100 more bits. That's why there is a significant difference between in-place and non in-place sorting algorithms: If you have a petabyte of data and a petabyte of storage space, you're not going anywhere without an in-place algorithm.

But given the way the question is worded, we have no guarantee about the current state of the pointers, as an adversary could defeat you every time on the first node.
Compilers are like boyfriends, you miss a period and they go crazy on you.
Oracle
Profile Blog Joined May 2007
Canada411 Posts
Last Edited: 2011-06-27 20:44:45
June 27 2011 20:42 GMT
#42
Sorry I havent checked this in a while, here's some clarifications:

I will post a diagram for Q2 soon

BottleAbuser, your proof of the O(n) running time of k-select is fine with me now

I have a different solution:
You turn the array into a heap and then find the k-th largest. I'll post a detailed solution soon.

For Q6:
You can assume that node->next modulo 4 == 0 for every node in the list. You guys are actually really close to the answer.

Frigo, your answer to Q7 doesn't seem right with me, you can refer to the post I made before regarding a similar method.
Oracle
Profile Blog Joined May 2007
Canada411 Posts
Last Edited: 2011-06-27 22:42:40
June 27 2011 21:26 GMT
#43
heapify(A)
A: an array

1. n ← size(A) − 1
2. for i ← floor(n/2) to 0 do
3. bubble−up(A, i)

Builds a max-heap in linear-time, given the assumption that the 2i'th index is the left child, and 2i+1'th index is the right child of an element.

Then its a simple o(k) time to find the kth largest
Hamster1800
Profile Blog Joined August 2008
United States175 Posts
June 27 2011 22:02 GMT
#44
Could you elaborate more on how to select once you've heapified the array? I'm not familiar with a linear time method to do k-select in a heap. BottleAbuser's method (recurse on median-of-medians) I believe is the standard method for k-select.
D is for Diamond, E is for Everything Else
Oracle
Profile Blog Joined May 2007
Canada411 Posts
Last Edited: 2011-06-27 22:37:46
June 27 2011 22:09 GMT
#45
You do sort of a breadth first search on the heap, giving priority to the greatest element and traverse that node. It comes out to O(k)
Hamster1800
Profile Blog Joined August 2008
United States175 Posts
June 27 2011 22:19 GMT
#46
That shouldn't work. The relative size of two nodes says nothing about the relative sizes of their children. For example, just because the top of the (min-)heap is 1 with children 10 and 100, the 20th smallest element might be the 100. It also could be some deep descendent of the 10 or a deep descendent of the 100. I don't understand how you're going to determine which is the case.
D is for Diamond, E is for Everything Else
Oracle
Profile Blog Joined May 2007
Canada411 Posts
Last Edited: 2011-06-27 22:44:38
June 27 2011 22:22 GMT
#47
A max heap is a left-justified binary tree. The invariant on the tree is that a node's key is strictly greater than or equal to each of its children nodes' key.

We traverse only k-1 edges, and every time we traverse an edge we will effectively be eliminating a greater element than k. But we only traverse the edge with the child with the greatest key.

Hence we place each key in a priority queue, and traverse the greatest key out of all the "active" nodes.

But since we only traverse k-1 edges, we are done at the kth iteration.


In Pseudocode,

activenode <- root
initialize Maxheap Q

for 0 to k-1
put children of activenode into Q
activenode <- get max of Q

return activenode

Actually i guess this is O(klogk) but I believe theres an analysis which shows its within n so i'll think about it for a bit. (Something to do with Q's size being at most n/2 iirc, guess I shouldve done the problems before posting them )

Hamster1800
Profile Blog Joined August 2008
United States175 Posts
Last Edited: 2011-06-27 22:27:47
June 27 2011 22:27 GMT
#48
Let me be more clear: I'm not worried about the runtime of your algorithm. I'm worried about what it is and that it gets the correct answer. If you could explain your k-select method in full and explain how it gets the kth largest element, that would answer my question.
D is for Diamond, E is for Everything Else
Oracle
Profile Blog Joined May 2007
Canada411 Posts
June 27 2011 22:38 GMT
#49
Ive edited my post above to be more clear
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-06-28 03:02:28
June 28 2011 02:59 GMT
#50
On June 28 2011 05:42 Oracle wrote:
For Q6:
You can assume that node->next modulo 4 == 0 for every node in the list. You guys are actually really close to the answer.

Well it's settled then. We just need to set a bit in the "next" pointer to mark a node visited. And technically, the algorithm uses only an O(1) space overhead, not O(n), made possible by the special structure of the list.

Frigo, your answer to Q7 doesn't seem right with me, you can refer to the post I made before regarding a similar method.

Well, I have only shown that we convey enough information to tell the 5th card, I left the ordering and indexing of the cards, and the method to calculate the index of the 5th from the possible arrangements, implicit.

Other than that, I forgot the case when all cards are upside down:
0 upside down, 4 visible: 4 choose 0 * 4! = 1 * 24 = 24
1 upside down, 3 visible: 4 choose 1 * 3! = 4 * 6 = 24
2 upside down, 2 visible: 4 choose 2 * 2! = 6 * 2 = 12
3 upside down, 1 visible: 4 choose 3 * 1! = 4 * 1 = 4
4 upside down, 0 visible: 4 choose 4 * 0! = 1 * 1 = 1
65 possible arrangements
http://www.fimfiction.net/user/Treasure_Chest
BottleAbuser
Profile Blog Joined December 2007
Korea (South)1888 Posts
Last Edited: 2011-06-28 11:17:25
June 28 2011 11:15 GMT
#51
Well, we can simply increment each traversed node's next pointer to mark it as visited then. If the next node'spointer mod 4 is 1 then that's the start of the loop.

Should read whole thread heh. I meant "what frigo said"
Compilers are like boyfriends, you miss a period and they go crazy on you.
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
June 28 2011 12:15 GMT
#52
On June 25 2011 09:32 Oracle wrote:
Here's mine:

We think of a card as a {0,1}-bit. A card represents 0 if it is face up and 1 if it is face-down.

So then we get a binary string of length four. So we can represent 2^4 - 1 = 15 possibly values with a string of 4 bits. But there are really only 13 distinct values. Hence we will never get the string 1111. So we will always have a face-up card.

So we assign 'a' = Hearts, 'b' = Diamonds, 'c' = Spades, 'd' = Clubs. The card which is face-up and leftmost denotes the suit.


So for example A F F F can be read as 0111 = 7. The A says its the 7 of Hearts.
FBDF can be read as 1001 = 9. The B says its the 9 of Diamonds.

Maybe I'm just misunderstanding your method, but doesn't this assume you actually get at least one other card of the same suit as the fifth card? For example how would you represent the 7 of Hearts if the other 4 cards are black?
Oracle
Profile Blog Joined May 2007
Canada411 Posts
Last Edited: 2011-06-28 15:02:31
June 28 2011 15:01 GMT
#53
On June 28 2011 21:15 iaretehnoob wrote:
Show nested quote +
On June 25 2011 09:32 Oracle wrote:
Here's mine:

We think of a card as a {0,1}-bit. A card represents 0 if it is face up and 1 if it is face-down.

So then we get a binary string of length four. So we can represent 2^4 - 1 = 15 possibly values with a string of 4 bits. But there are really only 13 distinct values. Hence we will never get the string 1111. So we will always have a face-up card.

So we assign 'a' = Hearts, 'b' = Diamonds, 'c' = Spades, 'd' = Clubs. The card which is face-up and leftmost denotes the suit.


So for example A F F F can be read as 0111 = 7. The A says its the 7 of Hearts.
FBDF can be read as 1001 = 9. The B says its the 9 of Diamonds.

Maybe I'm just misunderstanding your method, but doesn't this assume you actually get at least one other card of the same suit as the fifth card? For example how would you represent the 7 of Hearts if the other 4 cards are black?

The 1st card I pulled out is mapped to hearts, regardless if it is a black-suited card. So we map the ordering not the suit.


On June 28 2011 20:15 BottleAbuser wrote:
Well, we can simply increment each traversed node's next pointer to mark it as visited then. If the next node'spointer mod 4 is 1 then that's the start of the loop.

Should read whole thread heh. I meant "what frigo said"



Right, I love this one
Prev 1 2 3 All
Please log in or register to reply.
Live Events Refresh
Next event in 6h 35m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nathanias 162
StarCraft: Brood War
Noble 76
Sharp 36
KwarK 13
Icarus 12
Dota 2
monkeys_forever476
LuMiX1
Counter-Strike
Stewie2K356
Other Games
summit1g9629
shahzam840
JimRising 737
C9.Mang0720
Maynarde180
ViBE172
Organizations
Other Games
gamesdonequick1081
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4472
• Lourlo584
• Rush458
• Stunt183
Upcoming Events
The PondCast
6h 35m
Map Test Tournament
7h 35m
OSC
12h 35m
SKillous vs Krystianer
GgMaChine vs Demi
ArT vs Creator
INexorable vs TBD
ReBellioN vs TriGGeR
UedSoldier vs Iba
sOs vs Moja
Map Test Tournament
1d 7h
OSC
1d 9h
Korean StarCraft League
1d 23h
CranKy Ducklings
2 days
Map Test Tournament
2 days
OSC
2 days
[BSL 2025] Weekly
2 days
[ Show More ]
Safe House 2
2 days
Sparkling Tuna Cup
3 days
Map Test Tournament
3 days
OSC
3 days
IPSL
3 days
Bonyth vs Art_Of_Turtle
Razz vs rasowy
Liquipedia Results

Completed

Acropolis #4 - TS2
Maestros of the Game
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
WardiTV TLMC #15
EC S1
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.