What is the point of indexing arrays 0...n-1? why is it better than indexing 1...n?

what is the point of indexing arrays 0...n-1? why is it better than indexing 1...n?

Attached: 1582219666127.jpg (960x960, 82K)

Other urls found in this thread:

cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
en.m.wikipedia.org/wiki/Zero-based_numbering
imgur.com/27JmibQ
blog.usejournal.com/arrays-start-at-zero-whats-up-with-that-f2d1054c9b77
twitter.com/SFWRedditImages

get off Cred Forums and go back to your csci-101 class

so you don't know.

so you don't know.

so you don't know.

Is this for REII 211?

>indexing arrays 0...n-1
Arrays start at zero - at least, most of the ones in the business sectors, running archaic shit from the 90s. Source: My company still uses FoxPro.

so you don't know.

so you don't know.

Probably simply because binary number go form 0 to 2^n so its represents better what is going on on a lower level.

Also potentially because the index represents the steps you need to take to access the element you want. It's faster to calculate with 0-based index.

e.x. If you want element i=5 (position 6), you start at the address pointing to your array and do ADDR + SIZE*5. where the size of the step is determined by the type of the array.
If it were 1-based, you'd need to do ADDR + (SIZE-1)*6 to access the same element.

I meant form 0 to (2^n)-1 of course

the fuck?

bitwise operations are in bases of 2. 2^0 = 1 which is the start position in an array.

we dont do 0 to n-1 bro lmao, n is the length of the array. if there are 5 elements in the array, the length is 5. given we start at position 0, the last position is n-1 = 4.

0 pos = 1st element
1 pos = 2nd element
etc...

who said n-1 is the length of the array? no one is saying that but you.

so you don't know.

did you read that at all? where tf do i say n-1 is the length?! i said the length is n, the position of the last element in the array is n-1.

kid is dumb asf

But nowadays there's such a thick layer of abstraction between what you write and what the computer is doing that it doesn't really matter. It's mainly for historical reasons.

Some newer languages whose users aren't necessarily "true programming" such as R are 1-indexed

base 2 nature has nothing to do with the choice of indexing starting at 0 or 1. do you even know how to code? actually I take it back. that's all you know how to do but you don't understand anything about the underlying architecture of a cpu. i'm guessing you are a python programmer. have fun with your shitty language and gil.

yeah you don't know shit.

So you don't know

so you don't know?

If you ever use an array with an element count equal 2^x for any positive integer x then you can use x bits to hold that array if you count from 0 to 2^x-1. If you wanted to count to 2^x then you'd need a whole new bit at least.
Also, say your memory is all initialized to 0s, why waste cycles adding 1 to your first element

Just trying to help, but "the fuck?" makes it hard to know what you don't understand...

> is currently googling what the gil is.

im a computer systems engineer lmao, i know more about architectures that you 100%. legit the fucking reason they picked it is cause of base 2. have you read any fucking cpp book ever? legit every book from the infamous dragon book to irwins talks about 0 indexing in c was chosen because of that. other languages are indexed and 1, it legit doesnt matter at all

because indexes are offsets, 0 offset means 1st element in the array, 1 offset, means 2nd and so forth

you're wrong, and I'm right

here's what dijkstra says about it: cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

heres a wikipedia overview: en.m.wikipedia.org/wiki/Zero-based_numbering

point out where it says anything about base 2. you're not too good at this.

so you don't know.

Another way to conceptualise this is how many steps away from the first element in the array do you want to go? n step = n+1 element in an array

imgur.com/27JmibQ

blog.usejournal.com/arrays-start-at-zero-whats-up-with-that-f2d1054c9b77

you really are adamant about something that legit doesnt fucking matter and that again, im not wrong about. you arent wrong either champ. there are tons of sources about zero indexing and tons of theories/reasons about why it starts are zero.

again other languages have 1 indexing, it legit makes no difference. dont get why you gotta throw a hissy fit when what i said is easily verifiable as well