university of macau faculty of science and technology programming languages architecture sftw 241...
DESCRIPTION
Contents For this presentation, we have the following three parts: 1)A4 ’ s initial idea 2)The final version of B3 3)The conclusionTRANSCRIPT
University of MacauFaculty of Science and Technology
Programming Languages Architecture
SFTW 241 spring 2004Class B Group 3
SFTW241SFTW241 Programming Programming
Language Language ArchitectureArchitectureGrouping Method Grouping Method
Analysis by Program Analysis by Program PresentationPresentation
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
Part 1Part 1
A4’s initial ideaA4’s initial idea
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
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
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.
A4’s initial ideaA4’s initial idea
………………captain
………………captain
………………captain
………………captain
0 …7654321 …
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
A4’s initial ideaA4’s initial idea
THL Yedda UNWFZH LJQ SUN ZDF YYYEricWalter……
Eric ZDF YYY Walter
Choose = 0
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
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
ImprovementImprovement In the presentation between us and
group A4, we got lots of good suggestions, and we also got some ideas from their algorithm.
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
Part 2Part 2
FFinal Versioninal Versionof B3of B3
Suggestion AnalysisSuggestion Analysis• I think our program should contain
the following two advantages:
(a)Efficient
(b)Reusable
(c)Informational
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.
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
InformationalInformational• Easy to get the information of a
team: the number of the member; identity of the member
Data StructureData Structure• Data is stored as the following form: class Record{ private: int id; string name; int first, second, third; }
UnitUnit
Student Unit
Student ID Student Name First Choice Third ChoiceSecond Choice
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
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
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.
DifferencesDifferences• The length of the index array may be not the same as the number of the students• IndexArray.Length >= S_R.Length
Processing of IAProcessing of IA• Our grouping just operate on the IA,
S_R (student records) is just used to store the information
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
THL LJQ UNWFZH Yedda …… ZDF YYYERICWalter
Index i Counter
usedSUN
THL SUN UNWFZH Yedda …… ZDF YYYERICWalter
Index i Counter
usedLJQ
SearchingSearching
SearchingSearching
How to get the information How to get the information of a groupof a group
ID1 ID2 ID3 ID6 ID8 ID5ID4ID7ID9ID10ID11ID12
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
SwappingSwapping
Member CounterIndex ( i )
Solution of the special Solution of the special case 1case 1
• 10 students
ID1 ID2 ID9ID3 ID10 ID6 ID8 ID5ID4ID7ID12ID11
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
ImplementationImplementation
ImplementationImplementation
• Show our program:
Part 3Part 3
ConclusionConclusion
ConclusionConclusion• Both of two methods are base on the
index array
• Advantages:
a) Reusable
b) Efficient
c) Informational
ComparisonComparison• Two versions
1. Pointer version (A4’s algorithm)
2. Array version (Our algorithm)
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
ComparisonComparisond) Array version have to do some
comparison when it want to get the information of a group
e) Array version use less space
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
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
ConclusionConclusion • Actually, both the two versions are
efficient
• Running time are both O(N)
• Their have their own advantages and disadvantages
ConclusionConclusion • What we done ?