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

Slides:



Advertisements
Similar presentations
Data Structures Static and Dynamic.
Advertisements

Hashing.
Searching for Data Relationship between searching and sorting Simple linear searching Linear searching of sorted data Searching for string or numeric data.
MATH 224 – Discrete Mathematics
Folk/Zoellick/Riccardi, File Structures 1 Objectives: To get familiar with: Data compression Storage management Internal sorting and binary search Chapter.
File Processing - Organizing file for Performance MVNC1 Organizing Files for Performance Chapter 6 Jim Skon.
HST 952 Computing for Biomedical Scientists Lecture 9.
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Hash Tables1 Part E Hash Tables  
CS 106 Introduction to Computer Science I 03 / 03 / 2008 Instructor: Michael Eckmann.
Hash Tables1 Part E Hash Tables  
CS 106 Introduction to Computer Science I 03 / 08 / 2010 Instructor: Michael Eckmann.
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Lecture 10: Search Structures and Hashing
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Yet More Array Practice Lecture 24, Mon Mar
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
Chapter 7 Indexing Objectives: To get familiar with: Indexing
CSE 326: Data Structures Binomial Queues Ben Lerner Summer 2007.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Chapter 16 Stacks and Queues Saurav Karmakar Spring 2007.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
Lecture No.01 Data Structures Dr. Sohail Aslam
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Final Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
CSC 205 Java Programming II Algorithm Efficiency.
Week 3 – Wednesday.  What did we talk about last time?  ADTs  List implementation with a dynamic array.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
WEEK 1 Hashing CE222 Dr. Senem Kumova Metin
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
SFTW241 PROGRAMMING LANGUAGES ARCHITECTURE I Leader : Peter Wong Secretary : Su Project Tracker : Jesse Web Admin : Nelson Liaison : Jacky.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
SFTW241 Programming Languages Architecture I University of Macau Faculty of Science and Technology Computer and Information Science Year2 Class A Group.
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
Data Structure and Algorithms
1 Linked Lists Assignment What about assignment? –Suppose you have linked lists: List lst1, lst2; lst1.push_front( 35 ); lst1.push_front( 18 ); lst2.push_front(
Data Structures Arrays and Lists Part 2 More List Operations.
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
© 2006 Pearson Addison-Wesley. All rights reserved15 A-1 Chapter 15 External Methods.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
LINKED LISTS.
Lists and Sorting Algorithms
Hash table CSC317 We have elements with key and satellite data
A Closer Look at Instruction Set Architectures
LEARNING OBJECTIVES O(1), O(N) and O(LogN) access times. Hashing:
Hash tables Hash table: a list of some fixed size, that positions elements according to an algorithm called a hash function … hash function h(element)
CO 303 Algorithm Analysis And Design Quicksort
Files Management – The interfacing
Presentation transcript:

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

SFTW241 Programming Language Architecture Grouping Method Analysis by Program Presentation

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 1 A4 ’ s initial idea

A4 ’ 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 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 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 idea …… captain …… captain …… captain …… captain 0… …

A4 ’ 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 idea THLYeddaUNWFZHLJQSUNZDFYYYEricWalter…… EricZDFYYYWalter Choose = 0

A4 ’ 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 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

Improvement In the presentation between us and group A4, we got lots of good suggestions, and we also got some ideas from their algorithm.

Idea & 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 2 F inal Version of B3

Suggestion Analysis I think our program should contain the following two advantages: (a)Efficient (b)Reusable (c)Informational

Reusable 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.

Efficient 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

Informational Easy to get the information of a team: the number of the member; identity of the member

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

Unit Student Unit Student ID Student Name First Choice Second Choice Third Choice

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 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 Array 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.

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

Processing of IA Our grouping just operate on the IA, S_R (student records) is just used to store the information

Processing 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

THLLJQUNWFZHYedda…… ZDFYYYERICWalter Index i Counter used SUN

THLSUNUNWFZHYedda…… ZDFYYYERICWalter Index iCounter used LJQ

Searching

Searching

How to get the information of a group ID1ID2ID3ID6ID8ID5ID4ID7ID9ID10ID11ID12

Special 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

Swapping

Member CounterIndex ( i ) Solution of the special case 1 10 students ID1ID2ID9ID3ID10ID6ID8ID5ID4ID7ID12ID11

Special 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

Implementation

Implementation Show our program:

Part 3 Conclusion

Conclusion Both of two methods are base on the index array Advantages: a)Reusable b)Efficient c)Informational

Comparison Two versions 1.Pointer version (A4 ’ s algorithm) 2.Array version (Our algorithm)

Comparison 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

Comparison d) Array version have to do some comparison when it want to get the information of a group e) Array version use less space

Space 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 case  Best case: N / M == Integer  Worst case: (N – 1)/ M == Integer

Best & 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

Conclusion Actually, both the two versions are efficient Running time are both O(N) Their have their own advantages and disadvantages

Conclusion What we done ?