Posts

Stack and Queue Introduction

Image
Stack A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items takes place at one end called top of the stack. The basic concept can be illustrated by thinking of your data set as a stack of plates or books where you can only take the top item off the stack in order to remove things from it. This structure is used all throughout programming. The basic implementation of a stack is also called a LIFO (Last In First Out) to demonstrate the way it accesses data, since as we will see there are various variations of stack implementations. There are many real life examples of stack. Consider the simple example of plates stacked over one another in canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to ...

Multithreading in Java

Image
Multithreading in Java What is Multithreading? Multithreading in java is a process of executing two or more threads simultaneously to maximum utilization of CPU. Multithreaded applications are where two or more threads run concurrently; hence it is also known as  Concurrency  in Java. This multitasking is done, when multiple processes share common resources like CPU, memory, etc. Each thread runs parallel to each other. Threads don't allocate separate memory area; hence it saves memory. Also, context switching between threads takes less time. Multithreading in java is a process of executing multiple threads simultaneously. Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking. But we use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between ...

Linked List and Its Operations

Image
Linked List In a game of Treasure Hunt, you start by looking for the first clue. When you find it, instead of having the treasure, it has the location of the next clue and so on. You keep following the clues until you get to the treasure. A linked list is similar. It is a series of connected "nodes" that contains the "address" of the next node. Each node can store a data point which may be a number, a string or any other type of data. Linked lists are the best and simplest example of a dynamic data structure that uses pointers for its implementation. However, understanding pointers is crucial to understanding how linked lists work and you must also be familiar with dynamic memory allocation and structures. Essentially, linked lists function as an array that can grow and shrink as needed, from any point in the array. Linked lists have a few advantages over arrays: 1.    Items can be added or removed from the middle of the list 2.   ...