Data Structures : Linear List
Introduction
Data Structure
A Data Structure is a named group of data of different data types which is stored in a specific way and can be processed as a single unit. A data structure has well-defined operations, behavior and properties.
Different Data structures
Data structures are very important in a computer system, as these not only allow the users to combine various data types in a group but also allow processing of the group as a single unit thereby making things much simpler and easier.
The data structures can be classified into two types:
1. Simple Data Structures : These data structures are normally built from primitive data types like integers, characters, boolean etc. For example:- Arrays, Linear lists.
2. Compound Data Structures : Simple data structures can be used in various ways to form more complex structures called compound data structures. Compound data structures are classified into following two types:-
- Linear Data Structures: These data structures are single level data structures. A dat structure is said to be linear if its elements form a sequence . For example:- Stack, Queue, Linked lists.
- Non-linear Data Structures: These are multilevel data structures. For example:- Tree.
Linear Lists
A linear data structure is that whose elements form a sequence. When elements of linear structures are homogeneous and are represented in memory by means of sequential memory locations, these linear structure are called arrays.
Linear list or Arrays are one of the simplest data structures and are very easy to traverse, search, sort etc. An array stores a list of finite number (n) of homogeneous data elements (i.e. the data elements of the same type). The number n is called length or size or range of a linear list.
When upper bound and lower bound of a linear list are given, its size is calculated as follows:
Linear list size(length) = UB - LB +1 ( UB- upper bound, LB- lower bound)
For instance, if a linear list or an array has elements numbered as -7,-6,-5....0,1,2,.....15, then its UB is 15 and LB is -7 and array length is
= 15 - (-7) + 1
= 15 + 7 + 1 =23
Linear List Data Structure
Searching in a Linear List
Linear Search
Binary Search
Insertion in a Linear List
Insertion of new element in array can be done in two ways:
(i) if the array is unordered, the new element is inserted at the end of the array,
(ii) if the array is sorted then new element is added at appropriate position without altering the order and to achieve this, rest of the elements are shifted.
Note: if array is already full, then insertion of an element into it results into OVERFLOW.
Deletion of an Element from a Sorted Linear List
The element to be deleted is first searched for in the array using one of the search techniques i.e., either linear search and binary search. If the search is successful, the element is removed and rest of the elements are shifted so as to keep the order of array undisturbed.
👉 Python provides a remove() method that itself takes care of shifting of elements.
-----------------------------------------------------------
Comments
Post a Comment