Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

35

Transcript of Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Page 1: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt
Page 2: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Sparkling Beelzebub Group Members :1)Muhammmad Mazhar Mustafa

Shahid 2)Hassan Ahmed 3)Imran Farooq Mughal 4)Hafiz Salman Majeed 5)Hafiz Muhammad Hamza

Page 3: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Submitted To Respected Mam Sobia Sarwar

Topics:

1.Basic data structures2.Static and dynamic data structures3.Abstraction and ADT’s4.Time and space requirements of

various implementation of ADT’s

Page 4: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Basic Data Structure

Page 5: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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….

Page 6: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 7: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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

Page 8: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 9: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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-outExample printing process

Page 10: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 11: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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].

Page 12: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Static and Dynamic Data

Structure

Page 13: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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’.

Page 14: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Static Data StructuresAs 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.

Page 15: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Dynamic Data StructuresDynamic 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.

Page 16: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 17: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

From here onwards an example of a static array and a dynamic linked list, will be considered to discuss differences.

Page 18: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Insertions and RemovalsAs 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.

Page 19: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 20: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 21: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt
Page 22: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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”.

Page 23: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt
Page 24: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 25: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 26: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Advantages and DisadvantagesAccording to above discussion it is clear that dynamic data structures share following characteristics.Ability to efficiently add, remove or modify elementsFlexible sizeEffective 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 characteristicsFaster 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.

Page 27: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Abstraction and Abstract Data

Types

Page 28: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

AbstractionIn 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.

Page 29: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

It has two types. 1) Control Abstraction 2) Data AbstractionAbstraction 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 flowsData abstraction allows handling data bits in meaningful ways. For example, it is the basic motivation behind datatype.

Page 30: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Abstract Data TypeAn 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.

Page 31: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 32: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.

Page 33: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

Time and space requirement of

various implementation of

ADT’s

Page 34: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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:C. Logical description of data structure.D. 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)

Page 35: Data structure,abstraction,abstract data type,static and dynamic,time and space requirement of adt

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.