Docsity

asm1 of data structure and algorithms, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
1
ASSIGNMENT 1
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Le Phuong Trung
Student ID
Gcd191109
Class
Gcd0807b
Assessor name
Truong Nguyen Xuan Vinh
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature
Trung
Grading grid
P1
P2
P3
M1
M2
M3
D1
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download asm1 of data structure and algorithms and more Exams Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT 1

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19 : Data Structures and Algorithms Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Le Phuong Trung Student ID Gcd Class Gcd0807b Assessor name Truong Nguyen Xuan Vinh Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Trung Grading grid P1 P2 P3 M1 M2 M3 D1 D

Summative Feedback:Resubmission Feedback: Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

  • A. Introduction:
  • B. Abstract data type:
    • I. Definition:
    • II. Implementation:
    • III. Benefit:
    • IV. ADT in VDM:
      • a) Definition VDM
      • b) Example ADT in VDM:
    • V. ADT in Java: Bag
  • computer: C. Determine the operations of a memory stack and how it is used to implement function calls in a
    • I. Definition:
    • II. Operations:
    • III. Key Features:
    • IV. Explain and example how memory stack is organized:
  • D. Using an imperative definition, specify the abstract data type for a software stack:
    • I. Identify the problem:
    • II. Solution:
      • a) Propose:
      • b) Initialize Array List in java:
      • c) Methods of class ArrayList:
    • III. Example:
  • E. CONCLUSION:
  • F. REFERENCES:
  • Figure 1 System design with ADTs
  • Figure 2 boolean type code example............................................................................................................................
  • Figure 3 result boolean type code
  • Figure 4 specify an ADT.................................................................................................................................................
  • Figure 5 implement an ADT
  • Figure 6 memory stack example code
  • Figure 7 memory stack example code (result)............................................................................................................
  • Figure 8 Variable storage
  • Figure 9 call function...................................................................................................................................................
  • Figure 10 two types of ArrayList
  • Figure 11 Arraylist example code
  • Figure 12 result
  • Table 1 Boolean type
  • Table 2 Operation structure of the boolean function

A. Introduction: In this exercise 1, I'll do tasks like Create a Design Specification for a Data Structure that explains the valid operations that can be performed on the structure. Next, I will define the operations of the memory stack and how it is used to make function calls in the computer. Finally, I will Use an imperative definition, specifying the abstract data type for a software stack. B. Abstract data type: I.Definition:

  • An abstract data type (ADT) is a type (or class) for objects that have a set of values and operations that determine their behavior. It's named "abstract" because it provides a view that is independent of implementation. Abstraction is the process of delivering only the essentials while concealing the subtleties. - ADT's consists are as follows:
  • Declaration of data
  • Declaration of operations
  • Encapsulation of data and operations : data is hidden from user and can be manipulated only by means of operations - Language:
  • ADT is a description, not code, and it is independent of any programming language. This means that the use of an abstract type is unaffected by its representation (the actual data structure or data fields used to implement it), and that changes in representation have no impact on code outside of the abstract type.
  • Promote contract design which clearly defines supplier and customer responsibilities so that they can be enforced, if necessary **II.Implementation:
  • Implementaion of an Abstract Data Type (ADT):**
  • The user is unaware of this.
  • Various languages may implement the same ADT in different ways.
  • reusable b) Stack:
  • simple to use, understand
  • familiar
  • cheap
  • component–based IV.ADT in VDM: a) Definition VDM The Vienna Development Method (VDM) is one of the most well-known formal methodologies for computer-based system development. It has developed to encompass a range of methodologies and tools based on a formal specification language—the VDM Specification Language—that originated in work done at the IBM Laboratory Vienna in the 1970s (VDM-SL). It features a more advanced version, VDM++, that allows you to simulate object-oriented and concurrent systems. Commercial and academic tools for assessing models are available, as well as help for testing and proving model features and producing program code from verified VDM models. There is a history of industrial usage of VDM and its tools and a growing body of research in the formalism has led to notable contributions to the. b) Example ADT in VDM: Type Name Boolean Code writing Symbol bool data type true, false Operational structure This function will compare 1 information with 1 pre-confirmed information and return true or false answer corresponding to the available setting. Table 1 Boolean type Operator Name Type Not b Negation bool - > bool a and b Conjunction bool * bool - > bool a or b Disjunction bool * bool - > bool a => b Implication bool * bool - > bool

a <=> b Bi implication bool * bool - > bool a = b Equality bool * bool - > bool a <> b Inequality bool * bool - > bool Table 2 Operation structure of the boolean function

