Docsity

Assignment 1 data structure, Study Guides, Projects, Research 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
Phan Anh Ly Ly
Student ID
GCD191295
Class
GCD0905
Assessor name
Pham Thanh Son
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
LyLy
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

Partial preview of the text

Download Assignment 1 data structure and more Study Guides, Projects, Research 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 Phan Anh Ly Ly Student ID GCD Class GCD0905 Assessor name Pham Thanh Son 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 LyLy Grading grid P1 P2 P3 M1 M2 M3 D1 D

 Summative Feedback:  Resubmission Feedback:

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

  • I. Introduction
    • A. Scenario:
  • II. LO1 Examine abstract data types, concrete data structures and algorithms
    • carried out on the structures. A. P1 Create a design specification for data structures explaining the valid operations that can be
        1. Abstract Data Type (ADT): (geeksforgeeks.org, n.d.)
      • 2 Example:.............................................................................................................................................................
        1. Result:
    • calls in a computer. B. P2 Determine the operations of a memory stack and how it is used to implement function
        1. Application of Stack in memory
  • III. LO2 Specify abstract data types and algorithms in a formal notation
    • A. P3 Using an imperative definition, specify the abstract data type for a software stack.
        1. Introduction:
        1. Code:
        1. Result:
  • IV. References
  • Figure 1: Abstract Data Type (ADT). Table of Figure
  • Figure 2: List ADT.
  • Figure 3: Array List get().
  • Figure 4: Array List insert().
  • Figure 5: Array list pop().
  • Figure 6: Array List removeAt().
  • Figure 7: Array List set().
  • Figure 8: Array List size().
  • Figure 9: Array List isEmpty().........................................................................................................................................
  • Figure 10: Array List isFull().
  • Figure 11: Stack ADT.
  • Figure 12: Stack ADT code.
  • Figure 13: Stack ADT push().
  • Figure 14: Stack ADT pop().
  • Figure 15: Stack ADT peek().
  • Figure 16: Stack ADT size().
  • Figure 17: Stack ADT isEmpty().
  • Figure 18: Stack ADT isFull().
  • Figure 19: Queue ADT.........................................................................................................................................................
  • Figure 20: Queue ADT code.
  • Figure 21: enqueue().
  • Figure 22: dequeue().
  • Figure 23: Queue ADT peek().
  • Figure 24: Queue ADT size().
  • Figure 25: Queue ADT isEmpty().
  • Figure 26: Queue ADT isFull().
  • Figure 27: Array remove().
  • Figure 28: Array add()........................................................................................................................................................
  • Figure 29: Array isEmpty().
  • Figure 30: Array set().
  • Figure 31: Array size().
  • Figure 32: Array get().
  • Figure 33: Main class.
  • Figure 34: Array Example.
  • Figure 36: Array result.
  • Figure 37: Example of LIFO 1.
  • Figure 38: Example of LIFO 2.
  • Figure 39: Operation push().
  • Figure 40: Operation pop().
  • Figure 41: Operation peek().............................................................................................................................................
  • Figure 42: Operation isFull().
  • Figure 43: Operation isEmpty()......................................................................................................................................
  • Figure 44: call function in main()...................................................................................................................................
  • Figure 45: function diagram.
  • Figure 46: result.
  • Figure 47: Menu System.
  • Figure 48: Display with no data.
  • Figure 49: Input with same ID.
  • Figure 50: Input data.
  • Figure 51: Display information.
  • Figure 52: Searching with wrong ID.
  • Figure 53: Searching student.
  • Figure 54: Updating.
  • Figure 55: Update with wrong ID.
  • Figure 56: Delete with wrong ID.
  • Figure 57: Deleting.
  • Figure 58: Display again.
  • Figure 59: Input wrong function.
  • Figure 60: Exiting.

II. LO1 Examine abstract data types, concrete data structures and algorithms A. P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures.

1. Abstract Data Type (ADT): (geeksforgeeks.org, n.d.)

a) Definition:

