






































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
data structure and algorithms assignment btec hnd uk diploma exam
Typology: Study Guides, Projects, Research
1 / 46
This page cannot be seen from the preview
Don't miss anything!
Qualification HND in Computing (RQF) Center Name Center Registration No Student name Assessor name Click or tap here to enter text. Choose an item. Unit Number/Name 19: Data Structures & Algorithms Assignment number and title Submitted on Softnet Development Ltd Click here to enter a date. Student Declaration Student signature: Date: Click here to enter a date.
Abstract data type: Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called “abstract” because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction The user of data type does not need to know how that data type is implemented, for example, we have been using Primitive values like int, float, char data types only with the knowledge that these data type can operate and be performed on without any idea of how they are implemented. So, a user only needs to know what a data type can do, but not how it will be implemented. Think of ADT as a black box which hides the inner structure and design of the data type. Now we’ll define three ADTs namely List ADT, Stack ADT, Queue ADT Student ADT properties of student: ID firstName lastName major birthOfDate email
status Method of Vehicle: Set, Get type Set, Get name Set, Get status run stop Implement in Java: Dog ADT:
Properties of Dog: name size type color Method of Dog: Set, Get name Set, Get size Set, Get size Set, Get color bark eat Implement in Java: 1-What is memory stack: A stack can be implemented in a random access memory (RAM) attached to a CPU. The implementation of a stack in the CPU is done by assigning a portion of memory to a stack operation and using a processor register as a stack pointer. The starting memory location of the stack is specified by the processor register as stack pointer.
Each new AR is placed on top of the run-time stack When a method terminates, its AR is removed from the top of the run-time stack. Thus, the first AR placed on the stack is the last one removed Implement Stack by Array in Java:
Definition of Queue: Like Stack, Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of queue is any queue of consumers for a resource where the consumer that came first is served first. The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. Queue Representation As we now understand that in queue, we access both ends for different reasons. The following diagram given below tries to explain queue representation as data structure
LinkedList
Linked List is a part of the Collection framework present in java.util package. This class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node Performing Various Operations on LinkedList: Adding elements Updating elements Removing elements Iterating over elements To Array (); Size (); remove First (); remove last (); Applications of linked list in computer science: Implementation of stacks and queues Implementation of graphs: Adjacency list representation of graphs is the most popular which uses a linked list to store adjacent vertices. Dynamic memory allocation: We use a linked list of free blocks. Maintaining a directory of names Performing arithmetic operations on long integers Manipulation of polynomials by storing constants in the node of the linked list representing sparse matrices Applications of linked list in the real world:
Output Compare the performance of two sorting algorithms Selection sort: Selection sort selects i-the smallest element and places at i-the position. This algorithm divides the array into two parts: sorted (left) and unsorted (right) subarray. It selects the smallest element from unsorted subarray and places in the first position of that subarray (ascending order). It repeatedly selects the next smallest element best case[O(N2)] also O(N) swaps Worst Case: Reversely sorted, and when the inner loop makes a maximum comparison. [O(N2)]. Also, O(N) swaps Average Case: [O(N2)]. Also, O(N) swaps Space Complexity: [ auxiliary, O (1)]. In Place sort Advantage:
Implementation in Java:
Using an imperative definition, specify the abstract data type for a software stack 1-Definition of software stack: An application consists of a set of functions working together in a defined architecture to deliver specified services to the user. The simplest application architecture consists of three layers: Presentation Layer: The presentation layer is what the client sees when they access the application through a website or web-based application portal. Logic Layer: The logic layer contains application logic and business rules that help fulfill application requests. This layer makes calculations and decisions about how to process requests while controlling the transmission of data between the data layer and the presentation layer. Data Layer: The data layer is a server-side system that passes information to the logic layer when it is necessary to complete a calculation or when it needs to be passed to the presentation layer where it becomes visible to users. Each of these layers has unique requirements in terms of the programming languages and software tools that are required to establish and maintain its function. A web-based presentation layer may be written in languages like HTML5, Javascript and CSS. The application layer could be programmed in Java, C#, Python or C++. Applications like MySQL and MongoDB could be used to maintain back-end servers. The term Software Stack refers to the set of components that work together to support the execution of the application. Some software components power back-end processes, some are used to perform calculations and some are used in the presentation layer to enable user interface. In any case, the components of a software stack work in tandem to efficiently deliver application part of a software stack: Applications have four tiers, three of which are on the server-side. This graphic explains the inner workings of a stack: the client is where it all starts and ends The client tier this is the only component in the browser
up to application architects to understand and anticipate the specific needs of an application before choosing the best set of software solutions that support the delivery of application services to the end-user Examine the advantages of encapsulation and information hiding when using an ADT Data encapsulation sometimes referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user. This mechanism restricts a range of operations that the user can perform on the hidden members of the class by executing special functions commonly called methods. This idea of hiding the details away from the user and providing a restricted, clearly defined interface is the underlying theme behind the concept of an abstract data type Data encapsulation’s advantages only affect the class’s implementation but the interface is still the same. For example, a developer can choose to create a stack that contains float numbers with lots of options such as an array (which will be chosen), linked list, and then write push () and pop () in order to put numbers into and remove them from the array respectively. However, in some cases, if the requirements force the developer to change the stack's implementation to a linked list, the array just need to be replaced with the linked list while all the implementation such as push () and pop (), which will be the same. Moreover, this mechanism is supported in C++ and C# by using the public, protected and private keywords during the class’s declaration In other word this mechanism is also called access control. A class will grant or deny access to its objects using the public and private access specifiers. Public objects can be accessed by any function in a program, while the private objects are the opposite objects can contain both public and private variables but only public information can be accessed
Discuss the view that imperative ADTs are a basis for object orientation and, with justification, state whether you agree 1-Discuss the view that imperative ADTs are a basis for object orientation ADT allows creation of instances with well-defined properties and behavior. Abstraction allows one to collect instances of entities into groups in which their common attributes need to be considered. Data abstraction is an encapsulation of a data type and the subprograms that provide the operation for that type In object-orientation, ADTs may be referred to as classes. Therefore, a class defines properties of objects which are the instances in an object-oriented environment. Programs can declare instances of that ADT, called an object. Object-oriented programming is based on this concept. ADT and Object-oriented Programming are different concepts. OOPs use the concept of ADT. ADTs vs OOP ADT allows creation of instances with well-defined properties and behavior. Abstraction allows one to collect instances of entities into groups in which their common attributes need to be considered. Data abstraction is an encapsulation of a data type and the subprograms that provide the operations for that type. Programs can declare instances of that ADT, called an object. Object-oriented programming is based on this concept. In object-orientation, ADTs may be referred to as classes. Therefore, a class defines properties of objects which are the instances in an object-oriented environment. ADT and Object Oriented Programming are different concepts. OOPs use the concept of ADT. ADT and OOP have some common features: Encapsulation, Abstraction, Attribute, Method, Recycle Besides that, OOP has some features that ADT does not have are Inheritance, Polymorphism How the processor uses the stack to perform the job?