Docsity

ASM1_Dataastrungture and algorithms, Essays (university) of Data Structures and Algorithms

Toggle sidebar
bg1
ASSIGNMENT 1 FRONT SHEET
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 Nguyen Tan Anh Student ID BHAF190112
Class BHAF-1911-2.1 Assessor name Nguyen Thai Cuong
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 Tan Anh
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a

Partial preview of the text

Download ASM1_Dataastrungture and algorithms and more Essays (university) Data Structures and Algorithms 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyen Tan Anh Student ID BHAF Class BHAF-1911-2.1 Assessor name Nguyen Thai Cuong 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 Tan Anh 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 A. INTRODUCTION....................................................................................................................................................... 6 B. CONTENTS............................................................................................................................................................... 6 I. Create a design specification for data structures explaining the valid operations that can be carried out on the structures (P1)......................................................................................................................................................... 6

  1. Definition of Abtract Data Types (ADT)............................................................................................................ 6
  2. List.................................................................................................................................................................... 8
 - 3. Stack............................................................................................................................................................... - 4. Queue............................................................................................................................................................ 
  • (P2)........................................................................................................................................................................
      1. Memory Stack definition................................................................................................................................
      1. Memory Stack operations..............................................................................................................................
      1. Memory Stack example..................................................................................................................................
      1. How the memory stack implemented function call.......................................................................................
  • III. Using an imperative definition, specify the abstract data type for a software stack (P3).................................
      1. A software stack.............................................................................................................................................
      1. Flow chart and code.......................................................................................................................................
  • IV. Illustrate, with an example, a concrete data structure for a First In First out (FIFO) queue (M1).....................
  • V. Compare the performance of two sorting algorithms (M2)...............................................................................
      1. Two sorting algorithms..................................................................................................................................
      1. Compare the performance of these sorting algorithms.................................................................................
  • VI. Examine the advantages of encapsulation and information hiding when using an ADT (M3)..........................
      1. Encapsulation and information hiding...........................................................................................................
      1. The advantages of encapsulation and information hiding when using an ADT..............................................
  • (D1)........................................................................................................................................................................ VII. Analyse the operation, using illustrations, of two network shortest path algorithms and an example of each
      1. Dijkstra algorithm..........................................................................................................................................
      1. Bellman-Ford algorithm.................................................................................................................................
  • whether you agree (D2)......................................................................................................................................... VIII. Discuss the view that imperative ADTs are a basis for object orientation and, with justification, state
  • C. CONCLUSION.........................................................................................................................................................
  • D. REFERENCES..........................................................................................................................................................
  • Figure 1: Abstract Data Type Concept Diagram........................................................................................................... List of Figures
  • Figure 2: Linkde list......................................................................................................................................................
  • Figure 3: Illustration for Singly-Linked List...................................................................................................................
  • Figure 4: Illustration for Doubly-Linked List.................................................................................................................
  • Figure 5: Class Node and Contructor.........................................................................................................................
  • Figure 6: Class MyList.................................................................................................................................................
  • Figure 7: The method "isEmpty()”.............................................................................................................................
  • Figure 8: The method "add()"....................................................................................................................................
  • Figure 9: The method "addMany()"...........................................................................................................................
  • Figure 10: The method "traverse".............................................................................................................................
  • Figure 11: The method "delFirst()"............................................................................................................................
  • Figure 12: The method "addFirst()"...........................................................................................................................
  • Figure 13: The method "delLast()".............................................................................................................................
  • Figure 14: The method "getLast()".............................................................................................................................
  • Figure 15: The main function.....................................................................................................................................
  • Figure 16: Result........................................................................................................................................................
  • Figure 17: Illustration for a stack...............................................................................................................................
  • Figure 18: Illustration for push a element onto stack................................................................................................
  • Figure 19: Illustration for a stack after push a element.............................................................................................
  • Figure 20: Illustration for pop operation the topmost element of a stack.................................................................
  • Figure 21: Illustration for a stack after pop................................................................................................................
  • Figure 22: Class Stack and methods...........................................................................................................................
  • Figure 23:The method "isEmpty()"'............................................................................................................................
  • Figure 24: The method "isFull()"................................................................................................................................
  • Figure 25: The method "push()"................................................................................................................................
  • Figure 26: The method "pushMany()".......................................................................................................................
  • Figure 27: The method "top()"...................................................................................................................................
  • Figure 28: The method "pop()"..................................................................................................................................
  • Figure 29: The main function.....................................................................................................................................
  • Figure 30: Figure illustratrion for a queue.................................................................................................................
  • Figure 31: Class ArrayQueue......................................................................................................................................
  • Figure 32: The method "isEmpty()"...........................................................................................................................
  • Figure 33: The method "isFull()"................................................................................................................................
  • Figure 34: The method "enqueue()"..........................................................................................................................
  • Figure 35: The method "enqueueMany()".................................................................................................................
  • Figure 36: The method "dequeue()"..........................................................................................................................
  • Figure 37: The method "front()"................................................................................................................................
  • Figure 38: The method "clear()"................................................................................................................................
  • Figure 39: The method "getQueue()"........................................................................................................................
  • Figure 40: The method "size()"..................................................................................................................................
  • Figure 41: The m ethod "grow()"...............................................................................................................................
  • Figure 42: The main function.....................................................................................................................................
  • Figure 43: Result........................................................................................................................................................
  • Figure 44: The program that calculates the factorial of a number.............................................................................
  • Figure 45: Result of factorical of 4.............................................................................................................................
  • Figure 46: The main interface of software.................................................................................................................
  • Figure 47: The result (red arrow)...............................................................................................................................
  • Figure 48: The result (red arrow)...............................................................................................................................
  • Figure 49: Main flow..................................................................................................................................................
  • Figure 50: Flowchart for check function....................................................................................................................
  • Figure 51: The method "check_bracket"...................................................................................................................
  • Figure 52: Get event , input and return result...........................................................................................................
  • Figure 53: Illustration a queue...................................................................................................................................
  • Figure 54: Class Person..............................................................................................................................................

 A data type is a type together with a collection of operations to manipulate the type. For example, an integer variable is a member of the integer data type. Addition is an example of an operation on the integer data type. Figure 1 : Abstract Data Type Concept Diagram.  Abtract Data Types (ADT): is the specification of a data type within some programming language, independent of an implementation. The interface for the ADT is defined in terms of a type and a set of operations on that type. The behaviour of each operation is determined by its inputs and outputs. An ADT does not specif y how the data type is implemented. These implementation details are hidden from the user of the ADT and protected from outside access; a concept referred to as Encapsulation.  A data structure is the implementation for an ADT. In an object-oriented language like Java, an ADT and its implementation together make up a class. Each operation associated with the ADT is implemented by a member, function or method. The variables that define the space required by a data item are referred to as data members. An object is an instance of a class, that is, something that is created and takes up storage during the execution of a computer program.  Types of ADT: Some common ADTs, which have proved useful in a great variety of applications, are:

  • List.
  • Stack.
  • Queue.
  1. List. The Abstract Data Type list is a set of elements that have a linear reference to each other. A linear association implies that each variable on the list has a unique successor, except for the first one. Lists also have an intuitively-called size property, which is essentially the number of elements on the list. That list is mutable. List is also an abstraction, meaning the actual specification of the data form is supported by other classes. These classes include ArrayList that is internally implemented using Arrays, and LinkedList that is internally implemented using the data structure of LinkedList. 2.1. Illustration. A linked list is a common data structure made of a chain of nodes in which each node contains a value and a pointer to the next node in the chain. The head pointer points to the first node, and the last element of the list points to null. When the list is empty, the head pointer points to null. Figure 2 : Linkde list. Types of Linked Lists
  • Singly Linked List (Uni-directional)
  • Doubly Linked List (Bi-directional)
  • Circular Linked List.

