• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:27
CEST 14:27
KST 21:27
  • 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
[ASL19] Finals Recap: Standing Tall2HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Retirement From ASL18Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster14Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
The SCII GOAT: A statistical Evaluation What is Lactobacillus used for? Weekly Cups (June 23-29): Reynor in world title form? StarCraft Mass Recall: SC1 campaigns on SC2 thread How does the number of casters affect your enjoyment of esports?
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 $200 Biweekly - StarCraft Evolution League #1
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
[ASL19] Finals Recap: Standing Tall Flash Announces Retirement From ASL ASL20 Preliminary Maps BW General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [BSL20] ProLeague LB Final - Saturday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Trading/Investing Thread Stop Killing Games - European Citizens Initiative Russo-Ukrainian War Thread
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread NBA General Discussion Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
Game Sound vs. Music: The Im…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 668 users

The Big Programming Thread - Page 789

Forum Index > General Forum
Post a Reply
Prev 1 787 788 789 790 791 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-10-31 19:41:29
October 31 2016 18:46 GMT
#15761
On October 31 2016 11:16 Blisse wrote:
:p

when you have problems like this, i think it helps to manually count.

so for the inside loop, can you manually count the number of iterations?

at i = 0, j = n, j >= i, j-- will loop... n times
at i = 1, j = n, j >= i, j-- will loop... ? times


? = n-1


at i = ...
at i = n-1, j = n, j >= i, j-- will loop... ? times

that should get you started

? = n-(n-1)

I guess it's (n^2+n) / 2

I had to look it up... didn't actually know how to solve that.. so I googled "factorial but with sum" and found the answer lol

This is O(n^2) ?




another question:

is an array a list? I understand that in java an array is an object that is NOT an implementation of the list interface, but it is a sequential data type and seems to fit the abstract definition of a list. So I am wondering if say, I was asked on a test, "is an array a list", would I say yes or would I say no?


yet another question:

review sheet says, "Describe how a queue is typically implemented using sequential allocation."

By sequential allocation, it means an array? So in this case I am guessing the answer is "add to the back, remove from the front, and make the array circular". I guess you would also need to expand and copy over the array as necessary.



yet another question, hashcode question:

okay so if I have a hashcode function, my professor taught our class a method to "scatter" our hash table is this:

( hashcode-function * a-large-prime-number ) % table size .

This is supposed to scatter the hashcode results throughout the table, but I don't really understand why and he didn't really explain why. Can someone explain why you do this?
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
Last Edited: 2016-10-31 20:11:48
October 31 2016 20:05 GMT
#15762
disclaimer: I'm just answering as an exercise for myself, I graduated 3 years ago and wasn't a very good student especially on theoretical courses

is an array a list?

as a java guy I'd directly say no because if array was a list it would implement the list interface. other than that doesn't it become a little political question? does a list have a formal definition independent of the language? biggest difference is a list can grow as much as memory but an array is fixed. plus when you remove an element at index(i) you need to shift other elements, hence a wrapper is needed for an array to become a list. wrap everything and you get an ArrayList. maybe the thing called "dynamic array" is more list-like?

"Describe how a queue is typically implemented using sequential allocation."
like a finite tube full of gumballs?

yet another question, hashcode question:

if I remember correctly this is done to prevent too many values with the same key. Imagine like this, if you put all the values to one key it becomes a linked list, so not a good thing. 1 value for 1 key is ideal. if you have a good enough hash function I guess you won't need this?

edit: related to last question stackoverflow.com
Age of Mythology forever!
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-10-31 20:25:23
October 31 2016 20:23 GMT
#15763
On November 01 2016 05:05 mantequilla wrote:


yet another question, hashcode question:

if I remember correctly this is done to prevent too many values with the same key. Imagine like this, if you put all the values to one key it becomes a linked list, so not a good thing. 1 value for 1 key is ideal. if you have a good enough hash function I guess you won't need this?

edit: related to last question stackoverflow.com



I think you mean too many keys that link to the same bucket

but either way, I don't actually get how it helps to scatter it.

I guess maybe the issue is that if we don't multiply by a large prime, then taking hashfunction % T is more likely to result in duplicates.

yes... I think that's it. If we were taking hashfunction%100 (as a weak example), then every multiple of 100 will result in the same bucket. But if we do (hashfunction*large prime) % 100 then that definitely does scatter it.
RoomOfMush
Profile Joined March 2015
1296 Posts
October 31 2016 20:44 GMT
#15764
An array is different things in different programming languages. In java an array is very similar to an array in C and C++. It is a continuous block of memory which is fixed in size and can hold multiple elements of the same type. Arrays are usually very very fast compared to other data structures because working with continuous blocks of memory complements current processor architecture.

