Download Data Structures and Algorithms: A Comprehensive Guide with Examples and more Thesis Information Technology in PDF only on Docsity!
ASSIGNMENT 1 FRONT SHEET
Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 19: Data Structures and Algorithms
Submission date 9/8/2023 Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Nguyễn Hải Việt Student ID GCD
Class GCD1101 Assessor name Phạm Thành Sơn
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
Grading grid
P1 P2 P3 M1 M2 M3 D1 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date:
Internal Verifier’s Comments:
IV Signature:
Table of Contents I. Create a design specification for data structures explaining the valid operations that can be carried out on the structures.(P1) ................................................................................................................................................ 7 A. Definition of ADT .......................................................................................................................................... 7 B. Feature of ADT .............................................................................................................................................. 7 C. Advantage of ADT ......................................................................................................................................... 8
Figure 18: IsEmpty.................................................................................................................................................... 14 Figure 19: Code Double Linked List......................................................................................................................... 15 Figure 20: Code Double Linked List 2...................................................................................................................... 16 Figure 21: Code Double Linked List 3...................................................................................................................... 17 Figure 22:Code Double Linked List 4....................................................................................................................... 18 Figure 23: main double 1........................................................................................................................................... 19 Figure 24:main double 2............................................................................................................................................ 20 Figure 25:main double 3............................................................................................................................................ 21 Figure 26: resul code double linked list..................................................................................................................... 22 Figure 27: Push operation.............................................................................................. Error! Bookmark not defined. Figure 28: Push code..................................................................................................... Error! Bookmark not defined. Figure 29:Pop operation................................................................................................ Error! Bookmark not defined. Figure 30: Pop code....................................................................................................... Error! Bookmark not defined. Figure 31: Peek Code.................................................................................................... Error! Bookmark not defined. Figure 32: isEmpty code................................................................................................ Error! Bookmark not defined. Figure 33: size code....................................................................................................... Error! Bookmark not defined. Figure 34: How Stack memory organized..................................................................... Error! Bookmark not defined. Figure 35: code Stack 1................................................................................................. Error! Bookmark not defined. Figure 36:code Stack 2.................................................................................................. Error! Bookmark not defined. Figure 37: code Stack 3................................................................................................. Error! Bookmark not defined. Figure 38: Code Main.................................................................................................... Error! Bookmark not defined. Figure 39: Code main 2................................................................................................. Error! Bookmark not defined. Figure 40: Result........................................................................................................... Error! Bookmark not defined. Figure 41: add function.............................................................................................................................................. 30 Figure 42: add oparation............................................................................................................................................ 30 Figure 43: get function.............................................................................................................................................. 31 Figure 44: get operation............................................................................................................................................. 31 Figure 45: remove function....................................................................................................................................... 32 Figure 46: remove operation...................................................................................................................................... 32 Figure 47: size operation........................................................................................................................................... 32 Figure 48: contains operation.................................................................................................................................... 33 Figure 49: code Arraylist 1........................................................................................................................................ 34 Figure 50: code Arraylist 2 ........................................................................................................................................ 35 Figure 51: code Arraylist 3 ........................................................................................................................................ 36 Figure 52: code Arraylist 4 ........................................................................................................................................ 37 Figure 53: code Arraylist 5 ........................................................................................................................................ 38 Figure 54: class Movie.............................................................................................................................................. 39 Figure 55: class Movie 2........................................................................................................................................... 40 Figure 56: class Movie Manage................................................................................................................................. 41 Figure 57: code Main................................................................................................................................................. 43 Figure 58: print infor movie...................................................................................................................................... 44 Figure 59: result 1...................................................................................................................................................... 44
Figure 102: encapsulation in ADT............................................................................................................................. 69
I. Create a design specification for data structures
explaining the valid operations that can be carried
out on the structures.(P1)
A. Definition of ADT
An object's behaviour may be described by a collection of values and a set of operations, and
this behaviour is known as an abstract data type (ADT). The definition of ADT merely specifies
the actions that must be taken, not how they must be carried out. It is unclear what algorithms will
be utilised to carry out the operations and how the data will be organised in memory. Because it
provides an implementation-independent perspective, it is dubbed "abstract."
Figure 1 : ADT
B. Feature of ADT
Data and actions on that data are combined into a single entity using abstract data types (ADTs).
Key characteristics of ADTs include:
Abstraction : Only the fundamentals are given, thus the user is not required to understand how
the data structure is implemented.
Better Conceptualization : The actual world is better understood for us thanks to ADT.
resilient : The software is capable of detecting mistakes and is resilient.
Encapsulation : ADTs encapsulate the underlying workings of the data and provide a user-
interactive public interface. The data structure may now be modified and maintained more
easily as a result.
Data Abstraction : ADTs provide a degree of abstraction from the specifics of the data's
implementation. Users do not need to be aware of the details around the execution of the
operations that may be carried out on the data.
Data Structure Independence : ADTs may be implemented using various data structures, such
as arrays or linked lists, without having an impact on how well they work.
Information concealment : By limiting access to only authorized individuals and processes,
ADTs can safeguard the accuracy of the data. This lessens the chance of mistakes and data
abuse.
Modularity : ADTs are modular in that they may be used to create bigger, more complicated
data structures. Programming may now be more flexible and modular as a result.
C. Advantage of ADT
Encapsulation: Data and actions may be combined into one unit using ADTs, which makes
the data structure simpler to maintain and alter.
Abstraction : ADTs make working with data structures possible without requiring users to be
familiar with implementation specifics, which may make programming simpler and less error-
prone.
Data Structure Independence : Different data structures may be used to implement ADTs,
which can make it simpler to adapt to shifting demands and requirements.
Information concealment : ADTs may safeguard data integrity by limiting access and
blocking unwanted changes.
Modularity : Programming may become more flexible and modular because to the modularity
of ADTs, which can be coupled to create more sophisticated data structures.
D. Disadvantage of ADT
Overhead : Implementing ADTs may result in additional memory and processing overhead,
which might have an impact on speed.
Complexity : Implementing ADTs may be challenging, particularly for big and intricate data
structures.
Learning curve : Understanding the implementation and use of ADTs is necessary for their
use, which might take some time and effort to understand.
Limited Flexibility : Some ADTs may not be suited for all sorts of data structures or may have
limited capabilities.
Cost : Putting ADTs into practice would call for more money and resources, which would raise
the price of development.
E. examples of a general ADT
1. Definition of Double LinkedList
A Doubly Linked List is a variant of a Linked List, where traversing the nodes can be done in two
directions: forward and backward easily when compared to a singly Linked List.
Figure 5 : addfirst 3
AddLast(element): Add an element to the end of the list.
Figure 6 : Add Last 1 Figure 7 : add last 2
Figure 8 : add last 3
RemoveFirst(): Remove and return the element at the beginning of the list.
Figure 9 : Remove Firsst 1 Figure 10 : remove first 2
Figure 14 : remove last 3
GetFirst(): Return the element at the beginning of the list.
Figure 15 : Get First
GetLast(): Return the element at the end of the list.
Figure 16 : GetLast
Size(): Return the number of elements in the list.
Figure 17 : Size
IsEmpty(): Check if the list is empty.
Figure 18 : IsEmpty
3. Advantage of Double linkedList
A DLL may be walked through both forward and backward.
If a reference to the node that has to be destroyed is provided, the delete operation in DLL is
more effective.
Before a certain node, a new node may be added fast.
A reference to the preceding node is required in a singly linked list in order to remove a node.
Sometimes the list is traversed to get this preceding node. Using the previous pointer in DLL,
we can get the previous node.
4. Disadvantage of Double linkedList
Every DLL node needs additional space for a prior pointer. However, DLL may be
implemented with only one pointer.
An additional prior pointer must be preserved for all operations. For instance, while doing
insertion, we must adjust both the preceding and subsequent pointers. For instance, setting the
previous pointer requires one or two more steps in the following routines for insertions at
various places.
5. Example code
- D. Disadvantage of ADT
- E. examples of a general ADT
- Definition of Double LinkedList
- Basic operation on Double LinkedList
- Advantage of Double linkedList
- Disadvantage of Double linkedList
- Example code
- computer(P2)
- III. Using an imperative definition, specify the abstract data type for a software stack.(P3) C. How stack memory is organized Error! Bookmark not defined.
- Secenario
- What is ArrayList
- Basic Operation of ArrayList
- Implement program
- a. Code ArrayList
- b. Class Movie
- c. Class Movie Manage
- d. Code main
- e. Result code
- IV. Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue (M1)
- Scenario
- What is Queue
- Why Queue is suitable for this problem
- Basic operation of Queue
- Implement Code
- a. Code Queue
- b. Code class Customer
- c. Code class Customer List
- d. Code Main
- e. Result
- V. Compare the performance of two sorting algorithms (M2)
- Insert sort
- a. What is insert sort
- b. How insert sort work
- c. Example with an unsorted array: [5, 2, 4, 6, 1, 3]:
- d. Analyze its performance (time, memory)
- e. Example code
- Quick sort
- a. What is quick sort
- b. How quick sort work
- c. Example with an unsorted array: [5, 2, 4, 6, 1, 3]:
- d. Analyze its performance (time, memory)
- e. Example code
- VI. Examine the advantages of encapsulation and information hiding when using an ADT(M3)
- VII. References
- Figure 1: ADT.............................................................................................................................................................
- Figure 2: Double Linked List......................................................................................................................................
- Figure 3: AddFirst1.....................................................................................................................................................
- Figure 4: addfirst 2.......................................................................................................................................................
- Figure 5: addfirst 3.....................................................................................................................................................
- Figure 6: Add Last 1..................................................................................................................................................
- Figure 7: add last 2....................................................................................................................................................
- Figure 8: add last 3....................................................................................................................................................
- Figure 9: Remove Firsst 1..........................................................................................................................................
- Figure 10: remove first 2...........................................................................................................................................
- Figure 11: remove first 3...........................................................................................................................................
- Figure 12: Remove Last 1..........................................................................................................................................
- Figure 13: remove last 2............................................................................................................................................
- Figure 14: remove last 3............................................................................................................................................
- Figure 15: Get First...................................................................................................................................................
- Figure 16: GetLast.....................................................................................................................................................
- Figure 17: Size...........................................................................................................................................................
- Figure 60: find movie and remove movie..................................................................................................................
- Figure 61: result 2......................................................................................................................................................
- Figure 62: queue........................................................................................................................................................
- Figure 63: offer function............................................................................................................................................
- Figure 64: code offer.................................................................................................................................................
- Figure 65: poll function.............................................................................................................................................
- Figure 66: code poll...................................................................................................................................................
- Figure 67: peek function............................................................................................................................................
- Figure 68: code peek.................................................................................................................................................
- Figure 69: code size...................................................................................................................................................
- Figure 70: code isEmpty............................................................................................................................................
- Figure 71: code queue 1.............................................................................................................................................
- Figure 72: code queue 2.............................................................................................................................................
- Figure 73: code queue 3.............................................................................................................................................
- Figure 74: class Customer.........................................................................................................................................
- Figure 75: class Customer List..................................................................................................................................
- Figure 76: code main.................................................................................................................................................
- Figure 77: result code queue......................................................................................................................................
- Figure 78: unsorted array...........................................................................................................................................
- Figure 79: example insert sort 1................................................................................................................................
- Figure 80:example insert sort 2.................................................................................................................................
- Figure 81:example insert sort 3.................................................................................................................................
- Figure 82:example insert sort 4.................................................................................................................................
- Figure 83:example insert sort 5.................................................................................................................................
- Figure 84: example code insert sort...........................................................................................................................
- Figure 85: result insert sort........................................................................................................................................
- Figure 86: unsorted array...........................................................................................................................................
- Figure 87: example quick sort 1................................................................................................................................
- Figure 88: example quick sort
- Figure 89: example quick sort
- Figure 90: example quick sort
- Figure 91: example quick sort
- Figure 92: example quick sort
- Figure 93: example quick sort
- Figure 94: example quick sort
- Figure 95: example quick sort
- Figure 96: example quick sort
- Figure 97: example quick sort
- Figure 98: example quick sort
- Figure 99: example code quick sort...........................................................................................................................
- Figure 100: main quick sort.......................................................................................................................................
- Figure 101: result quick sort......................................................................................................................................
- Figure 20 : Code Double Linked List
- Figure 21 : Code Double Linked List
- Figure 23 : main double
- Figure 24 :main double