Figure 5 : Class Node and Contructor. Image is the MyList class to contain the list link. In it, initialize 2 pointers are head and tail. The constructor of the MyList class initially has 2 null pointers. Figure 6 : Class MyList. The method that checks if the list is empty, if the empty list returns true, otherwise it returns false Figure 7 : The method "isEmpty()”. The add method to add a node to the singly linked list:

Figure 8 : The method "add()" The addMany method used to add many element of an array into linked list. Figure 9 : The method "addMany()" The traverse method has the function of displaying the value of the elements of the linked list Figure 10 : The method "traverse"

Figure 13 : The method "delLast()" The getLast method returns the value of the last node in the list Figure 14 : The method "getLast()" The main function involves the initialization of an empty singly linked list, then adding the elements of the array a to the list, and displaying the list on the screen, followed by deleting the first node and the last node of the list. and display the result, finally taking the value of the current last node of the list

Figure 15 : The main function. Below is an image of the output when it is printed to the screen after running the program Figure 16 : Result. 2.3. Appications.  Applications of linked list in computer science :

  • Implementation of stacks and queues.
  • Implementation of graphs: Adjacency list representation of graphs is most popular which is 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 linked list.  Applications of linked list in real world:
  • Push adds an element at the top of a stack: Figure 17 : Illustration for a stack. Figure 18 : Illustration for push a element onto stack.

Figure 19 : Illustration for a stack after push a element.

- Pop removes the topmost element of a stack: Figure 20 : Illustration for pop operation the topmost element of a stack

The isEmpty method will check if the stack is empty, if the stack is empty it will return true, otherwise, it will return false. Figure 23 :The method "isEmpty()"' The isFull method will check if the stack is full, if the stack is full it will return true, otherwise it will return false. Figure 24 : The method "isFull()" The push method will add an element to the top of the stack if the stack is not full, otherwise the full stack will print the message screen. Figure 25 : The method "push()"

The pushMany method will add the elements of an array one by one to the top of the stack in order if the stack is not full, otherwise the full stack will print the message screen. Figure 26 : The method "pushMany()" The top method will return the value of the element at the top stack Figure 27 : The method "top()" The pop method will return the value and remove the element at the top of the stack Figure 28 : The method "pop()" The main method will first initialize an empty stack. Next is to call pushMany method of the stack class to add the elements of array a to the stack, next will make the pop method call to get the value and delete the element at the top of the stack, then get the price. value of the current stack top. Continue adding value 10 to the top of the stack and show the value just added