**- Example:

  • Code:** Figure 2 boolean type code example + Result: Figure 3 result boolean type code V.ADT in Java: Bag
  • Bags are only designs and will only show an overview of functions. Ex: similar: a bag of candy, you can only see the shell of the candies but not the actual candy.
  • similar to list, the position of the elements is not important. Ex: {3, 2, 7, 8} is equivalent to {2, 3, 7, 8}.

- In Java, we can use implement an ADT by a: Figure 5 implement an ADT C. Determine the operations of a memory stack and how it is used to implement function calls in a computer: I. Definition: The execution of each thread takes place in stack memory. Method-specific data, such as local variables and pointers to objects in the heap memory referenced by the method, are stored in stack memory. The memory on the stack is accessed in LIFO (Last In First Out) order. Stack storage, to be precise. When a method is called, a block in stack memory is generated to contain local

primitives and object references. When the method is finished, the block is no longer utilized and is passed on to the next method. When compared to Heap memory, Stack memory is extremely tiny. II. Operations: The stack performs the following fundamental operations:

  • Push: Inserts a new item into the stack. An overflow circumstance occurs when the stack is completely full.
  • Pop: Takes an item off of the stack. Items are shown in reverse order of when they were pushed. It is considered to be a Flow condition if the stack is empty.
  • Peek or Top: Returns the stack's top element.
  • isEmpty :If the stack is empty, returns true; otherwise, returns false (geeksforgeeks, 2021). III. Key Features: stack memory will have the following main functions:
  • It grows and shrinks as new methods are called and returned respectively
  • Variables inside stack exist only as long as the method that created them is running
  • It's automatically allocated and deallocated when method finishes execution
  • If this memory is full, Java throws java.lang.StackOverFlowError
  • Access to this memory is fast when compared to heap memory
  • This memory is threadsafe as each thread operates in its own stack (baeldung, 2020) IV. Explain and example how memory stack is organized:
  • A block is reserved on top of the stack for local variables and certain accounting data when a function is invoked. The block will not be utilized when that function returns, but it can be used in the following function call. The stack is always put first in LIFO (last in, first out) order, with the most recently reserved block being the first to be released. This simplifies stack tracing; removing a block off the stack is as easy as changing a pointer.
  • Below is a picture illustrasion for memory stack implemented function call:
  • When a function call happens previous variables get stored in the stack Figure 8 Variable storage +Returning value from base case to caller function: Figure 9 call function In the example, the calls are 'stacked' on top of the other because they depend on the results of the previous functions and this stacking also makes the base case controllable. program stop. This is called the call stack (or execution stack). D. Using an imperative definition, specify the abstract data type for a software stack: I.Identify the problem:

To save the list of information, we will need to create an array. This list will be sorted so that we can have quick random access to each child element. For example, if you want to get the child element information at the 10th position, the system must display it immediately. Second, this list can be rearranged by a certain criterion, thereby filtering out words according to the criteria of the top 10 students. Finally, since we don't know how many elements there will be or there will be any changes, the array needs to be able to change the size and elements. II.Solution: a) Propose:

  • From the problems mentioned above, I recommend using Arraylist for the following reasons:
  • The size of the Array List can be increased or decreased depending on the number of elements in it.
  • Add and remove elements at any position in the array quickly and efficiently.
  • There are many methods that support operations such as remove All - delete all, searching - search, iterations - browse arrays, retain All - edit elements, ...
  • An Array List can contain many types of objects such as Integer, String, Scanner, or a user-declared object. b) Initialize Array List in java: There are two types of ArrayList initialization, non-generic and generic. Figure 10 two types of ArrayList c) Methods of class ArrayList:
  • size(), isEmplty(), get(), set() – O(1)

Result: Figure 12 result E. CONCLUSION: After completing this report, I myself have learned a lot of remaining knowledge and added a lot of new and useful knowledge. Thanks to my new knowledge of Data Structure & Algorithms, I will be able to better prepare my products in the future. And most of all, I would like to thank Mr. Vinh for his enthusiastic guidance and help. F. REFERENCES:

Bibliography

baeldung. (2020, 7 22). baeldung. Retrieved from Stack Memory and Heap: https://www.baeldung.com/java- stack-heap geeksforgeeks. (2021, 9 17). geeksforgeeks. Retrieved from Stack Data Structure: https://www.geeksforgeeks.org/stack-data-structure-introduction-program/