# Data Structures And Algorithms Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

This assignment talks about Data Structures and Algorithms. What is the data structure and what are the types of data structures, when the data structures are use and the use of various data structures in real world software applications.

Healthy Life is a hospital; they need to implement Application for OPD section. This application used linked queue to develop it. This hospital scenario is task 1. In task 2 we have to implement application for PVR movie hall. According to the scenario we developed an application to handle their process using stack. I repeated the task 1 by implementing the queue using arrays. Task 4 talking about store customer details using array. Rest tasks are comparison about speed, running time in algorithms.

## TASK 1

## 1.1 DEVELOPED SYSTEM USING QUEUE

Admission form

Figure 1 : Admission

Board

Figure 2 : Board

## 1.2 CLASSES / ABSTRACT DATA TYPES

Person Class

Figure 3 : Person Class

Patient Class

Figure 4 : Patient Class

## 1.3 JUSTIFY THE REASON FOR USING QUEUE DATA STRUCTURE FOR THIS APPLICATION

A queue holds a collection of data or elements and follows the First In First Out (FIFO) rule. The First In First Out that means which data added first in the list, only that element can be removed or retrieved first from the list. In other sense, You can remove or perform operation on that data which had been added first in the Collection (list). Whenever you need to remove the last added element then you must remove all these elements which are entered before the certain element.

A linked list is a data structure which consists of data record in a sequence such that each data record has a field of data as well as link reference to its connected node. It does not provide the random access to any of its member data as it is form of a indexing and the connected node is pre-defined. The main advantage of linked list is quick insertion and quick deletion.

Linked Queue is a combination of Queue and Link list. Main reasons for use Linked Queue are Fist in First out and Quick insertion & deletion. This system implemented for hospital OPD. When the patient comes to the hospital first customer service agent will take the necessary details form the patient. Then he will enter those details to admission form. Likewise the front dest officer will take the all patients details. After that system will call to first patient. Then second patent, likewise first patient in and first patient out. This is the standard way in the hospital.

If we use other data structures for this hospital system it will not give the proper output. As an example, we cannot use stack data structure for the hospital system because, stack provides last-in, first-out. If last patient can meet the doctor first, that hospital is not a good one. In that case patients don't like to go to that hospital. we can't use other data structure for this system, but some data structure can take. It there are many disadvantages of that data structures.

## TASK 2

## 2.1 DEVELOPED APPLICATION

Purchase Form

Figure 5 : Purchase Form

Get Glass form

Figure 6 : Get Glass Form

## 2.2 CLASSES

Audience Entity Class

Figure 7 : Audience Entity Class

Audience Class

Figure 8 : Audience Class

Stack Array Class

Figure 9 : Stack Array Class

## 2.3 JUSTIFY THE REASON FOR USING QUEUE DATA STRUCTURE FOR THIS APPLICATION

A stack is simple: a data structure that allows adding and removing elements in a particular order. Every time an element is added, it goes on the top of the stack; the only element that can be removed is the element that was at the top of the stack. Consequently, a stack is said to have "first in last out" behavior (or "last in, first out"). The first item added to a stack will be the last item removed from a stack. Stacks have some useful terminology associated with them:

Push: - To add an element to the stack

Pop: - To remove an element from the stock

For this application I used Stack array to develop the system. The main advantages of Stack is provides last-in, first-out. An Arrays also have advantage is Quick insertion. So we can insert quickly to the system. Reason for use Stack an array is PVR movie hall contains 20 seats. We can set arrays to fixed size. According to the PVR movie hall suitable data structure is Stack data structure.

We cannot use other data structures to this scenario. Because when we analysis this PVR movie hall scenario their requirements is clear so according to that the best suitable data structure is Stack with Arrays. Other than other some data structures.

## TASK 3

## 3.1 DEVELOPED SYSTEM USING QUEUE

Admission form

Figure 10 : Admission

Board

Figure 11 : Board

## 3.2 CLASSES

Person Class

Figure 12 : Person Class

Patient Class

Figure 13 : Patient Class

Sample Queue Class

Figure 14 : Sample Queue Class

## 3.3 JUSTIFY THE REASON FOR USING QUEUE-ARRAY DATA STRUCTURE FOR THIS APPLICATION

A queue holds a collection of data or elements and follows the First In First Out (FIFO) rule. The First In First Out that means which data added first in the list, only that element can be removed or retrieved first from the list. In other sense, You can remove or perform operation on that data which had been added first in the Collection (list). Whenever you need to remove the last added element then you must remove all these elements which are entered before the certain element.

An array is a particular method of storing elements of indexed data. Elements of data are stored sequentially in blocks within the array. Each element is referenced by an index, or subscript. The index is usually a number used to address an element in the array. The concept of an array can be daunting to the uninitiated, but it is really quite simple.

Main reason for use Queue-Array data structure is queue provides first in last out access and in array we can insert quickly and we can give fixed size for array. A doctor can appoint 25 patients per day, so in this system after giving 25 it will display a limitation message.

Other data structure also we can use for this system but most efficiently and suitable data structure is Queue-Array data structure.

## TASK 4

## 4.1 CREATING AUTOMATIC SECRET CODE

When the user clicks the new button automatically Customer secret code will generated. Following code will show you how it will happen.

if(source == btnNew)

## {

double Num1 = Math.random() * 100000;

Num1 = Math.round(Num1);

long Num2=(long)(Num1);

Long Longobj = new Long(Num2);

String Code = Longobj.toString();

txtCustomerSecretCode.setText(Code);

## }

## 4.2 SORTING METHOD

I used insertion sorting method to sort the array items according to the alphabetical order (in the ascending order) of the customer name. Following codes are insertion sort method.

public void insertionSort()

## {

