• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:29
CEST 17:29
KST 00:29
  • 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
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun11[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22[ASL21] Ro16 Preview Pt1: Fresh Flow9
Community News
2026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid25
StarCraft 2
General
Team Liquid Map Contest #22 - The Finalists Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid Maestros of the Game 2 announced
Tourneys
GSL Code S Season 1 (2026) SC2 INu's Battles#15 <BO.9 2Matches> WardiTV Spring Cup RSL Revival: Season 5 - Qualifiers and Main Event SEL Masters #6 - Solar vs Classic (SC: Evo)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
Data needed Pros React To: Leta vs Tulbo (ASL S21, Ro.8) ASL21 General Discussion [TOOL] Starcraft Chat Translator JaeDong's ASL S21 Ro16 Post-Review
Tourneys
Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2 [ASL21] Ro8 Day 1
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Daigo vs Menard Best of 10 Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV Diablo IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2162 users

The Big Programming Thread - Page 788

Forum Index > General Forum
Post a Reply
Prev 1 786 787 788 789 790 1032 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.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-10-29 23:58:13
October 29 2016 23:52 GMT
#15741
On October 29 2016 06:47 centirius wrote:
C# solution (so probably works in Java with minimal changes I suppose) also O(n^2) obv


bool HasTwoSubArraysWithSameTotal(int[] values){
return HasTwoSubArraysWithSameTotal(values, 0, 0, 0);
}

bool HasTwoSubArraysWithSameTotal(int[] values, int sumA, int sumB, int index){
return values.Length == index ? sumA == sumB :
HasTwoSubArraysWithSameTotal(values, sumA + values[index], sumB, index + 1) ||
HasTwoSubArraysWithSameTotal(values, sumA, sumB + values[index], index + 1);
}



Good catch that this can be done without storing the actual arrays, I didn't catch that.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 30 2016 18:31 GMT
#15742
Some review questions, testing my knowledge of big-O notation

20. True/False ‘
a. 7n^2+10n+100 is O(1) False
b. 7n^2+10n+100 is O(n) False
c. 7n^2+10n+100 is O(n^2) True
d. 7n^2+10n+100 is O(n^3) True
e. 7n^2+10n+100 is O(2^n) True
21. True/False
a. 7n^2+10n+100 is θ(1) False
b. 7n^2+10n+100 is θ (n) False
c. 7n^2+10n+100 is θ (n^2) True
d. 7n^2+10n+100 is θ (n^3) False
e. 7n^2+10n+100 is θ (2^n) False

Is my understanding correct?

and then little o notation .. if my understanding of the above is correct could someone explain little-o to me?
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2016-10-30 18:39:08
October 30 2016 18:36 GMT
#15743
Yes you're correct. You already got that O is upper bound, and theta is both upper and lower bound. o is just lower bound.

So n^2 + n + 5 is

O(n^2), O(n^3), O(n^5), etc...

o(n^2), o(n), o(nlog(n)), o(1), etc...

Same idea, just on the other side.



In practice in industry all that gets talked about is theta, but confusingly they will call it O when then mean theta. But you can worry about that later.
Who after all is today speaking about the destruction of the Armenians?
phar
Profile Joined August 2011
United States1080 Posts
October 30 2016 18:37 GMT
#15744
Or for your abcde question there,

O is FFTTT
Theta is FFTFF
o is TTTFF
Who after all is today speaking about the destruction of the Armenians?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 30 2016 18:48 GMT
#15745
Okay cool

Followup question about big o, this time actually looking at a couple situations and determining the complexity


a. for (int i = 0; i < n; i++) {
for (int j = n; j >= i; j++) { … } }


outside goes through n times, inside ends up going through..... just throwing out an observation... 2^(n-1) ?
is this O(2^(n-1)) ?


b. for (int i = 10000; i < 50000; i++) {
for (int j = n; j >= 1; j /= 2) { … } }


outside goes through constant times
inside goes through... uh.. it looks like it keeps dividing by 2. So that's log(n) ? This one is a lot weirder to me
Is the answer O(log(n)) ?
RoomOfMush
Profile Joined March 2015
1296 Posts
October 30 2016 19:02 GMT
#15746
On October 31 2016 03:48 travis wrote:

a. for (int i = 0; i < n; i++) {
for (int j = n; j >= i; j++) { … } }


outside goes through n times, inside ends up going through..... just throwing out an observation... 2^(n-1) ?
is this O(2^(n-1)) ?

This one is not only tricky, its immensely stupid. Please never ever code like this. Everybody will believe you made a mistake when you write code like that. The example doesnt even make sense with the big-O-notation. The number of iterations is not really limited by the input but by the size of integers on your execution enviroment. In java that is 32bit integers and thus (2^31)-1 positive values.
If we go with the most rigorous interpretation of the big-O-notation the loop over the variable j would be constant and thus O(1). If we use that interpretation though the loop over the variable i would also be O(1) because (2^31)-1 is also an upper bound for n. Since n must be less than 2^31 => O(n) == O(2^31) == O(1) but you can apply this logic to every algorithm in java. This makes the entire exercise pointless.
Whoever came up with that question is either stupid or expects you to realize on your own that the exercise is stupid.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
October 30 2016 19:11 GMT
#15747
^ lol I thought I misread it but it is as stupid as it seems...
maybe travis meant j-- in which it'd O(n^3)
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 30 2016 19:22 GMT
#15748
Well, I think the only point is to test your ability to figure out the complexity. I didn't write it, the professor did.

I get what you are saying, mush, but I feel like what you are saying is a little pointless.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2016-10-30 20:07:22
October 30 2016 19:55 GMT
#15749
On October 31 2016 03:48 travis wrote:

b. for (int i = 10000; i < 50000; i++) {
for (int j = n; j >= 1; j /= 2) { … } }


outside goes through constant times
inside goes through... uh.. it looks like it keeps dividing by 2. So that's log(n) ? This one is a lot weirder to me
Is the answer O(log(n)) ?

The outer loop does nothing to change the complexity, it just applies a constant factor of 40000 which is irrelevant for big O.

For the inner loop, imagine it was j /= 10: in this case it would run as many times as n has digits in the decimal system - each division cuts off the last digit. The number of digits is log_10(n) (logarithm with base 10). So this would be O(log_10(n)). In the actual example the same reasoning works if you think of n as a binary number, so it runs in O(log_2(n)).

You write log(n), which usually is interpreted as log_10(n). But whether you meant base 10 or 2 or e, O(log(n)) is right anyways because log_b(n) = C * log_a(n), where C = log_b(a) is a constant.


For question a, please double check that you didn't make a mistake when copying it. If that is the exact version, we have to assume that the inner loop is either constant (Integer.MaxValue + 1 overflows into a negative value) or infinite if you don't restrict the range. So the whole thing would either be O(n) or infinite. It really is stupid though.
And it certainly is not anything like O(2^n). It's either O(1), O(n). O(n^2) or infinite. For a function f(n) you usually get 2^n stuff if you recursively do 2 calls to f(n - 1), n levels of recursion deep. Not if you nest two loops like that.
If you have a good reason to disagree with the above, please tell me. Thank you.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 30 2016 20:17 GMT
#15750
oh i see, i did misread it.
but yeah that's what the professor wrote, i copy pasted it.

I see what you guys are saying, inner loop goes forever

sorry about that mush
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2016-10-30 20:43:52
October 30 2016 20:43 GMT
#15751
On October 31 2016 05:17 travis wrote:
oh i see, i did misread it.
but yeah that's what the professor wrote, i copy pasted it.

I see what you guys are saying, inner loop goes forever

sorry about that mush

Its worse than "inner loop goes forever".
In every actual programming language the loop will not go forever. The range of integer variables is limited and thus it will end fairly quickly. The problem with that is that the big-O-notation doesnt work for actual real-life examples. Its a purely theoretical construct which can only be used in a gedankenexperiment. Once you try to use it on real-world code you will get O(1) for most pieces of code like the ones you posted.

If we, on the other hand, assume that your code is pseudo-code and has nothing to do with real life then the answer is that it runs forever. In this case we can not give an upper bound and there is nothing in the big-O notation that you can write to express that.

The example simply doesnt make any sense at all no matter how you look at it.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
October 30 2016 20:55 GMT
#15752
I'd just ask the professor to clarify that question, I can't imagine that it's not j-- unless the professor wanted you to think super outside the box or something like that.
There is no one like you in the universe.
raNazUra
Profile Joined December 2012
United States10 Posts
October 30 2016 21:37 GMT
#15753
On October 31 2016 03:36 phar wrote:
Yes you're correct. You already got that O is upper bound, and theta is both upper and lower bound. o is just lower bound.

So n^2 + n + 5 is

O(n^2), O(n^3), O(n^5), etc...

o(n^2), o(n), o(nlog(n)), o(1), etc...

Same idea, just on the other side.



In practice in industry all that gets talked about is theta, but confusingly they will call it O when then mean theta. But you can worry about that later.


This is incorrect. Omega is the lower-bound analysis, not little-o. Little-o is the same as big O, but it is strictly greater. If an algorithm is O(f(n)), but not Theta(f(n)) (that is, the bound is not tight), then it is o(f(n)). It's like the difference between <= and <.
Speak the truth, even if your voice shakes
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 31 2016 01:30 GMT
#15754
okay, professor got back to me. it was supposed to be j--

so outside goes through n times
so inside goes through... I have no idea
how do I figure this out
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-10-31 02:21:22
October 31 2016 02:16 GMT
#15755
: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
at i = ...
at i = n-1, j = n, j >= i, j-- will loop... ? times

that should get you started
There is no one like you in the universe.
phar
Profile Joined August 2011
United States1080 Posts
October 31 2016 07:42 GMT
#15756
On October 31 2016 06:37 raNazUra wrote:
Show nested quote +
On October 31 2016 03:36 phar wrote:
Yes you're correct. You already got that O is upper bound, and theta is both upper and lower bound. o is just lower bound.

So n^2 + n + 5 is

O(n^2), O(n^3), O(n^5), etc...

o(n^2), o(n), o(nlog(n)), o(1), etc...

Same idea, just on the other side.



In practice in industry all that gets talked about is theta, but confusingly they will call it O when then mean theta. But you can worry about that later.


This is incorrect. Omega is the lower-bound analysis, not little-o. Little-o is the same as big O, but it is strictly greater. If an algorithm is O(f(n)), but not Theta(f(n)) (that is, the bound is not tight), then it is o(f(n)). It's like the difference between <= and <.


Ah yea, you're right, I had completely forgotten about Ω. In part, cus as previously mentioned, industry tends to be a bit... cavalier with definitions.
Who after all is today speaking about the destruction of the Armenians?
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
October 31 2016 10:49 GMT
#15757
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

why are there always last two versions of jdk on the download page? the latest one below and the older one on top? why would I want to download not the latest one but just 1 before the latest?
Age of Mythology forever!
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 31 2016 11:13 GMT
#15758
On October 31 2016 19:49 mantequilla wrote:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

why are there always last two versions of jdk on the download page? the latest one below and the older one on top? why would I want to download not the latest one but just 1 before the latest?


Because:

On October 28 2016 02:44 Nesserev wrote:
Show nested quote +
On October 27 2016 22:04 Djagulingu wrote:
Fuck Oracle

ftfy, efficiency matters

"windows bash is a steaming heap of shit" tofucake
RoomOfMush
Profile Joined March 2015
1296 Posts
October 31 2016 16:11 GMT
#15759
On October 31 2016 19:49 mantequilla wrote:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

why are there always last two versions of jdk on the download page? the latest one below and the older one on top? why would I want to download not the latest one but just 1 before the latest?

Probably in case the latest one has bugs. Instead of waiting for a hotfix you can downgrade and perhaps things will work out that way.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
Last Edited: 2016-10-31 17:20:37
October 31 2016 17:19 GMT
#15760
I guessed like that too. It indicates latest version usually ( ) has bugs since older one is on the top. They want you to download the older one. Or they expect you to usually download it. Or all this is wrong and there's a more technically correct answer.

since bosses are reluctant to even use java 7 (not yet mature ), it's a funny thing.
Age of Mythology forever!
Prev 1 786 787 788 789 790 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
13:00
King of the Hill #246
WardiTV626
TKL 285
Liquipedia
INu's Battles
11:00
INu's Battles#15
SHIN vs ByuNLIVE!
IntoTheiNu 1018
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Serral 1767
TKL 285
trigger 65
StarCraft: Brood War
Britney 40007
Calm 5155
Sea 2579
Mini 774
EffOrt 559
Light 490
Shuttle 457
firebathero 421
BeSt 420
ggaemo 272
[ Show more ]
Hyuk 264
Leta 205
actioN 153
Dewaltoss 148
Hyun 109
hero 108
ToSsGirL 83
Sharp 61
Hm[arnc] 58
Pusan 56
Free 54
Sea.KH 52
yabsab 25
Barracks 24
Rock 21
scan(afreeca) 17
zelot 15
GoRush 15
IntoTheRainbow 13
910 13
Terrorterran 12
Shine 11
SilentControl 10
Sacsri 9
JulyZerg 8
Dota 2
Gorgc5281
qojqva1920
monkeys_forever288
syndereN240
Other Games
Grubby2580
singsing2247
B2W.Neo988
hiko811
DeMusliM383
crisheroes264
Hui .207
FrodaN141
ArmadaUGS101
QueenE50
Trikslyr33
ViBE24
Organizations
Dota 2
PGL Dota 2 - Main Stream73
StarCraft: Brood War
lovetv 10
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 16 non-featured ]
StarCraft 2
• Adnapsc2 9
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• escodisco4257
• Michael_bg 3
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis4234
Other Games
• WagamamaTV273
• Shiphtur72
Upcoming Events
Big Brain Bouts
32m
Replay Cast
8h 32m
Replay Cast
17h 32m
RSL Revival
18h 32m
Classic vs GgMaChine
Rogue vs Maru
WardiTV Invitational
19h 32m
IPSL
1d
Ret vs Art_Of_Turtle
Radley vs TBD
BSL
1d 3h
Replay Cast
1d 8h
RSL Revival
1d 18h
herO vs TriGGeR
NightMare vs Solar
uThermal 2v2 Circuit
1d 22h
[ Show More ]
BSL
2 days
IPSL
2 days
eOnzErG vs TBD
G5 vs Nesh
Patches Events
2 days
Replay Cast
2 days
Wardi Open
2 days
Afreeca Starleague
2 days
Jaedong vs Light
Monday Night Weeklies
3 days
Replay Cast
3 days
Sparkling Tuna Cup
3 days
Afreeca Starleague
3 days
Snow vs Flash
WardiTV Invitational
3 days
GSL
4 days
Classic vs Cure
Maru vs Rogue
GSL
5 days
SHIN vs Zoun
ByuN vs herO
Replay Cast
6 days
Escore
6 days
The PondCast
6 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Proleague 2026-04-30
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Escore Tournament S2: W5
KK 2v2 League Season 1
StarCraft2 Community Team League 2026 Spring
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
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 © 2026 TLnet. All Rights Reserved.