Abstract Data Type (ADT) is a data type whose behavior is determined by a set of values and a set of operations. The abstract data type refers only to what operations will be performed, not how these operations will be performed. It does not specify how the data will be organized in memory and what algorithms will be used to perform the math operations. It is called "abstract" because it hides the details of how the operations are performed but only tells what the operation does is called abstraction. Figure 1 : Abstract Data Type (ADT). Now we’ll define three ADTs namely List ADT , Stack ADT , Queue ADT.

b) List ADT:

The data is generally stored in key sequence in a list which has a head structure consisting of count, pointers and address of compare function needed to compare the data in the list.

Figure 2 : List ADT. The data node contains the pointer to a data structure and a self-referential pointer which points to the next node in the list. The List ADT Functions is given below: A list contains elements of the same type arranged in sequential order and following operations can be performed on the list.

  • get() – Return an element from the list at any given position. Figure 3 : Array List get().
  • insert() – Insert an element at any position of the list.

Figure 6 : Array List removeAt().

  • replace() – Replace an element at any position by another element. Figure 7 : Array List set().
  • size() – Return the number of elements in the list. Figure 8 : Array List size().
  • isEmpty() – Return true if the list is empty, otherwise return false.

Figure 9 : Array List isEmpty().

  • isFull() – Return true if the list is full, otherwise return false. Figure 10 : Array List isFull().

c) Stack ADT:

  • In Stack ADT Implementation instead of data being stored in each node, the pointer to data is stored.
  • The program allocates memory for the data and address is passed to the stack ADT. Figure 11 : Stack ADT.
  • The head node and the data nodes are encapsulated in the ADT. The calling function can only see the pointer to the stack.
  • The stack head structure also contains a pointer to top and count of number of entries currently in stack.

Figure 14 : Stack ADT pop().

  • peek() – Return the element at the top of the stack without removing it, if the stack is not empty. Figure 15 : Stack ADT peek().
  • size() – Return the number of elements in the stack. Figure 16 : Stack ADT size().
  • isEmpty() – Return true if the stack is empty, otherwise return false. Figure 17 : Stack ADT isEmpty().
  • isFull() – Return true if the stack is full, otherwise return false.

Figure 18 : Stack ADT isFull().

d) Queue ADT:

  • The queue abstract data type (ADT) follows the basic design of the stack abstract data type. Figure 19 : Queue ADT.
  • Each node contains a void pointer to the data and the link pointer to the next element in the queue. The program’s responsibility is to allocate memory for storing the data. Figure 20 : Queue ADT code.
  • peek() – Return the element of the queue without removing it, if the queue is not empty. Figure 23 : Queue ADT peek().
  • size() – Return the number of elements in the queue. Figure 24 : Queue ADT size().
  • isEmpty() – Return true if the queue is empty, otherwise return false. Figure 25 : Queue ADT isEmpty().
  • isFull() – Return true if the queue is full, otherwise return false. Figure 26 : Queue ADT isFull().

2. Example:

  • Array List
  • SYMBOL: myArray
  • DATA VALUE: Integer OPERATOR NAME DESCRIPTION void remove(int x) Delete int - > void. remove (): used to remove element at position x. Example: myArray = [1, 6, 8 ,11] remove(1) - > myArray = [1,8,11] void add(int x) Insert int - > void add(): to add an element at position x. Example: myArray = [null] add(1); add(6); add(8); add(11). myArray = [1, 6, 8, 11] boolean isEmpty() isEmpty isEmpty - > boolean isEmpty(): if the myArray empty value true will return and false if it not empty. Example: myArray = [1,6,8,11] isEmpty() - > false list = [] isEmpty() - > true void set(int x, int y) Update int, int - > void get(): to update an element at the position x with new value y. Example: list = [8,11] updateList(1, 19) - > myArray = [8,19] int size() Size size - > int size(): return the number of element in the Array List. Example: myArray = [8 ,19] size() - > myArray = 2 a get(int x) Get get – a get(): gets the element at the position x Example: myArray = [8, 19] get(1) - > myArray = 19

Figure 29 : Array isEmpty(). Figure 30 : Array set().

Figure 31 : Array size(). Figure 32 : Array get().