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

final examination report of data strucures and algorithms course

36 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 đề Final Examination Report
Tác giả Trương Quang Khôi
Người hướng dẫn Ho Thị Thanh Tuyền
Trường học Ton Duc Thang University
Chuyên ngành Data Structures and Algorithms
Thể loại Report
Năm xuất bản 2022
Thành phố Ho Chi Minh City
Định dạng
Số trang 36
Dung lượng 2,59 MB

Nội dung

Then it check a basece weather it equal to | or not, and n is 6 it work toward base case and call the recursion which find max between two number, first is the array of size less form th

Trang 1

VIETNAM GENERAL CONFEDERATION OF LABOR

TON DUC THANG UNIVERSITY FACULTY OF INFORMATION TECHNOLOGY

7a

TOPIC FINAL EXAMINATION REPORT OF

DATA STRUCURES AND ALGORITHMS COURSE

Instructing Lecturer HO TH] THANH TUYEN Student’s name: TRUONG QUANG KHOI — 520H0546

Class : 20H50201 Course : 24

HO CHI MINH CITY, 2022

HO CHI MINH CITY, 2021 VIETNAM GENERAL CONFEDERATION OF LABOR

Trang 2

TON DUC THANG UNIVERSITY FACULTY OF INFORMATION TECHNOLOGY

7a

TOPIC FINAL EXAMINATION REPORT OF

DATA STRUCURES AND ALGORITHMS COURSE

Instructing Lecturer HO TH] THANH TUYEN Student’s name: TRUONG QUANG KHOI — 520H0546

Class : 20H50201 Course : 24

HO CHI MINH CITY, 2022

Trang 3

THANK YOU Thanks for your effort in teaching even in online studying and help me have a knowledge to understand this course

Trang 4

Summarize

I solve 5 question in the report with my knowledege about data structure

Trang 5

ll

THE REPORT WAS COMPLETED

AT TON DUC THANG UNIVERSITY

I assure you that this essay is my own and under the instructions of lecturer Mai

Duy Tan The content of research, results, source code in this report is honest and has

not been published in any form before The documents and reference sources for

making the report, I will specify in the references section

If any fraud is found, I am fully responsible for the content of my report Ton Duc Thang University is not involved in any copyright infringement in the course of making this report (if any)

Ho Chi Minh city, January 20" 2022

Khôi Trương Quang Khôi

Trang 6

IV

CONFIRMATION AND EVALUATION OF LECTURER

Confirmation for the instructor

Ho Chi Minh City, 2022 (Sign and write full name) Khôi Trương Quang Khôi

Evaluation of the grading lecturer

Ho Chi Minh City, 2022 (Sign and write full name) Khoi

Trương Quang Khôi

Trang 7

Contents

Group 1: calculate Xj ccc 221111211 1111121 1112111011111 1111110111118 4 Group 2: Find the largest number 1n an afray - :525+ + 25552 5 B) PracticÌ€ - - - c T1 01110211101 11111122111 111101112 1110111111111 k1 ky 7 Question 2: SOFfÏTE o0 0 0 9 000 118050 15050 50058880499 059 958 7 A1) Selection SOYT L1 0111201121 1121111211211 101111011181 11 811g Hà 7

A) THeOFV Q20 0 0201112111121 1 12111121112 011 1011118112011 2á 24 A) _ Add new student - L2 1 22112211 11111211 101 111122 11111222111 2k 24 B) Remove a stud€nt Q2 0 12111211121 11121 1121111811110 112g xk 25 C) Search a studerit -. - 20 2 1222112211121 1 1121115211121 1 111181111118 81 111kg 25 B) PractICÌ€ - Q2 0202102011110 1 1111 11111111111 1111111111111 kka 25 Linked List 25

Trang 8

31 B) cccccccsssssssssssssevesssssssssssssstsessssssssssssssasssssssssssssesesssssssssessesseseseess 33 1 34 REFERENCES .34

Trang 9

Question 1: Recursion

Group 1: calculate x,

Calculation of 2°G using recursion

Final result 2*arcupIA(2,5)

2*groupiA(2,3) 2*aroupIA(2,2) a + os Gis rewrned

2#aroupIA(2 2) 2*aroopIA(2.2) 2 %* 4 = Bis returned

My funtcion have 2 parameter is a base number and an exponent

My recursive algorithms have:

+ Base case: when number of exponent equal to 1

+ Work toward base case: Each times my the exponent is reduce by | and continue until it reach to 1

+ Recursive Call: Group1A( x, y-1)

My function has a name is group! A(int x, int y) with the return is an interger For example I want to calculate 2°, so the base number X is 2 and the exponent

Y is 6

Trang 10

First recursion, Y was pass and check the base case, Y equal to 6 still higher than | so, it work toward to recursive Call, Y is reduced to | and remain 5 and

2 * group1A(2,5) which the function call it self

