• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:57
CET 08:57
KST 16:57
  • 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
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.171Evil Geniuses - shutting down17ISSL (IntoTheTV x SOOP SC2 League): Premier5Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League86
StarCraft 2
General
Evil Geniuses - shutting down Weekly Cups (October 19-25): Clem triples first in 5.0.17 REPORT: StarCraft 2: Remastered In Development How do you feel about the mass reverts in the 5.0.17 PTR? Team Liquid Map Contest #22: Results and Winners
Tourneys
RSL goes to London! 2026 Offline Finals Nov 21-22 ScienceCraft (October 24-25) - Live Event Sparkling Tuna Cup - Weekly Open Tournament ISSL (IntoTheTV x SOOP SC2 League): Premier WORTEX Challenger Series — Open SC2 LAN in Budapes
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[G] How to playtest arcade maps [A] Nemrods 1/4 players [M] (2) Sweltering Sands
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
BW General Discussion [BW] Looking for Clan Thread! [ASL22] Finals Preview: Sweet Victory! Recent recommended BW games [Megathread] Daily Funny Videos
Tourneys
[$1250] International ShieldBattery League [Megathread] Daily Proleagues [ASL22] Grand Finals [BSL23] RO24 Group C
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread European Politico-economics QA Mega-thread US Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 10723 users

The Big Programming Thread - Page 846

Forum Index > General Forum
Post a Reply
Prev 1 844 845 846 847 848 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.
Hanh
Profile Joined June 2016
146 Posts
February 17 2017 04:13 GMT
#16901
On February 17 2017 12:11 Blisse wrote:
-12 / 7 = 1 remainder -5


This part is incorrect because you used truncation division instead of Euclidian division. The remainder has to be between 0 and n-1.

The two definitions are equivalent.

jalstar
Profile Blog Joined September 2009
United States8198 Posts
February 17 2017 06:26 GMT
#16902
Is anyone here Base SAS certified? I signed up to take the test and have studied a bit already.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-17 15:53:54
February 17 2017 15:35 GMT
#16903
edit:

ohhhh shit. i have no idea what is going on in my C program. this is weirdness I have not yet experienced in programming.

time to learn to debug I guess



edit2: if c is in an infite loop, is it normal for it to sit at an empty prompt asking for input for no reason? basically as though it was doing a scanf?
slmw
Profile Blog Joined October 2010
Finland233 Posts
February 17 2017 16:34 GMT
#16904
You're not making a lot of sense. When a process is running in your typical terminal, it will show an empty line until it's complete, you write something in the terminal, or the process writes something to stdout. There's no special interface for prompt. Why not test this yourself by writing one program with "while(1);" and one with "scanf("%d",&a);"?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-17 16:43:04
February 17 2017 16:42 GMT
#16905
I don't really mean a special interface. keep in mind I have no history with unix, I am not used to how you interact with the shell

it seemed very weird to me that i could sit there and type in spam and go to the new line over and over during the execution of my program
slmw
Profile Blog Joined October 2010
Finland233 Posts
February 17 2017 21:15 GMT
#16906
Yeah, all the text you enter goes into a buffer which either gets read by your process if you do read from STDIN, or is written to the terminal itself as if you wrote that after the process ended.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 17 2017 21:24 GMT
#16907
well, i successfully completed my first project a weekish early! yay (i worked really hard on it though)
it was a bit harrowing
C is a million times harder to debug than Java
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-02-18 01:40:58
February 18 2017 01:40 GMT
#16908
one of my homeworks include implementing a pointer based list data structure (singly linked).
i'm doing it in python.

while doing timing I noticed my delete was taking too long.
the book we are using says it should take constant time which it wasn't.

I check and it makes sense because I was traversing the list for the previous node to have previous.next point to p.next (if p is the pointer given).

after googling, I found this which says it should be O(n) : https://www.codefellows.org/blog/implementing-a-singly-linked-list-in-python/
which was basically how it was working in my implementation.

