Posts

Showing posts with the label data structure python

Data Structures and Algorithms - Arrays (2)

Image
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array. Element  − Each item stored in an array is called an element. Index  − Each location of an element in an array has a numerical index, which is used to identify the element. Array Representation Arrays can be declared in various ways in different languages. For illustration, let's take C array declaration. Arrays can be declared in various ways in different languages. For illustration, let's take C array declaration. As per the above illustration, following are the important points to be considered. Index starts with 0. Array length is 10 which means it can store 10 elements. Each element can be accessed via its index. For example, we can fetch an element at index 6 as 9. Basic Operations Following are the basic operations supported

Data Structures & Algorithms - Quick Guide (Step By Step) (1)

Image
  Overview Data Structure is a systematic way to organize data in order to use it efficiently. Following terms are the foundation terms of a data structure. Interface  − Each data structure has an interface. Interface represents the set of operations that a data structure supports. An interface only provides the list of supported operations, type of parameters they can accept and return type of these operations. Implementation  − Implementation provides the internal representation of a data structure. Implementation also provides the definition of the algorithms used in the operations of the data structure. Characteristics of a Data Structure Correctness  − Data structure implementation should implement its interface correctly. Time Complexity  − Running time or the execution time of operations of data structure must be as small as possible. Space Complexity  − Memory usage of a data structure operation should be as little as possible. Need for Data Structure As applications are gettin

Introduction to Linked List| Data Structure with Python

Image
   Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at a contiguous location. The element are linked using pointers. Why Linked list is used:- Arrays can be used to store linear data of similar types, but arrays have the following limitations. Array's size is fixed. So we must know the highest limit of the array in advance. So we must declare the size of the array first and elements there after.  Inserting a new element is very expensive because the room has to be be created for the new elements and shift the existing elements. Ex :- Suppose we have arrays in sorted order   i.e. [1,2,3,4,6,7]  and we have to insert new element   i.e. [5]   in the array. So in order to maintain elements in sorted order, we have to place that element after suitable element. In this situation we have to shift the element   i.e. [6,7] by position 1. Now  we saw the arrays limitations. Let's understand the advantages of the Linked List over array.  Advantage