1. Trang chủ
  2. » Luận Văn - Báo Cáo

Information technology assignment 2 unit data structures and algorithms

46 0 0
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Data Structures and Algorithms
Tác giả Pham Phu Loc
Người hướng dẫn Phan Hoang Phu, Supervisor
Trường học BTEC FPT INTERNATIONAL COLLEGE
Chuyên ngành Information Technology
Thể loại Assignment
Năm xuất bản 2023
Thành phố Da Nang
Định dạng
Số trang 46
Dung lượng 10,36 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Cấu trúc

  • CHAPTER 3: IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS. (LO3) (11)
    • 1. Implement a complex ADT and algorithm in an executable programming language to solve (11)
  • CHAPTER 4: ASSESS THE EFFECTIVENESS OF DATA STRUCTURES AND ALGORITHMS. (LO4) (25)
    • 1. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm 4. Define asymptotẽC aniaèVSẽS................- c c HH HH TH HH HH TT ng 1 TH KT n0 kg ng 3 2. The reason of using asymptotic analysis for assessing the effectiveness of an (25)
    • 2. Determine two ways in which the efficiency of an algorithm can be measured, illustrating (30)
      • 2.1.2. lImplementafẽOn......................-‹c c c. 1111 HS T110 11 1H ng ng ng TH T00 118001150 4 2.1.3. D€mO......................... Án Hà HH HHằ HH HH KT KH HH KH TT 4 2.2. Measure of memOorY US4ÿ€............... LH TggnngkHT ng n kg g kg 4 2.1.1. DEFING. ốc ốố ố ốằằồ.ằ......... 4 lImplementafẽOn......................-‹c c c. 1111 HS T110 11 1H ng ng ng TH T00 118001150 4 (0)
  • FIQUre 20 OULPULL 7777... an (0)

Nội dung

Figure 2 Algorithm flowchart of Menu Source code: Performed Student: Pham Phu Loc... View Latest Message"; Performed Student: Pham Phu Loc 4... Education Send Message Algorithm Step

IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS (LO3)

Implement a complex ADT and algorithm in an executable programming language to solve

A queue is a line of items waiting to be handled, starting at the front of the line and processing it sequentially

In essence, a message is a byte array with some headers at the topff it is the data that is carried between the sender and the receiving program

A message queue employs an asynchronous communication protocol that allows messages to be added to a designated queue without the need for immediate replies or synchronization between sender and receiver In this model, the sender can continue processing other tasks without waiting for a response Email serves as a notable illustration of a message queue, where messages are enqueued and delivered to recipients without demanding an instant reply or acknowledgment.

Figure 1 Message Queue 1.2 Scenario overview

The conveyance and processing of messages between layers is one aspect of the provider interface for the middleware that is currently under development For transport, a buffer of queued messages is deployed and processed, the system requires a stack of messages

It is necessary to develop these types of collections for the system It is recommended to design an ADT/algorithm for these 2 structures and implement a demo version with the message as a string of up to 2fi0 characters Handle the problems and errors encountered in the demo carefully with exceptions and some tests should be done to prove the correctness of the algorithms/operations

From the requests that have been made, | have selected two suitable ADT types to deal with, namely Stacks and Queues

- The stack will be used to store process messages

- Queues are used to store the messages being transported

Performed Student: Pham Phu Loc 2

‘BTEC s nine win IG ean ù ‘BT EC

The main menu offers four primary functions: input message, send message, view message, and exit Each function corresponds to a number from 1 to 4 To execute a specific action, users select the function's corresponding number and enter it to initiate the desired process.

Figure 2 Algorithm flowchart of Menu Source code:

Performed Student: Pham Phu Loc

9 static Queue messageStore = new LinkedList();

10 static Stack messageConsumer = new Stack();

11 128 public static void main(String args[]) { int choice = 0;

14 Scanner sc = new Scanner(System.in);

17 System.out.println("Message System!");

18 System.out.println("1 Input Message");

19 System.out.println("2 Send Message");

20 System.out.println("3 View Latest Message");

26 System.out.print("Choose a number from 1 to 4: ");

27 choice = Integer.parseInt(sc.nextLine());

30 System.out.println("Please input number format!");

36 System.out.println("Please input number from 1 to 4!");

Figure 3 Source code of Menu Input Message

Step 1: Input a message below 2fi0 characters Step 2: Store a message to queue

Performed Student: Pham Phu Loc 4 eee SB Step 3: Break ‘BTEC

Display the message: Display the message

“Input Message Failed! -—yes> oe Gaerne aS

Messages can only contain characters ge SE Bo Kr"

Figure 4 Algorithm flowchart of Input Message Source code: a) SOSIBDARANHPSHCHUARHEWN

//Input Message e public static void addMessage() {

Scanner sc = new Scanner(System.in);

System.out.print("Input Message: "); ms = sc.nextLine(); try { if (ms.isEmpty()) { throw new Exception("Message cannot be blank!");

} else { try { if (ms.length() > 250) { throw new Exception("Input Message Failed! Messages can only contain 25@ characters"); else { } messageStore.add(ms) ; System.out.println("messageStore: nan Dan

} catch (Exception e) { System.out.printIn(e.getMessage());

Figure 5 Source code of Input Message

Performed Student: Pham Phu Loc 5

Step 1: Check if there are already messages in the queue

Step 2: If yes, retrieve the message in the first line of the queue

Step 3: Push messages to consumers

Please input messageStorel" if there are no message a in the queue yet

Vv Send the first message in the queue to the consumer

Figure 6 Algorithm flowchart of Send Message Source code:

Performed Student: Pham Phu Loc 6

“BTEC _ ơ aaa bon ù ‘BT E Cc

92 System.out.println("MessageStore is empty! Please input messageStore!");

97 System.out.println("messageStore: " +messageStore);

98 System.out.println("messageConsumer: " +messageConsumer) ;

Figure 7 Source code of Send Message View Latest Message

Step 1: Check if there are any messages in the stack

Step 2: If yes, retrieve the message on top of the stack

Input Nessage_

Ngày đăng: 08/10/2024, 16:42