1649 Datastructure Assignment 1 Pass, Assignments of Computer Science

dhakbavanevnajananenvjaejfeinia

Typology: Assignments

2020/2021

Uploaded on 06/29/2023

nicolasdaocter
nicolasdaocter 🇻🇳

22 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
University of Greenwich
Data Structures & Algorithms
Assignment No: 1/2
NameNguyễn Minh Đạo
ID: GCS210351
Class: GCS1003B
ProjectID: 1649
InstructorLê Ngọc Thành
Due Date26/02/2023
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download 1649 Datastructure Assignment 1 Pass and more Assignments Computer Science in PDF only on Docsity!

University of Greenwich

Data Structures & Algorithms

Assignment No: 1/

Name:Nguyễn Minh Đạo

ID: GCS

Class: GCS1003B

ProjectID: 1649

Instructor:Lê Ngọc Thành

Due Date:26/02/

Assignment Brief 1 (RQF)

Higher National Certificate/Diploma in Business

Student Name/ID Number: Nguyễn Minh Đạo/GCS Unit Number and Title: Unit 19: Data Structures and Algorithms Academic Year: 2021 Unit Assessor: Lê Ngọc Thành Assignment Title: Examine and specify ADT and DSA Issue Date: Submission Date: 28/02/ Internal Verifier Name: Date: 26/02/ Submission Format: Format: ● The submission is in the form of an individual written report and a presentation. This should be written in a concise, formal business style using single spacing and font size 12. You are required to make use of headings, paragraphs and subsections as appropriate, and all work must be supported with research and referenced using the Harvard referencing system. Please also provide a bibliography using the Harvard referencing system. Submission ● Students are compulsory to submit the assignment in due date and in a way requested by the Tutor. ● The form of submission will be a soft copy posted on http://cms.greenwich.edu.vn/. ● Remember to convert the word file into PDF file before the submission on CMS. Note:

Learning Outcomes and Assessment Criteria (Assignment 1) Pass Merit Distinction LO1 Examine abstract data types, concrete data structures and algorithms D1 Analyse the operation, using illustrations, of two network shortest path algorithms, providing an example of each. P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures. P2 Determine the operations of a memory stack and how it is used to implement function calls in a computer. M1 Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue. M2 Compare the performance of two sorting algorithms. LO2 Specify abstract data types and algorithms in a formal notation D2 Discuss the view that imperative ADTs are a basis for object orientation and, with justification, state whether you agree. P3 Using an imperative definition, specify the abstract data type for a software stack. M3 Examine the advantages of encapsulation and information hiding when using an ADT.

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

Table of Content

  • Assignment Brief 1 (RQF)..................................................................................................................
    • Higher National Certificate/Diploma in Business...........................................................................
  • Introduction......................................................................................................................................
  • carried out on the structures (P1).................................................................................................... I. Create a design specification for data structures explaining the valid operations that can be
      1. Abstract data type (ADT)......................................................................................................
      • a. Definition.........................................................................................................................
      • b. Examples........................................................................................................................
        • b.1. ArrayList ADT........................................................................................................
        • b.2. LinkedList ADT....................................................................................................
  • a computer (P2)............................................................................................................................. II. Determine the operations of a memory stack and how it is used to implement function calls in
      1. Definition of Stack memory.................................................................................................
      1. Operations of memory stack...............................................................................................
      1. How Stack used to implement function calls......................................................................
  • III. The abstract data type for a software stack (P3).....................................................................
      1. What is a software stack?...................................................................................................
      1. Example of software stack..................................................................................................
  • References....................................................................................................................................

Features of ADT:

+Abstraction: The user does not need to know how the data structure is

implemented.

+Improved Conceptualization: ADT improves our understanding of the real world.

+Robust: The program is robust and capable of detecting faults.

Implementation of an Abstract Data Type (ADT):

+This is completely unknown to the user.

+The same ADT may be implemented differently in different languages.

+Several programming languages have ADTs and/or the ability to create ADTs

(userdefine types).

+ADTs provide modular design, which is essential in software development.

b. Examples.

As a result, a user only has to understand what a data type can accomplish, not how

it will be implemented. Consider ADT to be a black box that conceals the underlying

structure and design of the data type. Below is the definition and example of two ADTs

namely ArrayList ADT and LinkedList ADT.

b.1. ArrayList ADT

ArrayList is a Collection of list type that uses array structure to store elements. The

order of the elements is based on the order in which they were added, and the values of

these elements may overlap.

Figure2: Array List Data Structure