Second time recursion, Y was pass and check the base case, Y equal to 5 still higher than | so, it work toward to recursive Call, Y is reduced to 1 and remain 4 and 2 * group|A(2,4) which the function call it self Keep continue

we will have 2 * group1A(2,3), 2 * group1A(2,2) , 2 * grouplAQ,1) Until it

Y catch the base case which Y equal to 1, it stop at grouplA(2,1) and it return

2

So turn around to next we have 2 * group1 A(2,1) At this time we have

group! A(2,1) equal to 2 above and 2 * 2 =4 is returned Next, we have

group! A(2,2) equal to 4 above and 2 * 4 = 8 is returned Next, we have

group! A(2,3) equal to 8 above and 2 * 8 = 16 is returned Next, we have group! A(2,4) equal to 16 above and 2 * 16 =32 is returned Next, we have group! A(2,5) equal to 32 above and 2 * 32 = 62 is returned that is a final

answer for calculation of 2°

Group 2: Find the largest number in an array

Find mex in set of array 231524

Mathmex(4, maxlarrs) ) Methmaxl4, maxlarr,s) ) 4 <5 505 is retuned Mathmox(2 maxlarr.4 Mathmax(2, maxlarr,4) ) i tae wei a

Mathmaxl'S, mnaxlarr3) ) Malhmax(S, max(arr,3) ) so 5 b relure

Trang 11

Explanation

My function have 2 parameter, first is an array and second is the length of

array

My recursive algorithms have:

+ Base case: return first number of array when the remaining array equal to |

+ Work toward base case: Each time the function not reach to the base case then call the function by passing the array of size less from the end + Recursive Call: Max( arr, n— 1)

My function has name is max(int[] arr, int n) with the return is an interger For example 1 want to find max of this array: 2, 3, 1, 5, 2, 4

First i call a function and pass into max(int[] arr, int n) which arr is an array above and n is 6 Then it check a basece weather it equal to | or not, and n is

6 it work toward base case and call the recursion which find max between two number, first is the array of size less form the end and call therecursive by passing the array and the array of size less form the end( Math.max( 4,

max(arr, 5)) Keep continue same as above we will have Math.max( 2,

max(arr,4) ), Math.max( 5, max(arr,3)), Math.max( 1, max(arr,2)),

Math.max( 3, max(arr,1)) and return 2

At this time, we will turn back a recursion with max(arr,1) = 2

+In Math.max(3, max(arr,1)) we will have Math.max(3 , 2) this method will return 3 because 3 is larger than 2

+In Math.max(1, max(arr,2)) we will have Math.max(1 , 3) this method will return 3 because 3 is larger than 1

+In Math.max(5, max(arr,3)) we will have Math.max(5 , 3) this method will return 5 because 5 is larger than 3

+In Math.max(2, max(arr,4)) we will have Math.max(2 , 5) this method will return 5 because 5 is larger than 2

+In Math.max(4, max(arr,5)) we will have Math.max(4 , 5) this method will return 5 because 5 is larger than 4

And the function will return number 5 which is the larger number of array

Trang 13

I will sort the array with acending

First sorted number: first position of an array was mark to swap with the minimum number of an array

+ After fisnish broswing the array, the minitum number of an array is 2 So we swap position of number 2 and position of number 10

Second sorted number: second position of an array was mark to swap with

2 1253 |17|23|14|36|16 |9 | 10) 11

+ After fisnish broswing the array, the minitum number of an array is 3 So we swap position of number 3 and position of number 25

Third sorted number: Third position of an array was mark to swap with the minimun number of array

Trang 14

+ After fisnish broswing the array, the minitum number of an array is 6 So we swap position of number 6 and position of number 25

Fourth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ After fisnish broswing the array, the minitum number of an array is 9 So we swap position of number 17 and position of number 9

Fifth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ Number 23 is the next unsorted number of an array, then we set it as mintum number of an array

Trang 15

+ we browsing the array from the next number we mark above weather a number Is lower to minimun number of an array, we will set a new minimum number of an array

+ After fisnish broswing the array, the minium number of an array is 10 So

we swap position of number 23 and position of number 10

Sixth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ After fisnish broswing the array, the minium number of an array is 11 So

we swap position of number 14 and position of number 11

Seventh sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ After fisnish broswing the array, the minium number of an array is 14 So

we swap position of number 36 and position of number 14

Eighth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

Trang 16

+ After fisnish broswing the array, the minium number of an array is 17 So

we swap position of number 25 and position of number 17

Nineth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ Number 25 is the next unsorted number of an array, then we set it as mintum number of an array

+ we browsing the array from the next number we mark above weather a number Is lower to minimun number of an array, we will set a new minimum number of an array

+ After fisnish broswing the array, the minium number of an array is 23 So

we swap position of number 25 and position of number 23

Tenth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

+ Number 25 is the next unsorted number of an array, then we set it as mintum number of an array

+ we browsing the array from the next number we mark above weather a number Is lower to minimun number of an array, we will set a new minimum number of an array

Trang 17

