Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt
1.
2. Sparkling Beelzebub
Group Members :
1)Muhammmad Mazhar Mustafa Shahid
2)Hassan Ahmed
3)Imran Farooq Mughal
4)Hafiz Salman Majeed
5)Hafiz Muhammad Hamza
3. Submitted To Respected Mam Sobia Sarwar
Topics:
1.Basic data structures
2.Static and dynamic data structures
3.Abstraction and ADTâs
4.Time and space requirements of various
implementation of ADTâs
5. Basic data structure
In Computer science
daIn ta structure is a particular way of storing and organizing data in computer
so it can be efficientlyâŠ.
*ObjectivesâŠ..
*We use this
· To understand the abstract data types stack, queue, deque, and list.
To understand the performance of the implementations of basic linear data
structures.
· To understand prefix, infix, and postfix expression formats.
· To use stacks to evaluate postfix expressions.
· To use stacks to convert expressions from infix to postfix.
· To use queues for basic timing simulations.
*and many moreâŠ.
6. b) LINEAR DATA STRUCTURESâŠ.
THAT IS THE SIMPLIST FORM OF DATA STRUCTURESâŠ..
Stacks, queues, deques, and lists are examples of data collections whose items are ordered
depending on how they are added or removed.
Once an item is added, it stays in that position relative to the other elements that came before
and came after it. SUCH SORT OF Collections are often referred as linear data STRUCTURESâŠ.
Linear structures can be thought of as having two ends. Sometimes these ends are referred to as
the âleftâ and the ârightâ or in some cases the âfrontâ and the ârear.â You could also call them the
âtopâ and the âbottom.â
The names given to the ends are not significant. What distinguishes one linear structure from
another is the way in which items are added and removed. in particular the location where
these additions and removals occur. For example, a structure might allow new items to be
added at only one end. Some structures might allow items to be removed from either end.
7. A stack (sometimes called a âpush-down stackâ) is an ordered collection of
items where the addition of new items and the removal of existing items
always takes place at the same end. This end is commonly referred to as
the âtop.â The end opposite the top is known as the âbase.â
The base of the stack is significant since items stored in the stack that are
closer to the base represent those that have been in the stack the longest.
The most recently added item is the one that is in position to be removed
first. This ordering principle is sometimes called LIFO, last-in first-out. It
provides an ordering based on length of time in the collection. Newer
items are near the top, while older items are near the base.
Many examples of stacks occur in everyday situations. Almost any
cafeteria has a stack of trays or plates where you take the one at the top,
uncovering a new tray or plate for the next customer in line. Imagine a
stack of books on a desk
8. The only book whose cover is visible is the one on top. To access
others in the stack, we need to remove the ones that are sitting on top
of them.
Considering this reversal property, you can perhaps think of
examples of stacks that occur as you use your computer. For
example, every web browser has a Back button. As you navigate from
web page to web page, those pages are placed on a stack (actually it
is the URLs that are going on the stack). The current page that you
are viewing is on the top and the first page you looked at is at the
base. If you click on the Back button, you begin to move in reverse
order through the pages.
9. As an element enters the queue it starts at the rear and makes its way
toward the front, waiting until that time when it is the next element to
be removed.
A queue is an ordered collection of items where the addition of new
items happens at one end, called the ârear,â and the removal of existing
items occurs at the other end, commonly called the âfront.â
The most recently added item in the queue must wait at the end of
the collection UNTILL a next elements comes in. This ordering
principle is sometimes called FIFO, first-in first-out
Example printing process
10. What Is a Deque?
A deque, also known as a double-ended queue, is an ordered collection of
items similar to the queue. It has two ends, a front and a rear, and the
items remain positioned in the collection.
What makes a deque different is the unrestrictive nature of adding and
removing items. New items can be added at either the front or the rear.
Likewise, existing items can be removed from either endâŠ
It is important to note that even though the deque can assume many of the
characteristics of stacks and queues, it does not require the LIFO and FIFO
orderings that are enforced by those data structures. It is up to you to
make consistent use of the addition and removal operations.
11. What is Lists?
The list is a powerful, yet simple, collection OF mechanism that provides the
programmer a wide variety of operations. However, not all programming
languages include a list collection.
A list is a collection of items where each item holds a relative position with
respect to the others.WE CAN SAY THAT ITâS A SYMITRICAL ARRANGMENT
OF ITEMS.
we will refer to this type of list as an unordered list. We can consider the list
as having a first item, a second item, a third item, and so on. ). For simplicity
we will assume that lists cannot contain duplicate items.
For example, the collection of integers 54, 26, 93, 17, 77, and 31 might
represent a simple unordered list of exam scores. Note that we have written
them as comma-delimited values, a common way of showing the list
structure. [54,26,93,17,77,31].
13. Data Structure is a way of storing
and organizing data, effectively.
There are two major categories of
Data Structures called ËâStatic
Structuresâ and âËDynamic
Structuresâ.
14. Static Data Structures
As same as the word static suggests, static data
structures are designed to store static âset of dataâ.
However, static âset of dataâ, doesnât mean that we can
not change the assigned values of elements. It is the
memory size allocated to âdataâ, which is static. So
that, it is possible to change content of a static
structure but without increasing the memory space
allocated to it.
15. Dynamic Data Structures
Dynamic data structures are designed to facilitate
change of data structures in the runtime. It is
possible to change the assigned values of elements, as
it was with static structures. Also, in dynamic
structures the initially allocated memory size is not a
problem. It is possible to add new elements, remove
existing elements or do any kind of operation on data
set without considering about the memory space
allocated initially.
16. Difference Between Static and Dynamic
Data Structure
Static data structure is given a fixed area of memory
which it can operate within. It is not possible to
expand this fixed size in the run time. So that,
locations of each element is fixed and known by the
program. Dynamic data structure also has an area
where it can operate. However, this size of the area is
flexible, not fixed as it was with static data structures.
It is possible to increase or decrease the area as
required, by adding or removing elements from data
structure.
17. From here onwards an example of a static array and a
dynamic linked list, will be considered to discuss differences.
18. Insertions and Removals
As discussed earlier, static structure has fixed sizes. It
is possible to remove the value of an element, but the
element is still there in the structure. Only difference
is that element doesnât contain any data. Such removal
is not going to free the memory occupied by the
element and can be considered as a waste of resources.
19. What about adding new elements to a static structure? As you already
know it is not possible because static data structure has a fixed size. In
order to add new element, we should create a new static structure
with number of elements required and move the data from existing
structure to new structure and assign additional elements with
required values.
20. As discussed earlier, dynamic data structures are
flexible. They do not have a fixed number of element or
fixed size. So it is possible to add or remove elements easily.
Consider a linked list as an example. As discussed earlier,
elements of a linked list points to next element of the list.
Imagine that you want to remove element âCâ of below
linked list. As you can see âBâ is pointing at âCâ and âCâ is
pointing at element âDâ. If we remove element âCâ, element
âBâ should point to element âDâ, to keep the linked list
unbroken. So what we have to do is just changing the
pointers and assign element âCâ with a NULL value, so that
garbage collator (or similar mechanism) will remove the
object and release the memory consumed by that object. An
example is shown below.
21.
22. Addition of new items to an dynamic data
structure is also similar to the process of
removal. Imagine that we want to add an
element after element âBâ and before element
âCâ. What we have to do is simply adding the
new element to memory, changing pointer of B
to point to newly added element and setting
pointer of new element to point at element âCâ.
23.
24. So it is clear that, removal of an element from Static Data
Structure is not possible. It is possible to remove or null the
value of element, but it will not free the memory consumed
by the element. It is possible to create a new static data
structure and move the data from previous structure,
excluding the valued needed to be removed. However, it is a
resource consuming process, as it creates number of
instances of data structures to complete the process.
When it comes to dynamic data structures, removal is
efficient and easy to manage. In linked lists, it is all about
setting an object to null and changing some pointers. No new
objects will be created and resource consume is at minimum.
25. Insertion is also same, static structures have a fixed size, so
insertion of elements in not possible. The only way of inserting
elements to a static data structure is creating a new data
structure with required number of elements and copying the
previous values in to new structure. This is again a resource
consuming process. Think of a array containing 1000 elements
and you want to add a new element at the end. Youâll have to
create a new array with 1001 elements and move values from
previous array to new array making number of calls.
But when it comes to dynamic structure, addition of an
element is a simple process. In linked lists, it is just creation of an
object and changing two pointers. When compared with static
data structures, resource consume is at minimum and resources
are used effectively.
26. Advantages and Disadvantages
According to above discussion it is clear that dynamic data structures
share following characteristics.
Ability to efficiently add, remove or modify elements
Flexible size
Effective use of resources â because resources are allocated at the runtime,
as required.
Slower access to elements (when compared with static data structures)
Static data structures share following characteristics
Faster access to elements (when compared with dynamic data structures)
Add, remove or modify elements is not directly possible. If done, it is a
resource consuming process.
Fixed size.
Resources allocated at creation of data structure, even if elements are not
contain any value.
28. Abstraction
In computer science, abstraction is a technique for managing
complexity of computer systems. For example, a programmer
writing code that involves numerical operations may not be
interested in the way numbers are represented in the underlying
hardware (eg. whether they're 16 bit or 32 bit integers), and
where those details have been suppressed it can be said that they
were abstracted away, leaving simply numbers with which the
programmer can work.Another Example is when we enter Roll.
No. for knowing the result and we check our result direct.We
cannot know about the inner process.This process is due to
abstraction.Abstraction is simply the removal of unnecessary
detail.The idea is that to design of part of a complex system you
must identify what about that part other must know in order to
design their parts and what detail you can hide.The part other
must know is the abstraction.
29. It has two types.
1) Control Abstraction
2) Data Abstraction
Abstraction can to control or to data: Control
abstraction is the apply abstraction of actions while
data abstraction is that of data structures.
Control abstraction involves the use of
subprograms and related concepts control flows
Data abstraction allows handling data bits in
meaningful ways. For example, it is the basic
motivation behind datatype.
30. Abstract Data Type
An abstract data type is a logical explanation of data processing
with hidden implementation process.There are two parts of
ADTPublic or external part.
* The Conceptual picture(The users view that how the picture
look like,how the structure is organized).
* The conceptual operation(Whatâs the user can do the ADT).
2) The private or internal part.
* The representation(How the structure actually stored).
* The implementation of the operation(The actual code).
Examples..
Application Software,Browser,Skype and Games etc.
31. Figure shows a picture of what an abstract data type is and how it
operates. The user interacts with the interface, using the operations
that have been specified by the abstract data type. The abstract data
type is the shell that the user interacts with. The implementation is
hidden one level deeper. The user is not concerned with the details of
the implementation.
32. The implementation of an abstract data type, often referred to as
a data structure, will require that we provide a physical view of
the data using some collection of programming constructs and
primitive data types. As we discussed earlier, the separation of
these two perspectives will allow us to define the complex data
models for our problems without giving any indication as to the
details of how the model will actually be built. This provides an
implementation-independent view of the data. Since there will
usually be many different ways to implement an abstract data
type, this implementation independence allows the programmer
to switch the details of the implementation without changing the
way the user of the data interacts with it. The user can remain
focused on the problem-solving process.
34. Data may be organized in many different ways. The logical or mathematical model
organization of data is called data structures . the choice of particular data structure
depend on the following considerations .
A. It must be able to represent the relationship of the data in the real world.
B. It must be simple enough so that it can be processed efficiently as and when
necessary.
The study of data structures includes:
A. Logical description of data structure.
B. Implementation of data structure.
Quantitative analysis of the data structure. This analysis includes determining the
amount of memory needed to store the data structure (also called as space complexity)
& the time required to process it. (also called as time complexity)
35. Time Complexity:
This measure is used to estimate the running time of algorithm in terms of size of
input data. For this purpose a popular notation called big âOâ notation is used.
Space Complexity :
This measure is used to define extra space consumed by the algorithm except
input data. This is also measured in terms of input size and big âOâ notation is also popular in
this case as well.
To calculate time and space complexity we use following notations.
1. Big Oh notation :
The function f(n)=O(g(n)) ( read as f of n is big O of g of n if and only if their
exist positive constants c and m such that f(n)<=c*g(n) for all n,n>=m.
2. Omega notation:
The function f(n)=âŠ(g(n)) ( read as f of n is omega of g of n if and only if their
exist positive constants c and m such that f(n)>=c*g(n) for all n,n>=m.
3. Theta notation:
The function f(n)=Æ(g(n)) ( read as f of n is theta of g of n if and only if their exist
positive constants c and m such that c*g(n)<=f(n)<=c2*g(n) for all n,n>=m.