int in,out;

for(out=1; out<nElems; out++)

## {

Customer temp = a[out];

in = out;

while(in>0 && a[in-1].getLast().compareTo(temp.getLast())>0)

## {

a[in] = a[in-1];

--in;

## }

a[in] = temp;

## }

## }

## 4.3 JUSTIFY SELECTED SORTING METHOD

Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and mostly-sorted lists, and often is used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. In arrays, the new list and the remaining elements can share the array's space, but insertion is expensive, requiring shifting all following elements over by one.

The insertion sort works just like its name suggests - it inserts each item into its proper place in the final list. The simplest implementation of this requires two list structures - the source list and the list into which sorted items are inserted. To save memory, most implementations use an in-place sort that works by moving the current item past the already sorted items and repeatedly swapping it with the preceding item until it is in place.

Reason for use insertion sorting method,

Simple implementation

Efficient for (quite) small data sets

Efficient for data sets that are already substantially sorted: the time complexity

Does not change the relative order of elements with equal keys

Only requires a constant amount O(1) of additional memory space

Can sort a list as it receives it

## 4.4 LINEAR SEARCH AND BINARY SEARCH

## Linear Search

Search each record of the file one at a time until finding the given name and hence the corresponding record. This method of searching for data in an array is straightforward and easy to understand. To find a given item, begin your search at the start of the data collection and continue to look until you have either found the target or exhausted the search space. Clearly to employ this method you must first know where the data collection begins and the size of the area to search. Alternatively, a unique value could be used to signify the end of the search space. This method of searching is most often used on an array data structure whose upper and lower bounds are known.

This type of search is complexity as, in the average case; one-half of the items in the search space will be examined before a match is found. (Linear Search, 2010)

## Binary Search

Compare the given Customer Secret Code with the Customer Secret Code in the middle of the list, list has which half of the list contains Customer Secret Code. Then compare Customer Secret Code with the Customer Secret Code of the middle of the correct half to determine which quarter of the list contains the Customer Secret Code, continue the process until finding Customer Secret Code in the list.

## TASK 5

## THE USE OF VARIOUS DATA STRUCTURES IN REAL WORLD SOFTWARE APPLICATION

A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways. In computer programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms.

The organized collection of data is known as data structures. Data is a part of information or an entity piece of fact. It can be a raw fact or unprocessed values. The processed data becomes information and when the data is organized it is called data structure. The possible ways in which the data value such as integers, float and character are logically related among them are defined by data structures.

Data structure = organized data + operations

There are Different Types of Data Structures:

The data structures can be classified into two different types namely

Primitive data structures

Non - primitive data structures

## Primitive data structures

The data structures which can be directly operated are called primitive data structures. The integer, float, character etc. are some of the primitive data structures. Operations like creation, deletion, selection and updation can be carried out on primitive data structures.

## Non - primitive data structures

The data structures which are not primitive are called non-primitive data structures which means these are data structures that cannot be manipulated directly. Non-primitive data structures can be again classified into two different types namely

Linear data structure

Non-linear data structure

A linear data structure is the one which establishes the relationship of adjacency between the elements which means all the elements are stored linearly or sequentially. Some examples of linear data structures are arrays, linked list, stacks and queues.

Any data structure which establishes the relationship their than the adjacency relationship are called as non-linear data structure. Some examples of non-linear data structures are trees and graphs.

There are many areas in data structures applied extensively. Such as, Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation. To implement minimum number of two priority queue needs. One queue is used for actual storing of data and another for storing priorities.

To perform recursion stack data structure ware used. Because of its LIFO (Last In First Out) property it remembers its 'caller' so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.

As a Real life examples for queues,

A queue of people at ticket-window: The person who comes first gets the ticket first. The person who is coming last is getting the tickets in last. Therefore, it follows first-in-first-out (FIFO) strategy of queue.

Vehicles on toll-tax Bridge: The vehicle that comes first to the toll tax booth leaves the booth first. The vehicle that comes last leaves last. Therefore, it follows first-in-first-out (FIFO) strategy of queue.

Phone answering system: The person who calls first gets a response first from the phone answering system. The person who calls last gets the response last. Therefore, it follows first-in-first-out (FIFO) strategy of queue.

Patients waiting outside the doctor's clinic: The patient who comes first visits the doctor first, and the patient who comes last visits the doctor last. Therefore, it follows the first-in-first-out (FIFO) strategy of queue.

So we can't use Stack data structure for above examples. Stack rule is last-in, first-out. We use stack for a queue of people at ticket-window it not fair for other peoples. We can check which data stricture can used for the implementation in System Develop Life Cycle (SDLC) requirement gathering stage.

## CONCLUSION

Firstly in task 1, I was created a program to healthy life hospitals OPD section. It was created by using queue. Then I moved to task 2. It was a little bit difficult for me. However I was created an application for PVR movie hall. For this application I used Stack array. In task 3, we have to repeat the task 1 by using Queue array. it also successfully implemented.

In Task 4 we have to a program to store customer's details using an array. Customer Secret Code automatically generated by system itself then I sorted the array using Insertion Sorting method. Linear and Binary searching methods and to print the number was very difficult tasks for me, it took lot of time. Then I moved to task 5, there I need to write an essay about the use of various data structures in real world software Application. Finally I was compare the speed and running time of the data structures and sorting algorithms.

## Drawbacks:-

In task 4, sub task 4-a, 4-b and 5 was very difficult for me. Some part are not current it that. I was huge drawback from me. Also in task 6, I didn't realize the exact question. It was very difficult to me to understand.

## Future Recommendation:-

I hope to update Linear and Binary search part and Printing facility on the application in Task 4.

## GANTT CHART

Figure 15 : Gantt Chart