Linked List: The OG Blockchain

in #programming5 years ago

Linkedlist.png

That's right!

The Blockchain has been around since the beginning of programming.
A linked this is nothing more than blocks of information chained together.

Each block has information stored in with an address pointer to the next block.

A @null pointer implies the end of the chain.
Want to add a value? No problem:

Linkedlist_insert_middle.png

Simply change the pointer to the new value, and point back to the old value using the new block.

Arrays

C-Arrays.jpg

This is the alternate data storage method. It is called an array. An array is kind of like a linked-list that has been smashed together in memory. You need a big chunk of contiguous memory in order to make room for the array. The advantage of an array is that you no longer need address pointers pointing to the next block of memory. All of the memory is accounted for.

How is all the memory accounted for? Well, the size of every block in an array is of equal length. This means that if you wanted to go to the 1,536,842 element in a big array, the only information you would need was a pointer to the beginning of the array. We then add to that address to the size of a block times 1,536,842 and we can get to the 1,536,842 element in the array instantly in O(1) time.

Conversely, if you wanted to get to the 1,536,842 element of a linked list, you would have to start at the head of the list and check every element to see where to go to next. It would take O(1,536,842) tries to get where we needed to go. This translates to O(n) where n is the number of elements in the list.

array-insertion-1.png

However, what would happen if we wanted to insert an element into the array? We can't do it easily, because all of the memory is in a solid block. We'd have to shift all the memory left or right to make room for the new block. It is a relatively expensive operation given a large array, so arrays and linked lists have many flaws and weaknesses that compliment each other if the programmer needs to optimize their code for speed.

The interesting thing about needing to optimize code is that for small projects you often never need to do so. Computers these days are so blazing fast that one rarely needs to wonder if they should use a linked list or an array. The front end will run exactly the same either way in most situations.

In fact, I tried to look up how to use a linked list in JavaScript and it's actually not that easy. The native container is an array by default, and if you need to use a linked list you have to import a special module to do so. Personally, I've always preferred arrays over linked lists anyway.

However, novice programmers will not even know the difference. The frontend functionality of linked lists and arrays can be exactly the same. They can both add, remove, and access information. In many situations you would never know which one was being used unless you looked it up.


bandwidth-tech.jpg

Lowering the bar

Advancements in technology have allowed us to get very sloppy and inefficient (Sound like anything you know? Spoiler: crypto). Scripting languages like Python and JavaScript allow us to greatly simplify the complexity of the code we write at the cost of efficiency. This creates higher overhead processing costs but can make the code much shorter and easier to read, upgrade, and maintain.

I have a friend who told me he programmed a Pac-Man clone called Tax-Man in assembly:

assembly.gif

Seriously, assembly is a fucking nightmare. This is what programmers had to use before Object Oriented Programming came around. It is blazing fast. It has access to the cache memory of the CPU and all kinds of other optimization goodies, but reading, updating, and maintaining it is a lot of work.

It took my friend 6 months to program Tax-Man in assembly.
He would be able to do it in a week with a higher level language.

Here's some JavaScript I wrote today:

let order = [
    {'unit':'rowdy', 'weapons':600, 'alcohol':0, 'attack':2, 'hp':2},
    {'unit':'bouncer', 'weapons':1400, 'alcohol':1300, 'attack':6, 'hp':10},
    {'unit':'knifer', 'weapons':3000, 'alcohol':800, 'attack':12, 'hp':5},
    {'unit':'big_mama','weapons':9000,'alcohol':12000,'attack':12,'hp':110},
    {'unit':'ninja', 'weapons':7000, 'alcohol':7000, 'attack':50, 'hp':20},
    {'unit':'gunman', 'weapons':3600, 'alcohol':3200, 'attack':25, 'hp':12},
    {'unit':'sniper', 'weapons':3000, 'alcohol':5600, 'attack':40, 'hp':8},
    {'unit':'hitman', 'weapons':10000, 'alcohol':0, 'attack':30, 'hp':15},
    {'unit':'bazooka','weapons':15000,'alcohol':13000,'attack':145,'hp':25},
    {'unit':'mercenary','weapons':19000,'alcohol':14000,'attack':120,'hp':75}
]

Much easier

The above structure is an array of objects that store @drugwars unit information.

A compiler will take this code and interpret it down to lower level languages until it finally ends up as Machine Code (ones and zeros).

to-machine-code.png

js-code-example.jpg

bytecode.png

bytecode2.png

machine-code.png

matrix-code.jpg

