Counting like a Computer Scientist

For the following linked list that is 0-indexed, what number is on index position [3]?

9 8 7 6 5 4 3 2 1 0 9 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 5 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 0

7 3 2 6

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Brock Brown
Sep 30, 2015

In computer science, it's standard to use the natural numbers (0, 1, 2, ...) to label list positions: the first element will always be in position 0.

0 holds 9, 1 holds 8, 2 holds 7, and finally 3 holds 6 \boxed{6} .

I think you meant whole numbers instead of natural numbers

Arulx Z - 5 years, 7 months ago

Log in to reply

Some authors define natural numbers to start at 0, some people define the sequence to start at 1. I guess it's a little bit of an ambiguous term. It's like how some people define the first two terms of the Fibonacci sequence to be (0, 1) and some people define the first terms as (1, 1).

You're right though, saying whole numbers make it a lot clearer.

Brock Brown - 5 years, 7 months ago

Yes it is whole numbers instead of natural numbers

Ankan Mitra - 1 year, 7 months ago
Ankan Mitra
Nov 9, 2019

In computer science, Always the indexing start from the whole number 0 and from the figure it can be easily seen that counting is start from the left hand side, So give the left most digit the index number 0 and start counting :)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...