Skip to main content

Posts

Link List

Recent posts

Operation on Array

Basic Operations : Following are the basic operations supported by an array. Traverse − print all the array elements one by one. Insertion − Adds an element at the given index. Deletion − Deletes an element at the given index. Search − Searches an element using the given index or by the value. Update − Updates an element at the given index. Traversing 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. Traverse − print all the array elements one by one.or process the each element one by one . Let A be a collection of data elements stored in the memory of the computer. Suppose we want to print the content of each element of A or suppose we want to count the number of elements of A with given property. This can be accomplished by traversing A, that is, by accessing and processing (frequently called visiting) each element of An exactly once...

Memory Representation of Array

Already discussed that whenever an array is declared in the program, contiguous memory to it elements are allocated. Initial address of the array – address of the first element of the array is called base address of the array. Each element will occupy the memory space required to accommodate the values for its type, i.e.; depending on elements datatype, 1, 4 or 8 bytes of memory is allocated for each elements. Next successive memory address is allocated to the next element in the array. This process of allocating memory goes on till the number of element in the array gets over. One Dimensional Array : Below diagram shows how memory is allocated to an integer array of N elements. Its base address – address of its first element is 10000. Since it is an integer array, each of its element will occupy 4 bytes of space. Hence first element occupies memory from 10000 to 10003. Second element of the array occupies immediate next memory address in the memory, i.e.; 10004 which requi...

Array

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array). The array is a fixed-size sequenced collection of variables belonging to the same data types. The array has adjacent memory locations to store values. Since the array provides a convenient structure for representing data, it falls under the category of the data structures in C. The syntax for declaring array are: data_type array_name [array_size]; The following are two terminology are used in Array data structure: Element : Every item stored in an array is termed as an element Index : each memory location of an element in an array is denoted by a numerical index which is used for identifying the element. Why you need ? When a ...

Asymptotic Notation

* Asymptotic analysis of an algorithm refers to defining the mathematical boundation /framing of its run-time performance. Using asymptotic analysis, we can very well conclude the best case, average case, and worst case scenario of an algorithm. * Asymptotic Notations are the expressions that are used to represent the complexity of an algorithm. Usually, the time required by an algorithm falls under three types − Best Case − Minimum time required for program execution. Average Case − Average time required for program execution. Worst Case − Maximum time required for program execution. Following are the commonly used asymptotic notations to calculate the running time complexity of an algorithm. Ο Notation Ω Notation θ Notation Big Oh Notation, Ο The notation Ο(n) is the formal way to express the upper bound of an algorithm's running time. It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to compl...

Algorithm & its Characteristics

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as probabilistic algorithms, incorporate randomness. * A step-by-step method of solving a problem or making decisions, as in making a diagnosis. * An established mechanical procedure for solving certain mathematical problems. Properties of the algorithm Finiteness . An algorithm must always terminate after a finite number of steps. Definiteness . Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specifie...

Need or Not ?

Data structures are used in computing to make it easy to locate and retrieve information.  Primitive data structures are simple ways for programming languages to represent basic values. These include data types like integer, char (character), Boolean, pointers, and the like. Non-primitive data structures provide ways of storing multiple values in a single variable.  These include arrays, lists, stacks, trees, and so forth. Data structures can also be used to group and organize other data structures.  In databases, a record can be thought of as a data structure that contains all the data structures related to a given key; in object oriented programming languages like Java, a class is a data structure that organizes attributes and functions in such a way that they can be easily replicated. In each case, the way the data is "structured" makes it easy to retrieve or manipulate.