Data Structure - Queue

In the last post of the series, we looked at the linked list - the basic form of data structure. In this part, we will look at the specialized type of a linked list - a queue.

The queue is nothing but a linked list, and the protocols to add and remove data from the queue are specified in a certain way. These specific constraints, when applied to a linked list, gives us a queue.

Data Structure - Queue

The queue of the software realm acts quite similar to the queue you find in real life. It is quite similar to the queue you find at movie theaters or bank teller counters. When people need to join the queue, they do so from behind - at the end of the queue. When they need to leave the queue, it is done at the starting point of the queue. The protocol is said to be ‘first in, first out’.

Read the rest of this entry »

Data Structure - Linked List

Data structures give order to the abstract world of code (software). There are many types of data structure. Among them linked list is the most fundamental type of data structure. Using one or another form of linked list, other data structures (queues or stacks for example) can be created.

Let us look at the theory behind linked list. I promise to try and make it interesting.

Data Structure - Linked List

The basic unit of a linked list is what is called a node. A node is something like a Lego brick, many of which you can combine to create something. As with the Lego brick, there are different types of nodes, but the most basic form contains a data element and a reference element.

  • Data Element - As the name suggests, the data element holds the data. It can be anything from simple data like numbers or characters, to complex data like a record holding the details of a song in a music album.
  • Reference Element - Reference element is of the node can either be empty or be containing the information of where the next node of the list is present. When implemented in machine code, it has the address within the memory where the next node is residing.

Read the rest of this entry »

Data Structures - Structuring Abstract

As we came to the end of the Journey Of Code series, we moved on from the realm of hardware and stepped into the world of software - the abstract world. Software can be called abstract because there is really no physical structure for it. And these abstract concepts can easily become disorganized.

The software can be broadly classified to be code and data. When we say data - it is meant the whole concept of storing the data, and also how the data is stored.Data Structure

The data structures are protocols or concepts that say how the data is stored. By storing it in a particular way - a particular operation on the data is optimized in terms of memory required and also time required to perform the operation. A well designed data structure needs to perform set of operations using as few resources (time and memory) as possible.

You must realize though, that there is no ideal type of data structure to this date. Every data structure has its own set of advantages and disadvantages based on the operations it is subjected to. That is the reason why there are different data structures which are used in situations where they perform the best.

The different data structures are made up of units called native data types and references. They are called by different names in different languages. By using these units in a certain way, different kinds of data structures can be constructed.

Some of the types of data structures are as follows.

  • linked lists
  • queues
  • stacks
  • trees
  • graphs

This is not a exhaustive list - there are many more.

But we can look at some of them - and that is what we will be doing in the posts that will follow in this series.

Journey Of Code - Applications

The series, Journey Of Code, comes to an end with this post. During this journey we have explored the technology stack from transistors, logic gates, chip level units, processors and the interface between the hardware and software – machine code.

The exploration has led us to the realm of software. It may be an end to this series, but it is a realm that deserves several such journeys. We will though, briefly look into the different aspects of software and applications.

Software - Hardware InterfaceAs we have seen in the earlier post, the machine code is written using the mnemonic – assembly language. In spite of the use of these human readable syntax, it can get quite complex and cumbersome to design applications that would serve any purpose more than simple calculator. Even a calculator application could get out of hand.

To alleviate from this problem, high level languages were created. These programs take more complex syntax which make it simpler to write programs, and compile them into machine code. Applications can be made to perform several complex tasks with the help of the code that is generated from compiling the programs written in high level languages.

The processors, as we have seen can perform a basic set of operations. These set of operations when combined in a certain way perform myriad of tasks. In order to reduce the size of applications and also to manage the loading and execution of these programs, operating systems were designed.
Read the rest of this entry »

Journey Of Code - Machine Level

In the last article of this series, Sandy explained, how at the processor level, everything is orchestrated to make the machine perform actions. The particular actions among the many that can be performed by the processor is determined by the code.

The machine code is the lowest level of abstraction in software terms. It is the bridge between the software and the hardware.

Technology StackThe machine code are patterns of bits that carries the information on what the processor should be doing. Every processor model will have its own set of machine code. (And that is the reason why programs written in machine level are very hard to port from one model of processor to another).

The machine code, as mentioned earlier are patterns of bits. A set of machine code is called a program and it performs a higher level task. The programs in machine codes are represented as ‘0’s and ‘1’s; they are more conveniently written down as hexadecimal codes (or hex codes).

Another level of abstraction is the ‘Assembly Language’. These are mnemonics that refer to the machine code on a one to one basis. What that means is that every pattern of code would have a assembly language word (English) to represent it.

The codes usually contain to parts - the operator and the operand. Some of the codes have no operands and the word itself holds the information of the task to be performed. An example of a two operand code in the 8086 series of processors is the MOV operation.

MOV A B

That simple code instructs the processor to move the data held in one register to another. (Register is on-processor word-sized memory).

There are other codes that would instruct the processor to add, subtract, multiply, or perform logic operations like AND, OR, XOR on data held in two or more registers and store it in another register. There would be even jumps and other flow control codes that would allow a small program to perform relatively complex tasks.

The actual set of codes, would differ from one processor model to another. It also depends on the type of processor architecture like MISC, RISC or CISC.

The machine level programs allow the interface between the processor and the higher levels. It frees the software designers (to some extent) from the intricate micro-operations that are required to be performed by the processors and focus on the higher level tasks.

In the next post, we will look at the proverbial end of the journey into the realm of software. This may be the end of journey for the hardware, but opens up a large realm where the design of software seems to break through paradigms every now and then.

Journey Of Code - Processors

In earlier posts we have seen the circuit level components. Now if we put all of them together, we get a system. A system can be designed to perform a specific task or to perform task as per user requests.

A general purpose processor is a system where in the user tells the processor what needs to be done. A processor system generally consists of a computing unit (ALU/FPU), control unit and storage unit(registers/cache/RAMs). The user tells the processor what needs to be done by means of something called “op-code”. A op-code or operation-code is a set of byte/bytes which the control unit of the processor understands. Processor systems can be classified into 3 categories based on their op-code types.

Technology Stack

  • MISC
  • RISC
  • CISC

MISC or Minimal Instruction Set Computer is the most basic of the lot. This processor architecture uses a stack for storage. And the requested operation is performed on the contents of top of the stack. Because of the stack based architecture, the applications of this architecture was very limited. So this architecture did not have large fan followers.

RISC or Reduced Instruction Set Computer is the next step. This processor architecture is based on registers. All the operations are based on these registers. This architecture is actually the most popular, and unknown to many; this is the highly used architecture. This architecture gives a lot of benefits due to small footprint and high execution speed due to reduced complexity. These have very small op-codes and executed them very fast. The most famous processors using this architecture are from ARM.

CISC or Complex Instruction Set Computer is the most complex of the lot. This architecture can do almost everything the other two can do, plus few more things. This architecture can do complex things with a single op-code. This is the most famous architecture among the three. All the processors found in PCs/servers these days follow this architecture.
Read the rest of this entry »