<p>I assume the linked list analogy just arises because of the reference to the previous block as you say. It's less about how to find that block, and more just about identifying it. The actual data structure used to store the Blockchain isn't what is being described.</p>

CC BY-SA 4.0
2018-10-22T19:15:58.810Z
Thank you for the clarification. I was confused by diagrams where one block references previous block and thought you had to traverse the chain in reverse until I started digging into it some more.
Huy
CC BY-SA 4.0
2018-10-22T19:13:01.783Z
2018-10-22T19:13:01.783Z
meshcollider
<p>I often hear people say that a blockchain is essentially a linked list (i.e. <a href="https://www.quora.com/Is-a-blockchain-essentially-a-linked-list" rel="nofollow noreferrer">https://www.quora.com/Is-a-blockchain-essentially-a-linked-list</a>)</p>

<p>A block stores the hash of the previous block for validation/consensus. This is similar to how a node in a linked list references the address of the previous node, but it's not quite the same. </p>

<p>In a block, the previous hash is stored by value, not by reference, so you can't really access the previous node by traversing the chain. Whereas in a linked list, you store the address which is a reference to the previous node. You can access any block in constant time where as in a linked list, it's linear time. </p>

<p>On top of this, many implementation that I've seen of a blockchain is an array/slice of blocks. I tried briefly looking at <a href="https://github.com/bitcoin/bitcoin/blob/master/src/chain.cpp" rel="nofollow noreferrer">bitcoin's source code</a> (disclaimer: I don't know C++). It looks like the implementation of the chain of blocks in memory uses <code>std::vector</code> which is basically a dynamic array.</p>

<p>Isn't a blockchain more similar to an array than it is to a linked list?</p>

<blockchain>
Why is a blockchain often compared to a linked list?
Huy
# Why is a blockchain often compared to a linked list?

(Asked by: username_0 on 2018-10-22)

I often hear people say that a blockchain is essentially a linked list (i.e. <https://www.quora.com/Is-a-blockchain-essentially-a-linked-list>)

A block stores the hash of the previous block for validation/consensus. This is similar to how a node in a linked list references the address of the previous node, but it's not quite the same.

In a block, the previous hash is stored by value, not by reference, so you can't really access the previous node by traversing the chain. Whereas in a linked list, you store the address which is a reference to the previous node. You can access any block in constant time where as in a linked list, it's linear time.

On top of this, many implementation that I've seen of a blockchain is an array/slice of blocks. I tried briefly looking at [bitcoin's source code](https://github.com/bitcoin/bitcoin/blob/master/src/chain.cpp) (disclaimer: I don't know C++). It looks like the implementation of the chain of blocks in memory uses `std::vector` which is basically a dynamic array.

Isn't a blockchain more similar to an array than it is to a linked list?

**Tags:** blockchain


---

## 1 answers

### Answer by username_1 on 2018-10-22. Score: 2 | Accepted answer

I assume the linked list analogy just arises because of the reference to the previous block as you say. It's less about how to find that block, and more just about identifying it. The actual data structure used to store the Blockchain isn't what is being described.

> **Comments:**
> **username_0**: Thank you for the clarification. I was confused by diagrams where one block references previous block and thought you had to traverse the chain in reverse until I started digging into it some more.  

---