+ After fisnish broswing the array, the mintum number of an array 1s itself, number 25 So we do nothing

Elevnth sorted number: First unsorted number of an array was mark to swap with the minimun number of array

number of an array

+ we browsing the array from the next number we mark above weather a number Is lower to minimun number of an array, we will set a new minimum number of an array

+ After fisnish broswing the array, the mintum number of an array 1s itself, number 26 So we do nothing

We complete sorting array with selection sort and this is the result

A2) Bubble Sort

My example array: 10, 25, 3, 17, 23 ,14 , 36, 6, 9, 2, 11

102513 |17|23|14|36|6 1912 |1

1 sort the array with decending order

First pass:

+( 10253 17 23 1436692 11) +~( 10253 17 23 14 3669 2 II) Here, algorithm compares the first two elements, and do nothing because 10 < 25 +( 10253 1723 1436692 11) (103 25 17 23 14 36692 11) swap since 25 > 3, We Have a flag and take it swapped

+( 103251723 1436692 11) (103 17 25 23 14 36692 11) swap since 25 > 17

+( 103 172523 1436692 11) (103 17 23 25 14 36692 11) swap since 25 > 23

Trang 18

12

+( 103 1723 25 1436692 11) (103 17 23 1425 36 6 92 11) swap since 25 > 14

+(103 1723 142536 692 II) — ( 10 3 17 23 1425 36 6 92 11) do

nothing since 25 < 36

+(103 1723 1425 36692 II) — ( 10 3 17 23 1425 636 92 11) swap since 36 > 6

+( 103 1723 142563692 11) (103 17 23 14 25 69 36 2 11) swap since 36 > 9

+( 1031723 142569362 11) +( 103 17 23 14 25 692 36 11) swap since 36 > 2

+( 1031723 1425692 36 11) —( 103 17 23 14 25 69 2 11 36) swap since 36 > 11

the largest element ( number 36) among the unsorted elements is placed at the end

Second Pass:

+( 103 1723 1425692 11 36) -+(3 10 17 23 14 25692 11 36) swap since 10 > 3,

+(3 1017 142325692 11 36) -+(3 1017 1423 25692 11 36) do

nothing since 23 < 25

+(3 1017 1423 25692 11 36) (3 10 17 14 23 6259 2 11 36) swap since 25 > 6

+(3 1017 142362592 11 36) (3 10 17 14 23 6 9 25 2 11 36) swap since 25 > 9

+(3 1017 142369252 11 36) (3 10 17 142369225 II 36) swap sinee 25 > 2

+(310 17142369225 11 36) — ( 3 10 L7 1423 692 1125 36) swap since 25 > IÍ

the largest element (number 25) among the unsorted elements 1s placed at the end

Trang 19

13

+(3 10 171423692 1125 36) — (3 10 14 17 23 6 92 11 25 36) swap since 17 > 14

+(3 10 141723692 11 2536) ¬ (3 10 14 17236 92 1125 36) do

nothing since 17 < 23

+(3 10 141723692 11 25 36) (3 10 14 17623 9 2 LI 25 36) swap since 23 > 6

+(3 10 141762392 11 2536) (3 10 14 176 9 23 2 II 25 36) swap since 23 > 9

+(3 10 141769232 11 2536) (3 10 14 17692 23 LI 25 36) swap since 23 > 2

+(310 141769223 11 25 36) — (3 I0 14 176 92 11 23 25 36) swap since 23 > 11

the largest element (number 23) among the unsorted elements is placed at the end

+(3 10 1461792 11 23 2536) (3 10 1469172 11 23 25 36) swap since 17 >9

+(3 10 1469172 11 23 2536) (3 10 1469217 11 23 25 36) swap since 17 >2

+(3 10 14692 17 11 23 25 36) — (3 I0 14692 11 17 23 25 36) swap sinee l7 > II

the largest element (number 17) among the unsorted elements is placed at the end

+(3 1061492 11 1723 2536) (3 106 9142 II 17 23 25 36) swap sinee l4 > 9

+(31069142 111723 25 36) ¬ (3 10 692 14 II 17 23 25 36) swap since 14 >2

Trang 20

14

+(3 10692141117 23 25 36) ~(3 1069211 1417 23 25 36) swap since 14> 11

the largest element (number 14) among the unsorted elements is placed at the end

Pass 6:

+(310692 11 1417 23 2536) ~ (310692 11 1417 23 25 36) do

nothing since 3 < 10

+( 310692 11 1417 23 2536) ~ (361092 11 1417 23 25 36) swap since 10 > 6

+(361092 11 1417 23 2536) ~ (369102 11 1417 23 25 36) swap since 10 >9

+(369102 11 1417 23 2536) ~ (36921011 1417 23 25 36) swap since 10 >2

+(32691011 1417 23 2536) ~( 32691011 1417 23 25 36) do nothing since 6 <9

the largest element (number 9) among the unsorted elements is placed at the end

Ngày đăng: 26/09/2024, 16:18