The "default" List implementation in java is the ArrayList which is a List that is implemented using an array in the background. Since a list can grow but an array cant the array has to be reallocated every time the size of the list grows above the capacity of the array.
An alternative List implementation is a LinkedList which does not use an array and is significantly slower than an ArrayList in most common use-cases.

In java arrays are objects and lists are objects but arrays are still something special. Their class does not exist at compile time but is instead dynamically generated at run time the first time a certain type of array is used.

About the hashcodes and prime numbers:
I dont know the big theory behind it but multiplying with prime numbers above a certain size has simply been proven to be a simple yet effective way of scattering hashcodes.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
October 31 2016 20:49 GMT
#15765
my tip for you is to study heaps

they teach 50 different data structures but always ask the fking heaps all the time...

or I'm unlucky. I don't like heaps.
Age of Mythology forever!
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 31 2016 21:22 GMT
#15766
If the hashcode is already decent, multiplying by a prime does nothing at best, and potentially causes problems if the prime and the table size are in an unfortunate relation.

For example with hashes 0 through 5, a prime 37 and a table size 74. Without multiplication by that prime, everything slots perfectly into buckets 0 through 5. With the prime, you only use the buckets 0 and 1, with 3 objects each.

Typically you only use primes (along with bitshifts, xors and lookup tables) to generate the hashcode from multiple input values like a byte array, not to slot the hashes into the hashtable. A good hashing algorithm is a carefully chosen sequence of operations. Blindly multiplying something with a random prime is NOT a good idea.
If you have a good reason to disagree with the above, please tell me. Thank you.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-10-31 22:00:13
October 31 2016 21:57 GMT
#15767
On November 01 2016 03:46 travis wrote:
Show nested quote +
On October 31 2016 11:16 Blisse wrote:
:p

when you have problems like this, i think it helps to manually count.

so for the inside loop, can you manually count the number of iterations?

at i = 0, j = n, j >= i, j-- will loop... n times
at i = 1, j = n, j >= i, j-- will loop... ? times


? = n-1

Show nested quote +

at i = ...
at i = n-1, j = n, j >= i, j-- will loop... ? times

that should get you started

? = n-(n-1)

I guess it's (n^2+n) / 2

I had to look it up... didn't actually know how to solve that.. so I googled "factorial but with sum" and found the answer lol

This is O(n^2) ?


So basically you have

at i = 0, j = n, j >= i, j-- will loop... n times (see that i=0, so n-0 = n)
at i = 1, j = n, j >= i, j-- will loop... n-1 times (see that i=1, so n-1, etc)
at i = 2, j = n, j >= i, j-- will loop... n-2 times
...
at i = n-2, j = n, j >= i, j-- will loop... n-(n-2)=2 times
at i = n-1, j = n, j >= i, j-- will loop... n-(n-1)=1 time

If you're trying to count the inner loop, you have this summation.

n + (n-1) + (n-2) + ... + 2 + 1

which is the same as this more recognizable form

1 + 2 + ... + (n-2) + (n-1) + n

This is known as, the sum of numbers from 1 to n.

This has an exact value, (n (n+1)) / 2.

So the inner loop happens (n*(n+1))/2 times, which is O(n^2).
The outer loop happens n times, which is O(n).

So the whole thing is O(n^3)
There is no one like you in the universe.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-10-31 23:12:54
October 31 2016 22:13 GMT
#15768
Normally for the queue implemented as an array you keep track of a current index and the current data size. The current pointer is the index of the item that is next in the queue. The current pointer plus the size (modulo the length of the array) tells you where the next insert should go. This way you never have to shift the array unless you're moving the data from a smaller array to a larger array.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 31 2016 23:07 GMT
#15769
On November 01 2016 06:57 Blisse wrote:


So the inner loop happens (n*(n+1))/2 times, which is O(n^2).
The outer loop happens n times, which is O(n).

So the whole thing is O(n^3)


ahh thank you
yeah my mistake in not multiplying it by the outer loop value
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2016-10-31 23:41:42
October 31 2016 23:39 GMT
#15770
On November 01 2016 08:07 travis wrote:
Show nested quote +
On November 01 2016 06:57 Blisse wrote:


So the inner loop happens (n*(n+1))/2 times, which is O(n^2).
The outer loop happens n times, which is O(n).

So the whole thing is O(n^3)


ahh thank you
yeah my mistake in not multiplying it by the outer loop value

No. This is counting the outer loop twice.

We're talking about this, right?
for (int i = 0; i < n; i++) { 
for (int j = n; j >= i; j--) { constant }
}

Two simple iterations bound by n can never be slower than O(n^2). I'll make the inner loop a little slower and at the same time make it easier to see:

Iterate all the way down to 0 instead of i:
for (int i = 0; i < n; i++) { 
for (int j = n; j >= 0; j--) { constant }
}


Change the iteration order, from n->0 to 0->n:
for (int i = 0; i < n; i++) { 
for (int j = 0; j <= n; j++) { constant }
}


To make this even simpler, use <= in both loops:
for (int i = 0; i <= n; i++) { 
for (int j = 0; j <= n; j++) { constant }
}


None of these transformation made anything faster, and now it is clearly O(n^2).
If you have a good reason to disagree with the above, please tell me. Thank you.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
November 01 2016 01:46 GMT
#15771
Holy brain fart, you are right, I even did the summation there with the outer loop too lmao
There is no one like you in the universe.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
Last Edited: 2016-11-01 10:22:05
November 01 2016 10:20 GMT
#15772
ORACLE SPATIAL...

For those who think the only way to make a regular well known text geometry compatible with a spatial column is to convert that spatial column into well known text and convert the resulting well known text and the well known text in the start of the sentence back to sdo geometry (spatial column format). I don't even know whether what I just said makes sense grammatically or not.
"windows bash is a steaming heap of shit" tofucake
R1CH
Profile Blog Joined May 2007
Netherlands10340 Posts
November 01 2016 14:13 GMT
#15773
On October 24 2016 20:06 Manit0u wrote:

Would be thankful if anyone could double-check this code as valid for encrypting/decrypting sensitive data for storage purposes (like personal data inside a database):


Couple of issues:

You seem to be doing MAC-then-encrypt, which is OK, but Encypt-then-MAC is the more standard way of doing things. See http://crypto.stackexchange.com/a/205

You don't check the "strong" value from openssl_random_pseudo_bytes. If the system PRNG is not seeded or there is another issue with it, you could be using insecure random numbers. Also since you're working with old systems, your openssl_random_pseudo_bytes might not be secure at all: https://bugs.php.net/bug.php?id=70014. You may want to look at https://github.com/paragonie/random_compat if this is the case.
AdministratorTwitter: @R1CH_TL
Manit0u
Profile Blog Joined August 2004
Poland17242 Posts
November 02 2016 11:23 GMT
#15774
On November 01 2016 23:13 R1CH wrote:
Show nested quote +
On October 24 2016 20:06 Manit0u wrote:

Would be thankful if anyone could double-check this code as valid for encrypting/decrypting sensitive data for storage purposes (like personal data inside a database):


Couple of issues:

You seem to be doing MAC-then-encrypt, which is OK, but Encypt-then-MAC is the more standard way of doing things. See http://crypto.stackexchange.com/a/205

You don't check the "strong" value from openssl_random_pseudo_bytes. If the system PRNG is not seeded or there is another issue with it, you could be using insecure random numbers. Also since you're working with old systems, your openssl_random_pseudo_bytes might not be secure at all: https://bugs.php.net/bug.php?id=70014. You may want to look at https://github.com/paragonie/random_compat if this is the case.


Thanks a lot. Fixed those issues.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 02 2016 15:48 GMT
#15775
anyone with ability in java and understanding of OOP/data structures willing to help me study over skype (not a call just text chat) for a couple hours? either tonight or tomorrow night (I am EST).

I'd be willing to pay 20 bucks for 2 hours. 10 dollars an hour. you'll be rich
Isualin
Profile Joined March 2011
Germany1903 Posts
November 02 2016 17:03 GMT
#15776
On November 01 2016 05:49 mantequilla wrote:
my tip for you is to study heaps

they teach 50 different data structures but always ask the fking heaps all the time...

or I'm unlucky. I don't like heaps.

Most of the interview questions i got were about stacks or binary trees.

On another note, in my latest interview i had to find the exit from a maze while collecting as many gold sacks as possible. I haven't done anything like that before so it felt pretty hard
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
November 02 2016 19:40 GMT
#15777
On November 03 2016 00:48 travis wrote:
anyone with ability in java and understanding of OOP/data structures willing to help me study over skype (not a call just text chat) for a couple hours? either tonight or tomorrow night (I am EST).

