47
University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Embed Size (px)

DESCRIPTION

Contents For this presentation, we have the following three parts: 1)A4 ’ s initial idea 2)The final version of B3 3)The conclusion

Citation preview

Page 1: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

University of MacauFaculty of Science and Technology

Programming Languages Architecture

SFTW 241 spring 2004Class B Group 3

Page 2: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

SFTW241SFTW241 Programming Programming

Language Language ArchitectureArchitectureGrouping Method Grouping Method

Analysis by Program Analysis by Program PresentationPresentation

Page 3: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Contents Contents • For this presentation, we have the

following three parts:

• 1)A4’s initial idea

• 2)The final version of B3

• 3)The conclusion

Page 4: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Part 1Part 1

A4’s initial ideaA4’s initial idea

Page 5: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• There are 21 students in class A and each student

file structure include the following information:

1.Student ID

2.Student name

3.Firest, second and third choice

4.Choose = 0

Page 6: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• There is one array and four stacks in this program

• All the information of each student is stored in this array

• And each stacks store all the members’ information of the corresponding group

• In each student’s data structure, if the choose is equal to 0, it meant that this student has not been selected; if it is 1, it meant that this student has been selected

Page 7: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• First load all the students’ information into

the array

• Then we choose four leaders random and load their information into the corresponding stack for each group

• And in this process there is a very important detail is that if the information is push into the stack, the choose in the array become 1 at once.

Page 8: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea

………………captain

………………captain

………………captain

………………captain

0 …7654321 …

Page 9: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• Then load the captain’s first choice’s ID number

and compare with the student ID number in the array

• If the ID number is not equal, compare with the next one

• If the ID number is equal and the choose is equal to 1, compare with the next one

• If the ID number is equal and the choose is equal to 0, push the student’s information into the corresponding stack

Page 10: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea

THL Yedda UNWFZH LJQ SUN ZDF YYYEricWalter……

Eric ZDF YYY Walter

Choose = 0

Page 11: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• If someone’s all three choices are selected, then the corresponding team will stop adding new member.• And we use the randomly method to add new members

Page 12: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

A4’s initial ideaA4’s initial idea• Their idea is use stack to store each group’s

information

• As we know, its advantage is that it is very easy to access data

• But its disadvantage is that we do not know who has been selected and who has not, and if you need to random select one person, you must do the selection from all the people, then the time you spend is very expensive

Page 13: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ImprovementImprovement In the presentation between us and

group A4, we got lots of good suggestions, and we also got some ideas from their algorithm.

Page 14: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Idea & SuggestionIdea & Suggestion• The most important suggestions:

(a)One array is enough to carry out our algorithm

(b)Swapping structures which contain huge data will cost lots of time

(c) There is no need to swap or delete by using link-list

Page 15: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Part 2Part 2

FFinal Versioninal Versionof B3of B3

Page 16: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Suggestion AnalysisSuggestion Analysis• I think our program should contain

the following two advantages:

(a)Efficient

(b)Reusable

(c)Informational

Page 17: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ReusableReusable• The data in the main memory can be used

again even after the grouping.

• Compare with the memory operation, I/O operation (file processing) is very low.

• We have to do the grouping from the beginning if some special case happen.

Page 18: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

EfficientEfficient• It is necessary to divide the data into

two parts: unused and used

• Just use one array to store the information

• The choice should be the integer instead of string for checking easy and less space

Page 19: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

InformationalInformational• Easy to get the information of a

team: the number of the member; identity of the member

Page 20: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Data StructureData Structure• Data is stored as the following form: class Record{ private: int id; string name; int first, second, third; }

Page 21: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

UnitUnit

Student Unit

Student ID Student Name First Choice Third ChoiceSecond Choice

Page 22: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Improvements Improvements • Id number is added, it is easy to get

the corresponding student’s information

• Actually, id number is not the real ID of the student

• The favorites were stored as integer

Page 23: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Index arrayIndex array• Index array, we also use the index array

• Advantages:

(a) just swap the index when process a piece of information

(b) protect the original data for the reuse

Page 24: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Length of the Index Length of the Index ArrayArray

• Let N = number of the students• Let M = the number of the teams• Let IA = index array• Then IA.Length = int (N/M) *M• If there are 18 students, and we will divide them into 4 groups, then the length of the index array should be 20.

Page 25: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

DifferencesDifferences• The length of the index array may be not the same as the number of the students• IndexArray.Length >= S_R.Length

Page 26: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Processing of IAProcessing of IA• Our grouping just operate on the IA,

S_R (student records) is just used to store the information

Page 27: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Processing of IAProcessing of IA• A count (integer) is used to divide

the IA into two parts: used and unused

• When a new member was selected, it’s index will be moved to last position of the unused part, then the count will decrease one unit

Page 28: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

THL LJQ UNWFZH Yedda …… ZDF YYYERICWalter

Index i Counter

usedSUN

Page 29: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

THL SUN UNWFZH Yedda …… ZDF YYYERICWalter

Index i Counter

usedLJQ

Page 30: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

SearchingSearching

Page 31: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

SearchingSearching

Page 32: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

How to get the information How to get the information of a groupof a group

ID1 ID2 ID3 ID6 ID8 ID5ID4ID7ID9ID10ID11ID12

Page 33: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Special case 1Special case 1• If N/M == integer, it is the best case

• Else, the length of the IA will be longer than the length of the S_R

• The processing will be a little different at the end

Page 34: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

SwappingSwapping

Page 35: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Member CounterIndex ( i )

Solution of the special Solution of the special case 1case 1

• 10 students

ID1 ID2 ID9ID3 ID10 ID6 ID8 ID5ID4ID7ID12ID11

Page 36: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Special case 2Special case 2• At the beginning of the grouping, we

will choose the leaders by chance.

• If one leader’s three choices are the leaders either, then it will choose the leaders again

Page 37: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ImplementationImplementation

Page 38: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ImplementationImplementation

• Show our program:

Page 39: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Part 3Part 3

ConclusionConclusion

Page 40: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ConclusionConclusion• Both of two methods are base on the

index array

• Advantages:

a) Reusable

b) Efficient

c) Informational

Page 41: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ComparisonComparison• Two versions

1. Pointer version (A4’s algorithm)

2. Array version (Our algorithm)

Page 42: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ComparisonComparison• Comparison

a)It’s faster and easier to get the information of a group by using pointer

b)Easy to add a new member or delete a wrong record by using pointer

c)Pointer version have to use two pointer operations when a member is added into a group

Page 43: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ComparisonComparisond) Array version have to do some

comparison when it want to get the information of a group

e) Array version use less space

Page 44: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Space ComparisonSpace Comparison • Pointer version: each element has to

contain pointer, it meant that the pointer version must spend more space than the array version

• Array Version: It has the best and the worst caseBest case: N / M == Integer Worst case: (N – 1)/ M == Integer

Page 45: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

Best & Worst CaseBest & Worst Case• Array Version:

Best Case: Each group has the same number of member

Worst Case: There are one student more

• Pointer Version:There are not best and worst case in the

pointer version

Page 46: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ConclusionConclusion • Actually, both the two versions are

efficient

• Running time are both O(N)

• Their have their own advantages and disadvantages

Page 47: University of Macau Faculty of Science and Technology Programming Languages Architecture SFTW 241 spring 2004 Class B Group 3

ConclusionConclusion • What we done ?