what was given in my book basically goes like this (its in pascal but I"ll use pseudo code):

function delete (position)
p=position
p.next = p.next.next


and thats it lol. when using this version of delete, I get constant time but ofc it runs into issues when I try to delete from the back of the list which we are supposed to test as well.

the professor is asking for an implementation that does deletion in constant time but I don't think it's possible with the version the book references. i've already talked with the professor but seriously can't understand him and he didn't seem to understand me (he's an old russian guy and isn't very articulate).

do you guys see any flaws in my understanding of this or is the project asking for something stupid?
TL/SKT
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-02-18 02:31:33
February 18 2017 01:49 GMT
#16909
Which node are you actually deleting is probably where you're running into issues.

When you delete the final node in the list your pointer is at position p. p.next is the final node in the list and it's p.next.next value is null. When you set the node at position p's next value to null you're removing the last node in the list as expected and not causing a problem.

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> [7] -> null


So if I need to delete 7, I want to traverse the list until p.next == 7. p will be at 6. Then I set p.next equal to p.next.next. The resulting list:

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> null



Consider the difference between delete(value) and delete(pointer). In the latter you've already done the search which is causing the discrepancy. The delete(value) function runs in O(n) time because you must traverse the list to find the node. However, the function signature looks like you're telling it to delete a pointer after you've traversed the list making it a O(1) deletion time. There is no search in the pseudo code.

Same example, but with delete(pointer):
function delete(6)
p=position
p.next = p.next.next


p.next.next is null. Set p.next equal to null and node 7 is removed in constant time.
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
Last Edited: 2017-02-18 03:05:50
February 18 2017 02:28 GMT
#16910
Is this the proper way to negate this statement?

statement: for all x, there exists y [x < y^2]

negation: for all y, there exists x [ x > y^2]

edit: it would be x >= y^2, huh
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-18 03:11:04
February 18 2017 03:06 GMT
#16911
On February 18 2017 11:28 travis wrote:
Is this the proper way to negate this statement?

statement: for all x, there exists y [x < y^2]

negation: for all y, there exists x [ x > y^2]


not (for all x, there exists y such that x < y^2)

there exists x, not (there exists y such that x < y^2)

there exists x, such that for all y, not (x < y^2)

there exists x, such that for all y, x >= y^2


the order is wrong and it's >=
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-18 03:15:07
February 18 2017 03:13 GMT
#16912
the order matters?

I thought I remembered the professor saying the order matters for this, but when I conceptualized it I couldn't see the difference between

there exists x, such that for all y

and

for all y, there exists x


edit: ok nevermind after thinking it about it some more I do see the difference. in the 2nd statement it means that it is for all y this thing happens universally, and in the first one that isn't the case

thank you, Blisse
kiemcom
Profile Joined February 2017
Bahrain2 Posts
February 18 2017 03:19 GMT
#16913
--- Nuked ---
Hanh
Profile Joined June 2016
146 Posts
February 18 2017 03:35 GMT
#16914
On February 18 2017 12:13 travis wrote:
edit: ok nevermind after thinking it about it some more I do see the difference. in the 2nd statement it means that it is for all y this thing happens universally, and in the first one that isn't the case


Not sure what you mean by that, the 1st statement is stronger than the 2nd. (1) is false but (2) is true.

Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-18 04:04:46
February 18 2017 03:59 GMT
#16915
On February 18 2017 12:13 travis wrote:
the order matters?

I thought I remembered the professor saying the order matters for this, but when I conceptualized it I couldn't see the difference between

there exists x, such that for all y

and

for all y, there exists x


edit: ok nevermind after thinking it about it some more I do see the difference. in the 2nd statement it means that it is for all y this thing happens universally, and in the first one that isn't the case

thank you, Blisse


I find it helpful to read the quantifiers out.


(1) for all y, there exists x [ x > y^2]

for every value of y, there is at least one value of x where x > y^2



(2) there exists x, such that for all y, x >= y^2

there is at least one value of x, where for every value of y it is true that x >= y^2


In this case it's clear that in (1) each y can map to a different x, whereas in (2) one x maps to all y.
There is no one like you in the universe.
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-02-18 06:00:13
February 18 2017 05:29 GMT
#16916
On February 18 2017 10:49 Blitzkrieg0 wrote:
Which node are you actually deleting is probably where you're running into issues.

When you delete the final node in the list your pointer is at position p. p.next is the final node in the list and it's p.next.next value is null. When you set the node at position p's next value to null you're removing the last node in the list as expected and not causing a problem.

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> [7] -> null


So if I need to delete 7, I want to traverse the list until p.next == 7. p will be at 6. Then I set p.next equal to p.next.next. The resulting list:

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> null



Consider the difference between delete(value) and delete(pointer). In the latter you've already done the search which is causing the discrepancy. The delete(value) function runs in O(n) time because you must traverse the list to find the node. However, the function signature looks like you're telling it to delete a pointer after you've traversed the list making it a O(1) deletion time. There is no search in the pseudo code.

Same example, but with delete(pointer):
function delete(6)
p=position
p.next = p.next.next


p.next.next is null. Set p.next equal to null and node 7 is removed in constant time.


Hi, thanks for this.
So I guess my confusion comes from my 'end' function not really being the true end of the list.

For example on my list x: 1 -> 2 -> 3 -> 4

If I ask for x.end(), it will give me a pointer to 3
so I will have to do x.delete(end().next) for it to delete the last node properly.

It seems so unintuitive for me to have 'end' not really be the end of the list, but apparently it has to work that way for me to implement the rest of the functions the way the book wants it.

If I have 'end' return me a pointer to the actual last node with data in it, I can't delete the last node in constant time.

Is this correct?

edit:

I feel like this isn't quite correct either because it isn't consistent.
If I have an empty list, end() will give HEAD. which is not the second to last in the list. so if I want to 'insert from the back' using end(), I would have to do x.insert(end()) for the first insertion instead of x.insert(end().next)

this seems like terrible practice.

edit2:

I'm still getting constant time for my results, but now that I think about it I guess it makes sense?

Because I'm using end() to delete from the back, which is O(n), the total time it takes to delete from the back of a list should take O(n) because of the traversal even if the deletion itself is O(1).

My traversal is basically p=p.next as long as p.next is not null.

my results on running tests on my implementation of a list with array, a list with pointers, and python default list:

traversal: all fairly similar but python>list w/ array>list w/ pointers
insert in front: python> pointers >array(O(n))
insert in back: python > array > pointers(O(n))
delete from front: python > pointers > array(O(n))
delete from back: python > array > pointers(O(n))

seems fine? though I'm curious how python's default list is so much faster in every way possible
TL/SKT
Yurie
Profile Blog Joined August 2010
12178 Posts
Last Edited: 2017-02-18 06:26:59
February 18 2017 06:20 GMT
#16917
On February 18 2017 14:29 dsyxelic wrote:
Show nested quote +
On February 18 2017 10:49 Blitzkrieg0 wrote:
Which node are you actually deleting is probably where you're running into issues.

When you delete the final node in the list your pointer is at position p. p.next is the final node in the list and it's p.next.next value is null. When you set the node at position p's next value to null you're removing the last node in the list as expected and not causing a problem.

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> [7] -> null


So if I need to delete 7, I want to traverse the list until p.next == 7. p will be at 6. Then I set p.next equal to p.next.next. The resulting list:

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> null



Consider the difference between delete(value) and delete(pointer). In the latter you've already done the search which is causing the discrepancy. The delete(value) function runs in O(n) time because you must traverse the list to find the node. However, the function signature looks like you're telling it to delete a pointer after you've traversed the list making it a O(1) deletion time. There is no search in the pseudo code.

Same example, but with delete(pointer):
function delete(6)
p=position
p.next = p.next.next


p.next.next is null. Set p.next equal to null and node 7 is removed in constant time.

If I have 'end' return me a pointer to the actual last node with data in it, I can't delete the last node in constant time.

Is this correct?


You could if you used a double linked list instead of a single linked list. That makes each position take up more space though since you have the element, pointer to next AND pointer to previous.

Basically a question of what action you will be performing on the list. If you add and remove at the start you don't even need an end pointer since you never need to find the last element (unless you use a check on it to see if it is the last element before doing first as null). LIFO / Stack is other terms for that type of list.


As for the rest, don't know about python so can't comment on its standard lists.
Acrofales
Profile Joined August 2010
Spain18485 Posts
Last Edited: 2017-02-18 07:14:25
February 18 2017 07:12 GMT
#16918
On February 18 2017 12:13 travis wrote:
the order matters?

I thought I remembered the professor saying the order matters for this, but when I conceptualized it I couldn't see the difference between

there exists x, such that for all y

and

for all y, there exists x


edit: ok nevermind after thinking it about it some more I do see the difference. in the 2nd statement it means that it is for all y this thing happens universally, and in the first one that isn't the case

thank you, Blisse

Try thinking of an example:

For all x there exists a y, such that x > y

Which one is the negation, and does the order make a difference?
(1) Exists x such that for all y, x < y
(2) For all x, there is a y, such that x < y

Well, let's start with the second one. Let's assume integers. Is there an integer that satisfies this condition? Yes. An example is x=4. We choose y=5 and our statement holds. However the problem is that the original statement also holds for integers. E.g. x=4 and y=3. So clearly (2) is not the negation of our original statement.

(1) says something different. It says that firstly, x is minimal and that that x exists in the set. This clearly doesn't hold for integers, because for any integer x, we can choose y=x-1, and invalidate that statement. So from an example, we can see we might be on the right track. Now let's try natural numbers. In this case, the original statement is false. Choose x=0, and you cannot find a y in N that satisfies x > y. Statement (1) still holds (statement (2) also holds, but we don't care).

Now normally you wouldn't go about it in this manner: you would simply use whatever formal system you're using to prove that (1) is the negation of the original statement (as Blisse already did), but when in doubt, filling in examples is a good way to understand what is going on.

Re Hahn: it's not true that (1) is a weaker or stronger version of (2). They say completely different things about the set. The original statement says there is no minimum element. (1) says there is a minimum element. (2) says nothing about minima, but instead says there is no maximum element. For instance, (1) is true for the set [0, 1,2], but (2) is not (and neither is the original statement).
Hanh
Profile Joined June 2016
146 Posts
February 18 2017 07:40 GMT
#16919
On February 18 2017 16:12 Acrofales wrote:
Re Hahn: it's not true that (1) is a weaker or stronger version of (2). They say completely different things about the set. The original statement says there is no minimum element. (1) says there is a minimum element. (2) says nothing about minima, but instead says there is no maximum element. For instance, (1) is true for the set [0, 1,2], but (2) is not (and neither is the original statement).


OK, but you misquoted me. I wasn't referring to these statements.

Travis:

there exists x, such that for all y

and

for all y, there exists x


Me:

Not sure what you mean by that, the 1st statement is stronger than the 2nd. (1) is false but (2) is true.


Do you disagree with me?

dsyxelic
Profile Joined May 2010
United States1417 Posts
February 18 2017 08:11 GMT
#16920
On February 18 2017 15:20 Yurie wrote:
Show nested quote +
On February 18 2017 14:29 dsyxelic wrote:
On February 18 2017 10:49 Blitzkrieg0 wrote:
Which node are you actually deleting is probably where you're running into issues.

When you delete the final node in the list your pointer is at position p. p.next is the final node in the list and it's p.next.next value is null. When you set the node at position p's next value to null you're removing the last node in the list as expected and not causing a problem.

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> [7] -> null


So if I need to delete 7, I want to traverse the list until p.next == 7. p will be at 6. Then I set p.next equal to p.next.next. The resulting list:

HEAD -> [1] -> [2] -> [3] -> [4] -> [5] -> [6] -> null



Consider the difference between delete(value) and delete(pointer). In the latter you've already done the search which is causing the discrepancy. The delete(value) function runs in O(n) time because you must traverse the list to find the node. However, the function signature looks like you're telling it to delete a pointer after you've traversed the list making it a O(1) deletion time. There is no search in the pseudo code.

Same example, but with delete(pointer):
function delete(6)
p=position
p.next = p.next.next


p.next.next is null. Set p.next equal to null and node 7 is removed in constant time.

If I have 'end' return me a pointer to the actual last node with data in it, I can't delete the last node in constant time.

Is this correct?


You could if you used a double linked list instead of a single linked list. That makes each position take up more space though since you have the element, pointer to next AND pointer to previous.

Basically a question of what action you will be performing on the list. If you add and remove at the start you don't even need an end pointer since you never need to find the last element (unless you use a check on it to see if it is the last element before doing first as null). LIFO / Stack is other terms for that type of list.


As for the rest, don't know about python so can't comment on its standard lists.


Unfortunately as it is a school assignment we were told to follow the design of the example given in our CS book which in this particular case is a singly linked list.

Another part of the assignment is running time tests on our procedures. We had to test both insertion from the front and insertion from the back. Insertion from the back was giving me this issue regarding how to define end() and delete()
TL/SKT
Prev 1 844 845 846 847 848 1032 Next
Please log in or register to reply.
Live Events Refresh
IntoTheTV X SOOP
11:00
Replaycast Group C
PiGosaur Cup
09:30
#105
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 154
StarCraft: Brood War
Rain 3289
Leta 529
Mong 308
Hyuk 286
Shine 85
Dewaltoss 65
910 37
ProTech28
NotJumperer 16
soO 15
[ Show more ]
Force[name] 6
Other Games
summit1g11022
Happy329
Livibee147
Sick94
Organizations
Other Games
gamesdonequick724
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Azhi_Dahaki57
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2380
League of Legends
• Rush1363
• Stunt583
Other Games
• Shiphtur536
Upcoming Events
The PondCast
2h 3m
Kung Fu Cup
3h 3m
IntoTheTV X SOOP
1d 3h
SHIN vs GuMiho
Clem vs Classic
OSC
1d 14h
WardiTV Invitational
2 days
GSL
2 days
Epic.LAN
2 days
Replay Cast
2 days
Sparkling Tuna Cup
3 days
Epic.LAN
3 days
[ Show More ]
AI Arena Tournament
3 days
Yamato Cup
4 days
Map Test Tournament
4 days
WardiTV Weekly
5 days
Replay Cast
5 days
Rogue vs Classic
Patches Events
6 days
PiGosaur Cup
6 days
Liquipedia Results

Completed

Proleague 2026-10-27
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 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.