I'd be willing to pay 20 bucks for 2 hours. 10 dollars an hour. you'll be rich



will you be implementing data structures with plain java or use structures in the standard library?
Age of Mythology forever!
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 02 2016 19:48 GMT
#15778
Does anyone know how I can compile the simplest possible Hadoop MapReduce program (aka the word count) using gradle? Is that even possible? Or do I have to compile using the Hadoop stuff that people download on their computers and shit. If latter, how am I supposed to know which classes belong to which packages and shit?

I am just getting started with Hadoop and I could really use some help with this shit.
"windows bash is a steaming heap of shit" tofucake
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 02 2016 20:24 GMT
#15779
On November 03 2016 04:40 mantequilla wrote:
Show nested quote +
On November 03 2016 00:48 travis wrote:
anyone with ability in java and understanding of OOP/data structures willing to help me study over skype (not a call just text chat) for a couple hours? either tonight or tomorrow night (I am EST).

I'd be willing to pay 20 bucks for 2 hours. 10 dollars an hour. you'll be rich



will you be implementing data structures with plain java or use structures in the standard library?


both, like a mix
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-02 20:59:17
November 02 2016 20:53 GMT
#15780
Hey, I have a question about writing recursive methods

the single biggest problem I have with recursion is "keeping count" in order to know when I reached a stopping case

example: one of the questions on my review says "Write a recursive method takes two (non-negative) int parameters and returns their product.
But… you may only use +, not * in your code."

I kind of understand what I need to do

something like


private int product(int one, int two) {
if(two > 1) {
two--;
return one + (product(one, two));
} else {
return one;
} }



so.. I think this works
but It required a lot of thought to come up with this
if I could just keep "count" of how many times I called my method it would be a lot easier to solve most of these methods
is there a way to keep count of how many times I call my recursive method without writing a helper method?
the problem for me is if I do something like (as a simplistic non-functional example)

recursiveMethod() {
count = 0;
count++;
recursiveMethod();
}

clearly this doesn't work because every time, count becomes 0 again. so how do you keep count?


edit: shit my way above doesn't work anyways huh. well... hrrmph lol
edit2: ok i fixed it
Prev 1 787 788 789 790 791 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 33m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 294
RotterdaM 244
ForJumy 21
StarCraft: Brood War
Rain 5857
Sea 5008
Larva 638
EffOrt 509
Mini 382
Pusan 341
BeSt 317
Stork 316
Zeus 261
Last 205
[ Show more ]
Mind 152
ZerO 138
Snow 128
Hyun 116
Rush 89
Light 74
hero 58
JYJ44
Aegong 43
Movie 29
Sharp 22
sSak 16
NaDa 15
Barracks 11
Noble 11
IntoTheRainbow 9
scan(afreeca) 9
SilentControl 7
Icarus 7
ajuk12(nOOB) 7
HiyA 6
Hm[arnc] 2
Britney 0
Stormgate
NightEnD13
Dota 2
Gorgc4210
qojqva1665
BananaSlamJamma537
XcaliburYe421
febbydoto6
League of Legends
singsing2123
Counter-Strike
x6flipin619
markeloff54
Super Smash Bros
Mew2King160
Westballz10
Heroes of the Storm
Khaldor178
Other Games
B2W.Neo740
DeMusliM501
Fuzer 474
hiko260
Pyrionflax252
XaKoH 248
crisheroes215
SortOf87
ArmadaUGS41
ZerO(Twitch)7
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• StrangeGG 40
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 3
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 1178
Upcoming Events
uThermal 2v2 Circuit
3h 33m
OSC
6h 33m
Replay Cast
11h 33m
The PondCast
21h 33m
RSL Revival
21h 33m
ByuN vs Classic
Clem vs Cham
WardiTV European League
1d 3h
Replay Cast
1d 11h
RSL Revival
1d 21h
herO vs SHIN
Reynor vs Cure
WardiTV European League
2 days
FEL
2 days
[ Show More ]
Korean StarCraft League
2 days
CranKy Ducklings
2 days
RSL Revival
2 days
FEL
3 days
Sparkling Tuna Cup
3 days
RSL Revival
3 days
FEL
3 days
BSL: ProLeague
4 days
Dewalt vs Bonyth
Replay Cast
5 days
Replay Cast
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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
FISSURE Playground #1
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.