Posts

Showing posts with the label Tress

Data Structure and Algorithms - Stack(8)

Image
  A Stack is a linear data structure that follows the   LIFO (Last-In-First-Out)   principle. Stack has one end, whereas the Queue has two ends ( front and rear ). It contains only one pointer   top pointer   pointing to the topmost element of the stack. Whenever an element is added in the stack, it is added on the top of the stack, and the element can be deleted only from the stack. In other words, a   stack can be defined as a container in which insertion and deletion can be done from the one end known as the top of the stack. Some key points related to stack It is called as stack because it behaves like a real-world stack, piles of books, etc. A Stack is an abstract data type with a pre-defined capacity, which means that it can store the elements of a limited size. It is a data structure that follows some order to insert and delete the elements, and that order can be LIFO or FILO. Working of Stack Stack works on the LIFO pattern. As we can observe in the below figure there are five

Data Structure - Circular Linked List (7)

Image
  Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list. Singly Linked List as Circular In singly linked list, the next pointer of the last node points to the first node. Doubly Linked List as Circular In doubly linked list, the next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions. As per the above illustration, following are the important points to be considered. The last link's next points to the first link of the list in both cases of singly as well as doubly linked list. The first link's previous points to the last of the list in case of doubly linked list. Basic Operations Following are the important operations supported by a circular list. insert  − Inserts an element at the start

Data Structure - Doubly Linked List (6)

Image
  Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. Following are the important terms to understand the concept of doubly linked list. Link  − Each link of a linked list can store a data called an element. Next  − Each link of a linked list contains a link to the next link called Next. Prev  − Each link of a linked list contains a link to the previous link called Prev. LinkedList  − A Linked List contains the connection link to the first link called First and to the last link called Last. Doubly Linked List Representation As per the above illustration, following are the important points to be considered. Doubly Linked List contains a link element called first and last. Each link carries a data field(s) and two link fields called next and prev. Each link is linked with its next link using its next link. Each link is linked with its previous link using its previous link. The

Linked List vs Array | Data Structures and Algorithm.

Image
  Arrays   store elements in contiguous memory locations, resulting in easily calculable addresses for the elements stored and this allows a faster access to an element at a specific index.   Linked lists   are less rigid in their storage structure and elements are usually not stored in contiguous locations, hence they need to be stored with additional tags giving a reference to the next element. This difference in the data storage scheme decides which data structure would be more suitable for a given situation.  Data storage scheme of an array Data storage scheme of a linked list   Major differences are listed below:  Size:   Since data can only be stored in contiguous blocks of memory in an array, its size cannot be altered at runtime due to risk of overwriting over other data. However in a linked list, each node points to the next one such that data can exist at scattered (non-contiguous) addresses; this allows for a dynamic size which can change at runtime. Memory allocation:  For

Data Structure and Algorithms - Linked List (5)

Image
  A linked list is a sequence of data structures, which are connected together via links. Linked List is a sequence of links which contains items. Each link contains a connection to another link. Linked list is the second most-used data structure after array. Following are the important terms to understand the concept of Linked List. Link  − Each link of a linked list can store a data called an element. Next  − Each link of a linked list contains a link to the next link called Next. LinkedList  − A Linked List contains the connection link to the first link called First. Linked List Representation Linked list can be visualized as a chain of nodes, where every node points to the next node. As per the above illustration, following are the important points to be considered. Linked List contains a link element called first. Each link carries a data field(s) and a link field called next. Each link is linked with its next link using its next link. Last link carries a link as null to mark the