Tuesday, 13 June 2017

Introduction to Data Structures

The concept of Data Structures is a very important concept in modern computer science. So, in this course we would examine what data structure is all about and then we briefly look at different data structures being used today.

Data and Data Structure

Data can be defined in a number of ways but it would suffice to say that data is a unit of information. An example would be biodata which would include:

Your Firstname

Your Surname

Date of Birth

Address

Etc

So these pieces of information could be referred to as data.

What is Data Structure?

A piece of information(data) could also be a combination of different other pieces of data.

For example,

Name is made up of Firstname, Lastname and Othername

Students Registration Number could be something like:

G2014/MSC/COMP/FT/295

Here we see a single piece of data student registration number, made up of different units like:

G – Graduate

MSC – Masters

COMP – Computer Science

FT – Full Time

295 – Serial number of student in the department

Another example would be Address, which would be made up of House number, Street, zip code etc.

So we can define data structure as the way(or structure) different pieces of data is organized and the relationship between them.

Lets now outline the various data structures in use in computer science.

Arrays

Arrays are the most common data structure in use and it has an implementation in about every programming language.

Definition: An array is a collections of items of the same data type with the collection having a given name and items arranged in a linear fashion such that each item in the array can be referenced by a given integer called the index or subscript.

Example is Fruit(10) made up of 11 element referenced as follows:

Fruit[0]

Fruit[1]

Fruit[2]

…

…

Fruit[9]

Fruit[10]

An array data structure is illustrated below

Linked List

Linked list is a data structure developed to address some of the deficiencies of the Array data structure. In a linked lists, the items are not stored in contiguous manner like arrays. Each item is related to the next item by the use of pointers.

This is illustrated by the figure below

Stacks

A stack is a linear data structure that allows insertions and deletions to be done only from one end of the list called the top. The last item inserted into the list is always the first item to be retrieved from the list. So a stack support Last In First Out (LIFO) data access.

Add ing an item to the top of a stack is called push while retrieving is called pop.

Stack is mainly applied in procedure call in programs.

Queues

A queue is a data structure that allows insertion of items only from one end of the list called the head, while deletions can only be done from the other end called the tail. A queue supports First In First Out(FIFO) data access.

An application of the queue data structure is print jobs. Job sent to the printer are placed in a queue where the first to be sent is the first to be printed.

Trees

A tree data structure is a hierarchical non-linear structure having a particular node called the root and other nodes make up the sub-tree(s). A tree have the appearance of an inverted tree, where the root is on top.

Nodes in a tree are connected by edges or branches. The nodes at the lower-most part of the tree with no sub-trees are called the leave nodes.

Tree data structure is shown below

Graphs

Just like trees, graphs are non-linear data structures made up of a set of nodes and a set of edges. An edge joins two nodes together.

A graph can be directed or non-directed, a graph is directed if the edge joining to nodes have a direction and non-directed if the edge have no direction.

Graph data structure is shown below

Dictionary, Hashing and Hash Tables

Hashing is a techniques applied in the dictionary data structure. Here, two things are used:

A Hash Function

A Hash Table

The hash function is applied to the key of an element to produce a value to represents the location in the hash table where the element would be stored.

This ends out discussion of Introduction to Data Structures. Spends you time to get used to the concepts and definition of each of the data structures before you drill down to the in-depth study of these data structures.

If you find this helpful, leave a comment to let me know. Thanks for your time.