We can't make an array list of primitive types like int, float, char, and so on. In such

circumstances, the requisite wrapper class must be used.

The size of a Java ArrayList is used to initialize it. The size of the array list is

dynamic, changing as entries are added or withdrawn from the list.

The ArrayList functions is given below:

+add() -- inserts the element to the arraylist.

+addAll() -- adds all the elements of a collection to arraylist.

+clear() -- removes all the elements form arraylist.

+get() -- returns the element present in the specified index.

+contains() -- checks if the element is present in the arraylist.

+set() -- replace the single element form an arraylist.

+sort() -- sorts the arraylist according to specified order.

+toArray() -- converts an arraylist to an array.

+toString() -- converts the arraylist to a String.

Code example of arraylist:

+Because there is no need to shift when an element is added to or deleted from the

list, adding and deleting (add/remove) elements may be done quickly.

+You may use LinkedList as a list, stack, or queue.

+A LinkedList's elements may be separated (rather than contiguous) in memory. The

connection between the components is two-way. Each element in the list has references to

the element argument that came before it and the element that came after it.

Figure3: Linked List Data Structure

The elements are stored in a doubly linked list using the Java LinkedList class. It

gives you a linked-list data structure. It derives from AbstractList and implements the List

and Deque interfaces.

Figure4: Doubly Linked List structure

The LinkedList functions is given below:

+add() -- add an element at the end of the linkedlist.

+get() -- access an element from the linkedlist.

+set() -- change elements of the linkedlist.

+remove() -- remove an element from linkedlist.

+contains() -- check if the linkedlist contains the element.

+indexOf() -- return the index of the first occurrence of the element.

+iterator() -- return an iterator to iterate over linkedlist.

Code example of LinkedList:

Figure5: Memory Stack

2. Operations of memory stack.

In the memory of a computer, data is kept in linear data structures called memory

stacks. They may also be known as lines. A stack must always contain the same type of

data.

Pop operation: Removing an element is referred to as a pop operation. There is only

one element that can be removed since we can only access the element at the top of the

stack. Just the top of the stack is removed.

Peek operation: The user can view the element at the top of the stack using the peek

operation. No changes are made to the stack during this process.

Push operation: The act of pushing data onto a stack is referred to as a push

operation.

isEmpty: Determine if the stack is empty or not. The programmer must internally

maintain the size of the stack, which will be updated throughout push and pop operations,

in order to prevent conducting actions on an empty stack. Normally, the boolean result

returned by the function isEmpty() True if size equals 0, else False.

Figure6: Push and pop operations

3. How Stack used to implement function calls.

Example for the working of function calls:

The call stack is set up as a stack, so when a call is made, the caller pushes the return

address into the stack. When the called subroutine is finished, it pops or pulls the return

address off of the stack and hands control to that address. A call stack's main function is to

store the return addresses. The location of the instruction at which the caller function can

subsequently resume is required to be kept someplace when a subroutine is called.

The last element pushed (inserted) into the stack is the first element popped

(removed) from the stack, which is why stacks are referred to as last-in first-out (LIFO)

data structures. Below is the example:

Explaination:

♦A space in stack memory is generated when we enter the a() function to store the

method's primitives and references.

+The basic integer b and c value is immediately stored in stack memory.

♦The a() function will allocate additional memory on top of the existing stack when it calls

the b() and c() function This will store:

+The calling object's stack memory this object reference

+The stack memory's primitive value

III. The abstract data type for a software stack (P3).

1. What is a software stack?

The collection of parts that cooperate to enable the execution of the program is

referred to as a software stack. Back-end operations are powered by certain software

components, computations are performed by others, and user interfaces are made possible

by others. Nevertheless, a software stack's elements cooperate to effectively offer

application services to the end user.

Figure8: Software Stack

An application is made up of a collection of functions that operate together in a

defined architecture to provide certain services to the user. The most basic application

architecture is made up of three layers:

+When a consumer accesses the program through a website or web-based

application portal, they view the presentation layer.

+Application logic and business rules are included in the logic layer to help satisfy

application requests. This layer controls data transit between the data layer and the display

layer, performs computations, and makes decisions regarding how to handle requests.

+When a computation is required or if it has to be moved to a user-visible

presentation layer, the data layer is a server-side system that sends logic layer information.

Advantages of software stack:

+They provide the very bare minimum of software needed to achieve the intended

outcomes.

+Software stacks may be manually placed in computer templates or installed

automatically in systems.

+For customisable systems, software stack installation and use are same. As a

consequence, the solutions provided are also reliable.