Introduction:
Seeing as TheNibbleByte have an audience of GCSE students, A Level students and maybe some degree students, I thought that it would be beneficial to talk about Data Structures, given that this is often a challenging area of the syllabus.
Definition:
A Data Structure is a 'specialised format for organising, processing, retrieving and storing data'. They can be categorised into 'linear' and 'non linear' (more on that in future posts!!!
Theory:
A list is simply a collection of elements in which the same element may appear multiple times.
They can be either static (using arrays) or dynamic.
They are mutable, allowing their contents to change (see the operations below!).
[] are used to represent a list, with elements inside, separated by commas.
List Operations:
isEmpty() - Tests if the list is empty, returning a boolean (True/False).
append(item) - Adds a new item to the end of the list.
remove(item) - Removes the first occourance of an item, from the list.
search(item) - Tries to find the item in the list, returning a boolean (True/False).
length(item) - Returns the number of items in a list, int.
index(item) - Returns the position of an item in the list.
insert(pos,item) - Inserts a new item in the list, at that position.
pop() - Removes and returns the last item in the list.
pop(pos) - Removes and returns the item at the specified position.
Representing Lists Using Arrays:
We haven't yet talked about Arrays (that will happen in the next few weeks) but an Array is 'a finite, ordered set of elements'.
Useful if the maximum number of elements is known in advance.
Implementation in Python and Java:
Python:
Most of the methods for lists are built in however I did have to build a couple myself.
Java:
Most of the methods are built in which makes things easy.
CHALLENGE:
If you want to test yourself, try and implement the search(item) operation in JAVA. Let me know in the comments that you've done it, or at least given it a go.
Conclusion:
Lists are a simple way of storing a collection of elements.
They have many useful operations.
Make sure you attempt the challenge!!
DISCLAIMER: This isn't an exclusive list of things about Lists. There's more information out there for you to find out. Don't limit yourself to this post, find out more!!
Final Things:
If you have any topics that you want me to blog about then please let me know in the comments!!!
Make sure you like, comment, share this blog post.
Follow CompAndCode on all platforms!
Thank You TheNibbleByte!!
Hashtags: #computerscience #coding #programming #technology #python #programmer #computer #tech #developer #coder #java #javascript #code #codinglife #webdeveloper #softwareengineer #engineering #machinelearning #softwaredeveloper #html #programmers #software #artificialintelligence #computerengineering #linux #datascience #cybersecurity #programmingmemes #hacking #bhfyp #informationtechnology #programminglife #hacker #css #pythonprogramming #php #webdesign #ai #science #programmerlife #codingmemes #deeplearning #developers #programmerhumor #coderlife #codingisfun #computers #kalilinux #developerlife #development #ethicalhacking #softwareengineering #computerprogramming #windows #coders #codingbootcamp #security #geek #daysofcode #programmingisfun #compandcode
Comments