Sunday 4 February 2018

Data structures and Algorithms

What is Data Structure??In computer terminology, a data structure is a Specific way to store and organize data in a computer's memory so that these data can be used efficiently later.Data structure is about rendering data elements in terms of some relationship
, for better organization and storage.Almost every enterprise application uses various types of data structures in one or the other way.Actually in our programming data stored in main memory(RAM) and To develop efficient software or firmware we need to care about memory. To efficiently manage we required data structure.

This Tutorial is for both Data Structure in C and Java

In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily.





Let us understand the concept in a simpler way using one basic example

Let us assume you are going to the local library to find a book about a specific subject matter. Most likely, you will be able to use some kind of electronic reference or, in the worst case, a card catalog, to determine the title and author of the book you want. Since the books are typically shelved by category, and within each category sorted by author’s name, it is a fairly straightforward and painless process to then physically select your book from the shelves.

Now, suppose instead you came to the library in search of a particular book, but instead of organized shelves, were greeted with large garbage bags lining both sides of the room, each arbitrarily filled with books that may or may not have anything to do with one another. It would take hours, or even days, to find the book you needed, a comparative eternity. This is how software runs when data is not stored in an efficient format appropriate to the application.




Types of Data Structure:

  • Linear Data Structure
  • Non-linear Data Structure



Linear Data Structure:


In linear data structure data elements stored in a sequential manner i.e its elements combine to form any specific order.


There are basically two techniques of representing such linear structure within memory.

1.First way is to provide the linear relationships among all the elements represented by means of linear memory location. These linear structures are termed as arrays.

2. The second technique is to provide the linear relationship among all the elements represented by using the concept of pointers or links. These linear structures are termed as linked lists.

The common examples of linear data structure are:

  • Arrays
  • Queues
  • Stacks
  • Linked lists

Non - linear Data structure:

This structure is mostly used for representing data that contains a hierarchical relationship among various elements.


Examples of Non -Linear Data Structures are listed below: 



  • Graphs 
  • Trees



Algorithm 


An Algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task.  Algorithm is not the complete code or program, it is just the core logic(solution) of a problem, which can be expressed either as an informal high level description as pseudocode or using a flowchart.




Every Algorithm must satisfy the following properties:



Input- There should be 0 or more inputs supplied externally to the algorithm.

Output- There should be atleast 1 output obtained.

Definiteness- Every step of the algorithm should be clear and well defined.

Finiteness- The algorithm should have finite number of steps.

Correctness- Every step of the algorithm must generate a correct output.



An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. The performance of an algorithm is measured on the basis of following properties :

  1. Time Complexity
  2. Space Complexity

Space Complexity


Its the amount of memory space required by the algorithm, during the course of its execution. Space complexity must be taken seriously for multi-user systems and in situations where limited memory is available.


An algorithm generally requires space for following components :


Instruction Space : Its the space required to store the executable version of the program. This space is fixed, but varies depending upon the number of lines of code in the program.

Data Space : Its the space required to store all the constants and variables value.

Environment Space : Its the space required to store the environment information needed to resume the suspended function.


Time Complexity


Time Complexity is a way to represent the amount of time needed by the program to run till its completion. 

No comments:

Post a Comment