Because the JavaScript is naturally inefficient compared to lower level languages, we have to hope that the compiler AI is smart enough to optimize it for us as much as possible.

running-times-order-n.gif

Big O notation

When optimization is required code is looked at using Big O notation. How many CPU cycles will it take to get the job done? Big O notation is a very rough estimation. Traversing a linked list only takes n/2 attempts on average, but the Big O notation gets rounded up to O(n). We don't care about +50 or x2. We are looking at upper bound worst-case scenario.

The main Big O classifications are:

  1. O(1) - Got there on the first try with no regard to the size of the data structure.
    O(4235897) would still round down to O(1) if that number has nothing to do with n.

  2. O(n) - For every element in the list, it takes that many tries to find the answer.

  3. O(n^2) - Polynomial Complexity; O(20n^2 + 500n + 8000) rounds down to O(n^2).

  4. O(2^n) - Exponential Complexity; This is the worst of the worst.
    Referred to as "Non-Polynomial" (NP) this is the worst complexity.
    Second only to an even worse NP problems like Factorial O(!n)
    This extremely inefficient complexity is what allows encryption to be secure.

  5. O(log(n)) - Better than O(n); basically the opposite of exponential.
    Often can be a solution using binary searches where half of all possibilities are pruned on every round.

  6. O(n*log(n)) - Worse than O(n) but better than O(n^2)

learn-blockchain.png

Grossly Off Topic

The original intention of this post was not meant to be a lesson in basic computer science. All I really wanted to do what show that blockchain isn't special or new. This structure has existed since the 1950's. The truly revolutionary thing about blockchain is that no one can control it.

Imagine a Linked List that can't be controlled by the person who downloads it. That's what cryptocurrency is. The thing that makes Distributed Ledger Technology unique is the decentralized nature of block production.

This is why centralized blockchains are an absolute joke, they bring absolutely nothing to the table. They are a step in the wrong direction; a farce designed by the elite to continue consolidating as much power as humanly possible.

Through the process of mining and/or stake-based consensus, we've managed to create systems that are highly resistant to being controlled by any one entity. This technology is evolving exponentially faster than the traditional systems designed to contain and control up-and-coming innovations.

The world will be a much different place in another ten years.

It's hard to imagine life without present-day internet and smartphones. That is going to happen with money, and because money is the foundation of the entire economy; the lifeblood of the language of value exchange, the transition is going to be far more violent and disruptive than the Internet ever could have been.

stamina bar.jpg

Lowering the bar 2.0

Software development is a constant struggle of trying to onboard as many users as possible. Simplicity and elegance are always in short supply. Developers create programming languages so other developers can work faster. Those developers create apps for the common person so that they can engage with the new tech. Even Steemit is an attempt at lowering the bar so anyone can get paid to blog.

The point is: now that money has been open-sourced things are going to accelerate at incredible speeds once the tipping point is reached and everyone has convenient access to the value built on these networks. The ability for anyone to work on open source projects and get paid to participate will catapult the entire world into the future.

The economy of the future is Open Source.

A return to healthy competition, free-market, and cooperation is just on the horizon.
Sort:  

I’m over here wondering why such a great post got flagged... Smh.

No worries, friend!
It's because of my @drugwars exploits.

Check my most recent post for the answer.

https://steemit.com/drugwars/@edicted/drugwars-pay-to-lose-ngc-and-z8teyb289qav9z-army-destroyed-wave-berniesanders

Seems a little petty, lol! Oh well, cheers m8

You had me until Tax Man but agree to your point; no turning back to inefficiency as we continue to evolve in the many processes today that are based kn control. I will expect the push to start soon as disruption takes hold in financial markets.

Posted using Partiko iOS

Yeah I went way overboard with machine code and big O notation.

Yeeaaa!
Voluntarism

Posted using Partiko Android

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 23 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.

I upvoted your contribution because to my mind your post is at least 6 SBD worth and should receive 134 votes. It's now up to the lovely Steemit community to make this come true.

I am TrufflePig, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!

Have a nice day and sincerely yours,
trufflepig
TrufflePig

Congratulations @edicted! You received a personal award!

DrugWars Early Access
Thank you for taking part in the early access of Drugwars.

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Are you a DrugWars early adopter? Benvenuto in famiglia!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Highly rEsteemed!

blockchain_consensus_linked_reject.png

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Edicted from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Coin Marketplace

STEEM 0.32
TRX 0.11
JST 0.034
BTC 66761.99
ETH 3256.83
USDT 1.00
SBD 4.27