You are on page 1of 22

TASK 01

What is data structure?


Data structures have been around since the structured programming era. A definition from
that era: a data structure is a set of types, a designated type from that type set. That definition
implies that a data structure is a type with implementation.
The data structure is a class definition is too broad because it embraces Employee,
Vehicle, Account, and many other real-world entity-specific classes as data structures.
Although those classes structure various data items, they do so to describe real-world entities
in the form of ob!ects" instead of describing container ob!ects for other entity and possibly
container" ob!ects. This containment idea leads to a more appropriate data structure
definition: a data structure is a container class that provides storage for data items, and
capabilities for storing and retrieving data items. E#amples of container data structures:
arrays, lin$ed lists, stac$s, and %ueues.
What is an algorithm?
Algorithms often relate with data structures. An algorithm is a se%uence of instructions that
accomplishes a tas$ in a finite time period. The algorithm receives &ero or more inputs,
produces at least one output, consists of clear and unambiguous instructions, terminates after
a finite number of steps, and is basic enough that a person can carry out the algorithm using a
pencil and paper. 'n contrast, a program is not necessarily finite: the program, such as a (eb
server, may never terminate without e#ternal intervention. E#amples of algorithms associated
with data structures: linear-search, bubble-sort, binary-search, matri#-multiplication, lin$ed-
list-concatenation, stac$-push-and-pop, and %ueue-insert-and-delete.
Queue
The stac$ and the %ueue. Each is defined by two basic operations: insert a new item,
and remove an item. (hen we insert an item, our intent is clear. )ut when we remove an
item, which one do we choose* The rule used for a %ueue is to always remove the item that
has been in the collection the most amount of time. This policy is $nown as first-in-first-
out or FIFO. The rule used for a stac$ is to always remove the item that has been in the
collection the least amount of time. This policy is $nown as last-in first-out or +',-.
1
Justify the reason for using queue for this application.
'n general, a %ueue is a line of people or things waiting to be handled, usually in se%uential
order starting at the beginning or top of the line or se%uence. 'n computer technology, a %ueue
is a se%uence of wor$ ob!ects that are waiting to be processed. The possible factors,
arrangements, and processes related to %ueues are $nown as %ueuing theory.
' have select %ueue for this application because it has lot advantages li$e it is scalable, by
adding new instances of the server application, or even adding a new &.-/ image with a
%ueue manager in the %ueue-sharing group" and a copy of the application. 't is highly
available and it naturally performs pull wor$load balancing, based on the available
processing capacity of each %ueue manager in the %ueue-sharing group.
2
TASK 0
A!stract data type
'n computing, an abstract data type or abstract data structure is a mathematical model for a
certain class of data structures that have similar behaviour0 or for certain data types of one or
more programming languages that have similar semantics. An abstract data type is defined
indirectly, only by the operations that may be performed on it and by mathematical
constraints on the effects and possibly cost" of those operations.
,or e#ample, an abstract stac$ data structure could be defined by two operations: push, that
inserts some data item into the structure, and pop, that e#tracts an item from it0 with the
constraint that each pop always returns the most recently pushed item that has not been
popped yet. (hen analy&ing the efficiency of algorithms that use stac$s, one may also
specify that both operations ta$e the same time no matter how many items have been pushed
into the stac$, and that the stac$ uses a constant amount of storage for each element.
Abstract data types are purely theoretical entities, used among other things" to simplify the
description of abstract algorithms, to classify and evaluate data structures, and to formally
describe the type systems of programming languages. 1owever, an ADT may be
implemented by specific data types or data structures, in many ways and in many
programming languages0 or described in a formal specification language.
ADTs are often implemented as modules: the module2s interface declares procedures that
correspond to the ADT operations, sometimes with comments that describe the constraints.
This information hiding strategy allows the implementation of the module to be changed
without disturbing the client programs. Abstract data types are also an important conceptual
tool in ob!ect-oriented programming and design by contract methodologies for software
development.
The name 3abstract data type3 apparently was coined by researchers in software engineering
and programming language design0 while 3abstract data structure3 was coined by researchers
in data structures and algorithms.
3
"omparing Array and #in$ed list
Array
4ossibly the most common data structure used to store data. -ne memory bloc$ is allocated
for the entire array which holds all the initiali&ed and rest of the uninitiali&ed" elements of
the array. 'nde#ing is 5-based and the elements can be accessed in a constant time by using
the inde# of the particular element a as the subscript.
The address of an element is computed as an offset from the base address of the array and one
multiplication is needed to compute what is supposed to be added to the base address to get
the memory address of the element. /ince memory re%uirements for every data type is
different, so first the si&e of an element of that data type is computed and then it2s multiplied
with the inde# of the element to get the value to be added to the base address. /o, the process
re%uires !ust one multiplication and one addition and this is re%uired for every element
irrespective of its position in the array.
Ad%antages of using arrays&
Easier to use and access
,aster access to the elements
'isad%antages of using arrays&
,i#ed si&e - the si&e of the array is static
-ne bloc$ allocation - if we don2t have enough memory to provide a single bloc$ to
allocate the space for the array then we6ll need to defragment and other similar stuff to
first create a free bloc$ of that si&e.
7omple# position-based insertion - if we want to insert an element at a position
already covered by some other element then we got to shift right by one position all
the elements to the right of that position. This will vacate the position for us to insert
the new element at the desired position.
4
#in$ed #ist
Elements are not stored in contiguous memory locations, not at least guaranteed to be stored
li$e that. Every node contains an element and a lin$ to the ne#t element. The allocation is not
static instead it2s dynamic. (henever a need arises, we got to first allocate memory for the
node and then use it to store the new element and lin$ either as 2null2 in case it2s the last
element" or the lin$ will store the address of the element, which is supposed to be ne#t to the
element being added. /ince the memory is allocated dynamically, so it2ll continue to e#ist
unless we will need to e#plicitly $ill it in the languages not having automatic memory
management.
Ad%antages of using #in$ed #ists&
,le#ibility - insert at or delete from" any position in constant time
8o single allocation of memory needed - fragmented memory can be put to a better
use
Dynamic allocation - the si&e is not re%uired to be $nown in advance
'isad%antages of using #in$ed #ists&
7omple# to use and access - relatively comple# as compared to arrays
8o constant time access to the elements - simply because it doesn2t involve the simple
arithmetic used by arrays to compute the memory address, so relatively inefficient as
compared to arrays
Stac$
A stac$ is a limited version of an array. 8ew elements, or nodes as they are often called, can
be added to a stac$ and removed from a stac$ only from one end. ,or this reason, a stac$ is
referred to as a +',- structure +ast-'n ,irst--ut". /tac$s have many applications. ,or
e#ample, as processor e#ecutes a program, when a function call is made, the called function
must $now how to return bac$ to the program, so the current address of program e#ecution is
pushed onto a stac$.
5
-nce the function is finished, the address that was saved is removed from the stac$, and
e#ecution of the program resumes. 'f a series of function calls occur, the successive return
values are pushed onto the stac$ in +',- order so that each function can return bac$ to
calling program. /tac$s support recursive function calls in the same manner as conventional
nonrecursive calls. /tac$s are also used by compilers in the process of evaluating e#pressions
and generating machine language code. They are also used to store return addresses in a chain
of method calls during e#ecution of a program.
Justify the reason for using Stac$(#in$ed list for this application.
+in$ed-lists and stac$s.%ueues are not really analogous data structures0 often if we loo$ at the
source code %ueues and stac$s are simply special types of lin$ed-lists. This is mainly because
adding and removing items from a lin$ed-list is generally much faster than using an array. /o,
' have selected stac$.lin$ed list for this application.
6
Tas$ 0)
*inary Search
A fast way to search a sorted array is to use a binary search. The idea is to loo$ at the
element in the middle. 'f the $ey is e%ual to that, the search is finished. 'f the $ey is less than
the middle element, do a binary search on the first half. 'f it2s greater, do a binary search of
the second half.
+erformance
The advantage of a binary search over a linear search is astounding for large numbers. ,or an
array of a million elements, binary search, -log 8", will find the target element with a worst
case of only 95 comparisons. +inear search, -8", on average will ta$e :55,555 comparisons
to find the element. 4robably the only faster $ind of search uses hashing, a topic that isn2t
covered in these notes. This performance comes at a price - the array must be sorted first.
)ecause sorting isn2t a fast operation, -8 log 8", it may not be worth the effort to sort when
there are only a few searches.
,%erflo-
This wor$s well, or at least has wor$ed well, until recently. The problem appeared when
memories, and arrays, got very large. ,or the first time the sum of two array inde#es, an
intermediate value in the computation, can overflow the si&e of an int. 7omputing the
midpoint by adding the two and then dividing doesn2t wor$.
.eordering the e/pession a%oids o%erflo-
The solution is to rewrite the e#pression so that no intermediate value overflows the si&e of
an int. This is easy to do using the following.
int mid ; first < last - first" . 90
,or most programs the difference between the two computations will never be seen because it
will only appeaer with very large arrays.
0ariation on !inary search
The following method shows another version of a binary search method: =" it compares
elements of a string array so comparisons use the compareTo" method", and 9" it sorts the
entire array so fewer parameters are supplied, and therefore local variables are declared to
ta$e their place
7
TASK 01
2/amples of stac$ and queue in real life situation...
A queue of people at tic$et3-indo-&
The person who comes first gets the tic$et first. The person who is coming last is getting the
tic$ets in last. Therefore, it follows first-in-first-out ,',-" strategy of %ueue.
0ehicles on toll3ta/ *ridge&
The vehicle that comes first to the toll ta# booth leaves the booth first. The vehicle that comes
last leaves last. Therefore, it follows first-in-first-out ,',-" strategy of %ueue.
+hone ans-ering 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 ,',-" strategy of
%ueue.
#uggage chec$ing machine&
+uggage chec$ing machine chec$s the luggage first that comes first. Therefore, it follows
,',- principle of %ueue.
+atients -aiting outside the doctor4s 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 ,',-" strategy of %ueue.
Use of Queues in Real World Software Development:
>ueue of !obs or 4rocesses ready to run(aiting for 74?":
Actually when we tal$ing about 74? running process, we are commonly considering
about the 74? program /cheduling and it is a $ey concept of computer is multitas$ing,
multi-processing operating system and real-time operating system design. The real time
operating systems are having these %ueue processes, which is specially in multi tas$
processing. 74? scheduling refers to the way processes are assigned to run the available
74?s, since there are typically many more processes running than there are available
74?s. (hen we doing the scheduler we have to consider such assignments, such as,
8
74? utili&ation @ Aeep the 74? as busy as possible.
Throughput @ 8umber of processes that complete their e#ecution per time unit.
Turnaround time TAT" @ Amount of time to e#ecute a particular process
(aiting time @ Amount of time a process has been waiting in the ready %ueue.
Besponse time @ Amount of time it ta$es from when a re%uest was submitted until
the first response is produced, not output. for time-sharing environment"
/o in real time operating system has functioning some of the sections by using %ueue data
structure and algorithm.
>ueues of processes waiting for '.-:
As we $now the input devices and output devices in computers are connected with the
system and its handling by the -perating system. 7omputer users always using inputs and
outputs parallel, so when they use they use those inputs and outputs parallel, operating
system send all the process re%uest in a pool and through the %ueue operating system
react with the re%uest order which mean that process are ordering in the pool according to
the re%uest pool and react to user 'nputs.-utputs.
,iles sent to 4rint
A system for printing %ueued print !obs includes a user interface and a !ob submission
component. The user interface communicates user input. The !ob submission component
submits print !obs to at least one print %ueue. The !ob submission component
communicates with the user interface to receive the user input therefore. The !ob
submission component includes at least one parameter associated with printing an
identification sheet with all of the at least one print !ob in the at least one print %ueue
when a predetermined condition occurs, the predetermined condition includes at least one
of a temporal condition, a periodic temporal condition, a threshold number of pages, and
a threshold number of print !obs in the at least one print %ueue.
-n the other hand if we want to more clearly about the ,iles sent to print using %ueues,
!ust we can e#plain through this way. There is one print shared with the multi computers
or multi applications. /o at that time period this >ueue is supporting to manage the
9
printer process. (hen and application is sending a re%uest to printer something, it is
added to a %ueue called the printing pool. As well as if other application also re%uest same
process such as printer at the same time, all these re%uest are added to the pool as they
arrive order. Then printer manager will send the print the document as they re%uest order,
it means, printer will print the document with ,irst Be%uest ,irst 4rint.
10
TASK 05
Big O Notation
Automobiles are divided by si&e into several categories: subcompacts, compacts, midsi&e,
and so on. These categories provide a %uic$ idea what si&e car you2re tal$ing about, without
needing to mention actual dimensions. /imilarly, it2s useful to have a shorthand way to say
how efficient a computer algorithm is. 'n computer science, this rough measure is called )ig
- notation. Cou might thin$ that in comparing algorithms you would say things li$e
3Algorithm A is twice as fast as algorithm ),3 but in fact this sort of statement isn2t too
meaningful.
)ecause the proportion can change radically as the number of items changes0 4erhaps you
increase the number of items by :5D, and now A is three times as fast as ). -r you have half
as many items, A and ) are now e%ual. (hat you need is a comparison that2s related to the
number of items.
Why bigoh notation isn!t always useful:
Complexity analysis can be very useful, but there are problems with it too.
Too hard to analy&e. Eany algorithms are simply too hard to analy&e mathematically.
Average case un$nown. There may not be sufficient information to $now what the
most important 3average3 case really is, therefore analysis is impossible.
?n$nown constant. )oth wal$ing and traveling at the speed of light have a time-as-
function-of-distance big-oh comple#ity of - 8". Although they have the same big-oh
characteristics, one is rather faster
than the other. )ig-oh analysis only
tells you how it grows with the si&e of
the problem, not how efficient it is.
/mall data sets. 'f there are no large
amounts of data, algorithm efficiency
may not be important.
11
1ow time and space grow as the amount of data increases
't2s useful to estimate the cpu or memory resources an algorithm re%uires. This 3comple#ity
analysis3 attempts to characteri&e the relationship between the number of data elements and
resource usage time or space" with a simple formula appro#imation. Eany programmers
have had ugly surprises when they moved from small test data to large data sets. This analysis
will ma$e you aware of potential problems.
Dominant Term
)ig--h the 3-3 stands for 3order of3" notation is concerned with what happens for very large
values of 8, therefore only the largest term in a polynomial is needed. All smaller terms are
dropped.
,or e#ample, the number of operations in some sorts is 8
9
- 8. ,or large values of 8, the
single 8 term is insignificant compared to 8
9
, therefore one of these sorts would be described
as an -8
9
" algorithm.
/imilarly, constant multipliers are ignored. /o a -FG8" algorithm is e%uivalent to -8",
which is how it should be written. ?ltimately you want to pay attention to these multipliers in
determining the performance, but for the first round of analysis using )ig--h, you simply
ignore constant factors.
(hy /i&e Eatters
1ere is a table of typical cases, showing how many 3operations3 would be performed for
various values of 8. +ogarithms to base 9 as used here" are proportional to logarithms in
other base, so this doesn2t affect the big-oh formula.
constant logarithmic linear quadratic cubic
n -=" -log 8" -8" -8 log 8" -8
9
" -8
H
"
= = = = = = =
9 = = 9 9 F I
F = 9 F I =J JF
12
I = H I 9F JF :=9
=J = F =J JF 9:J F,5KJ
=,59F = =5 =,59F =5,9F5 =,5FI,:LJ =,5LH,LF=,I9F
=,5FI,:LJ = 95 =,5FI,:LJ 95,KL=,:95 =5
=9
=5
=J
Does anyone really have that much data*
't2s %uite common. ,or e#ample, it2s hard to find a digital camera that that has fewer than a
million pi#els = mega-pi#el". These images are processed and displayed on the screen. The
algorithms that do this had better not be -8
9
"M 'f it too$ one microsecond = millionth of a
second" to process each pi#el, an -8
9
" algorithm would ta$e more than a wee$ to finish
processing a = megapi#el image, and more than three months to process a H megapi#el image
note the rate of increase is definitely not linear".
Another e#ample is sound. 7D audio samples are =J bits, sampled FF,=55 times per second
for each of two channels. A typical H minute song consists of about I million data points. Cou
had better choose the write algorithm to process this data.
A dictionary '2ve used for te#t analysis has about =9:,555 entries. There2s a big difference
between a linear -8", binary -log 8", or hash -=" search.
)est, worst, and average cases
Cou should be clear about which cases big-oh notation describes. )y default it usually refers
to the average case, using random data. 1owever, the characteristics for best, worst, and
average cases can be very different, and the use of non-random data often more realistic"
data can have a big effect on some algorithms.
(hy big-oh notation isn2t always useful
7omple#ity analysis can be very useful, but there are problems with it too.
Too hard to analy&e. Eany algorithms are simply too hard to analy&e mathematically.
Average case un$nown. There may not be sufficient information to $now what the
most important 3average3 case really is, therefore analysis is impossible.
13
?n$nown constant. )oth wal$ing and traveling at the speed of light have a time-as-
function-of-distance big-oh comple#ity of -8". Altho they have the same big-oh
characteristics, one is rather faster than the other. )ig-oh analysis only tells you how it
grows with the si&e of the problem, not how efficient it is.
/mall data sets. 'f there are no large amounts of data, algorithm efficiency may not be
important.
)enchmar$s are better
)ig-oh notation can give very good ideas about performance for large amounts of data, but
the only real way to $now for sure is to actually try it with large data sets. There may be
performance issues that are not ta$en into account by big-oh notation, eg, the effect on paging
as virtual memory usage grows. Although benchmar$s are better, they aren2t feasible during
the design process, so )ig--h comple#ity analysis is the choice.
Typical big-oh values for common algorithms
/earching
1ere is a table of typical cases.
Type of /earch )ig--h 7omments
+inear search array.Array+ist.+in$ed+ist -8"
)inary search sorted array.Array+ist -log 8" Be%uires sorted data.
/earch balanced tree -log 8"
/earch hash table -="
-ther Typical -perations
Algorithm
array
Array+ist
+in$ed+ist
14
access front -=" -="
access bac$ -=" -="
access middle -=" -8"
insert at front -8" -="
insert at bac$ -=" -="
insert in middle -8" -="
/orting arrays.Array+ists
/ome sorting algorithms show variability in their )ig--h performance. 't is therefore
interesting to loo$ at their best, worst, and average performance. ,or this description
3average3 is applied to uniformly distributed values. The distribution of real values for any
given application may be important in selecting a particular algorithm.
Type of /ort est !orst "verage Comments
)ubble/ort -8" -8
9
" -8
9
" 8ot a good sort, e#cept with ideal data.
/election
sort
-8
9
" -8
9
" -8
9
" 4erhaps best of -8
9
" sorts
>uic$/ort -8 log 8" -8
9
" -8 log
8"
Nood, but it worst case is -8
9
"
1eap/ort -8 log 8" -8 log 8" -8 log
8"
Typically slower than >uic$/ort, but
worst case is much better.
E#ample - choosing a non-optimal algorithm
' had to sort a large array of numbers. The values were almost always already in order, and
even when they weren2t in order there was typically only one number that was out of order.
-nly rarely were the values completely disorgani&ed. ' used a bubble sort because it was -="
for my 3average3 data. This was many years ago when 74?s were =555 times slower. Today
' would simply use the library sort for the amount of data ' had because the difference in
15
e#ecution time would probably be unnoticed. 1owever, there are always data sets which are
so large that a choice of algorithms really matters.
E#ample - -8
H
" surprise
' once wrote a te#t-processing program to solve some particular customer problem. After
seeing how well it processed the test data, the customer produced real data, which '
confidently ran the program on. The program fro&e -- the problem was that ' had
inadvertently used an -8
H
" algorithm and there was no way it was going to finish in my
lifetime. ,ortunately, my reputation was restored when ' was able to rewrite the offending
algorithm within an hour and process the real data in under a minute. /till, it was a sobering
e#perience, illustrating dangers in ignoring comple#ity analysis, using unrealistic test data,
and giving customer demos.
/ame )ig--h, but big differences
Although two algorithms have the same big-oh characteristics, they may differ by a factor of
three or more" in practical implementations. Bemember that big-oh notation ignores constant
overhead and constant factors. These can be substantial and can2t be ignored in practical
implementations.
Time-space tradeoffs
/ometimes it2s possible to reduce e#ecution time by using more space, or reduce space
re%uirements by using a more time-intensive algorithm.
16
Summaries of popular sorting algorithms
*u!!le sort
)ubble sort is a straightforward and simplistic method of sorting data that is used in computer
science education. The algorithm starts at the beginning of the data set. 't compares the first
two elements, and if the first is greater than the second, it swaps them. 't continues doing this
for each pair of ad!acent elements to the end of the data set. 't then starts again with the first
two elements, repeating until no swaps have occurred on the last pass. This algorithm is
highly inefficient and is rarely used e#cept as a simplistic e#ample. ,or e#ample, if we have
=55 elements then the total number of comparisons will be =5555. A slightly better variant,
coc$tail sort, wor$s by inverting the ordering criteria and the pass direction on alternating
passes. The modified )ubble sort will stop = shorter each time through the loop, so the total
number of comparisons for =55 elements will be FK:5.
6nsertion sort
'nsertion 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. 't wor$s by
ta$ing elements from the list one by one and inserting them in their correct position into a
new sorted list. 'n arrays, the new list and the remaining elements can share the array2s space,
but insertion is e#pensive, re%uiring shifting all following elements over by one. /hell sort
see below" is a variant of insertion sort that is more efficient for larger lists.
Shell sort
/hell sort was invented by Donald /hell in =K:K. 't improves upon bubble sort and insertion
sort by moving out of order elements more than one position at a time. -ne implementation
can be described as arranging the data se%uence in a two-dimensional array and then sorting
the columns of the array using insertion sort. Although this method is inefficient for large
data sets, it is one of the fastest algorithms for sorting small numbers of elements.
7erge sort
Eerge sort ta$es advantage of the ease of merging already sorted lists into a new sorted list. 't
starts by comparing every two elements i.e., = with 9, then H with F..." and swapping them if
the first should come after the second. 't then merges each of the resulting lists of two into
lists of four, then merges those lists of four, and so on0 until at last two lists are merged into
17
the final sorted list. -f the algorithms described here, this is the first that scales well to very
large lists, because its worst-case running time is - n log n". Eerge sort has seen a relatively
recent surge in popularity for practical implementations, being used for the standard sort
routine in the programming languages 4erl, 4ython as timsort", and Oava currently uses an
optimi&ed merge sort0 will probably switch to timsort in ODAL", among others.
8eapsort
eapsort is a much more efficient version of selection sort. 't also wor$s by determining the
largest or smallest" element of the list, placing that at the end or beginning" of the list, then
continuing with the rest of the list, but accomplishes this tas$ efficiently by using a data
structure called a heap, a special type of binary tree. -nce the data list has been made into a
heap, the root node is guaranteed to be the largest or smallest" element. (hen it is removed
and placed at the end of the list, the heap is rearranged so the largest element remaining
moves to the root. ?sing the heap, finding the ne#t largest element ta$es -log n" time,
instead of -n" for a linear scan as in simple selection sort. This allows 1eapsort to run in
-n log n" time.
Quic$ sort
>uic$ sort is a divide and con%uer algorithm which relies on a partition operation: to partition
an array, we choose an element, called a pivot, move all smaller elements before the pivot,
and move all greater elements after it. This can be done efficiently in linear time and in-place.
(e then recursively sort the lesser and greater subsists. Efficient implementations of
%uic$sort with in-place partitioning" are typically unstable sorts and somewhat comple#, but
are among the fastest sorting algorithms in practice. Together with its modest -log n" space
usage, this ma$es %uic$sort one of the most popular sorting algorithms, available in many
standard libraries. The most comple# issue in %uic$sort is choosing a good pivot element0
consistently poor choices of pivots can result in drastically slower -nP" performance, but if
at each step we choose the median as the pivot then it wor$s in -n log n".
*uc$et sort
)uc$et sort is a sorting algorithm that wor$s by partitioning an array into a finite number of
buc$ets. Each buc$et is then sorted individually, either using a different sorting algorithm, or
by recursively applying the buc$et sorting algorithm. Thus this is most effective on data
18
whose values are limited e.g. a sort of a million integers ranging from = to =555". A variation
of this method called the single buffered count sort is faster than %uic$sort and ta$es about
the same time to run on any set of data.
.adi/ sort
Badi# sort is an algorithm that sorts a list of fi#ed-si&e numbers of length $ in -n Q $" time
by treating them as bit strings. (e first sort the list by the least significant bit while
preserving their relative order using a stable sort. Then we sort them by the ne#t bit, and so
on from right to left, and the list will end up sorted. Eost often, the counting sort algorithm is
used to accomplish the bitwise sorting, since the number of values a bit can have is minimal -
only 2=2 or 252.
'istri!ution sort
Distribution sort refers to any sorting algorithm where data is distributed from its input to
multiple intermediate structures which are then gathered and placed on the output. 't is
typically not considered to be very efficient because the intermediate structures need to be
created, but sorting in smaller groups is more efficient than sorting one larger group.
Shuffle sort
/huffle sort is a type of distribution sort algorithm see above" that begins by removing the
first =.I of the n items to be sorted, sorts them recursively, and puts them in an array. This
creates n.I 3buc$ets3 to which the remaining L.I of the items are distributed. Each 3buc$et3 is
then sorted, and the 3buc$ets3 are concatenated into a sorted array.
19
7onclusion

'n this paper ' have discussed about data structures and their algorithms. The intrinsic,
invariant behaviors are encapsulated into an intelligent structure class. A hoo$ is added, and a
communication protocol with e#trinsic algorithm classes is established. The e#trinsic, variant
behaviors on the data structure are encapsulated into ob!ect. The merits of this techni%ue
include enhanced reusability and unlimited e#tensibility. 'n addition, one finds that the coding
is pleasantly simple. This does not happen by accident, for all the hard wor$ has been shifted
up front to formulate the appropriate abstraction for the problem at hand. -b!ect-oriented
design patterns provide ways to implement data structures in such a way that the gap between
the abstraction and the computing model is minimal. Effective use of polymorphism
eliminates most control structures and reduces code comple#ity. Data structures and
algorithms built as such are elegant in their simplicity, universal in their applicability, and
fle#ible in their e#tensibility
20
21
.eference&
Robert Sedgewick and Kevin Wayne. 2000. Stacks and Queues. !"#$"%&
'vai(ab(e at) *tt+),,introc-.c-.+rinceton.ed.,43-tack,. 'cce--ed 11 /ay
11&.
Wiki an-wer-. 2010. What are the Advantages of linked list over stack and
queue? !"#$"%& 'vai(ab(e at)
*tt+),,wiki.an-wer-.co0,1,W*at2are2t*e2'dvantage-2o32(inked2(i-t2over2-
tack2and24.e.e'cce--ed 13 /ay 11&.
*a0i(ton.be((.ac..k. 2005. THE STACK DATA STRCTRE! !"#$"%&
'vai(ab(e at) *tt+),,*a0i(ton.be((.ac..k,-wdev2,note-,note-212.+d3.
'cce--ed 14 /ay 11&.
7hen > and +iu (. Test and evaluate the performance of sorting methods R-nlineS Available
at: http:..www.cse.unr.edu.TchenU%.sorta.html RAccessed 59.5:.==S
OAVA 8otes 955:. Algorithms: )ig -h 8otation R-nlineS Available at
http:..www.leepoint.net.notes-!ava.algorithms.big-oh.bigoh.html RAccessed 59.5:.==S
(i$ipedia 955K. /tac$ data structure" R-nlineS Available at
http:..en.wi$ipedia.org.wi$i./tac$UdataUstructure" RAccessed 59.5:.==S
Data /tructures and Algorithms =KKI. >ueues R-nlineS Available at
http:..www.cs.auc$land.ac.n&.software.AlgAnim.%ueues.html RAccessed 59.5:.==S
4rogramming 955:. 'ntroduction to Data /tructures and Algorithms R-nlineS Available at
http:..www.idevelopment.info.data.4rogramming.dataUstructures.overview.DataU/tructuresU
AlgorithmsU'ntroduction.shtml RAccessed 59.5:.==S
22

You might also like