?
Solved

replacement selection algorithim

Posted on 2005-05-03
20
Medium Priority
?
459 Views
Last Modified: 2010-04-02

 i need program for REPLACEMENT SELECTION ALGORITHIM FOR VARIABLE LENGTH RECORD
0
Comment
Question by:pad_anu
  • 6
  • 5
  • 2
  • +2
16 Comments
 
LVL 4

Expert Comment

by:smpoojary
ID: 13916286
Explain what it is doing.
0
 

Author Comment

by:pad_anu
ID: 13916307
kindly help me for writing a program for replacement selection for variable length record
0
 
LVL 4

Expert Comment

by:smpoojary
ID: 13916328
I have forgotten that algorithm. Can you explain that algorithm. May be it is coming in O.S. Then I will help you to write program for that.
-Mahesh
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Accepted Solution

by:
Kent Olsen earned 1000 total points
ID: 13916678
Hi pad_anu,

Clearly, you've asked for help with homework.  The rules of the board are quite specific about the kinds of help that we can provide.  In general, we can assist you with YOUR code, or we can provide clues and examples, but the work must be yours.

To offer any help, we'll need to know more about your assignment.  "REPLACEMENT SELECTION ALGORITHIM FOR VARIABLE LENGTH RECORD" covers a lot of ground.

If your variable length records are strings, you can simply strcpy() the new one over the old one, as long as the buffer doesn't overflow.  Better yet is to use pointers to strings.  Then you simply change the pointer value.

The same is true if you're dealing with structures.  A pointer to a structure is pretty simple.  To change the target object, you can modify the object directly, or change the pointer to contain the address of the new object.

Then again, the data might be buffered.  You've got a fixed length buffer (perhaps 4K) with some number of structures contained within the buffer.  Most DBMS engines work this way.  You'll use a combination of techniques here.

And of course, you might simply have a linked list of objects in a large buffer.  This is similar to buffered approach above where you'll search for objects and/or free space for new objects.

Or you could be dealing with a tree.  If so, you'll need a set of recursive routines to manage the tree.


Object selection techniques vary greatly with the underlying structure.  If you want us to help you, you'll need to tell us more that "i need a program".


Kent
0
 
LVL 4

Expert Comment

by:smpoojary
ID: 13916938
//This is a simulation
//Following is the algorithm for handling 10 processes in FIFO manner
//convert it for your purpose
step 1: declare int buff[3]; //Buffer has 3 blocks
step 2: think you are processing 10 processes (read its pid as a number).
step 3: counter = 0;
step 4: while(i<10)
      {
            4.1:scanf("%d",&pid);
            4.2:buff[counter % 3] = pid;
            4.3://Go for processing this pid process
            4.4:++counter;
       }
step 5: stop

0
 

Author Comment

by:pad_anu
ID: 13933235
sir
         I NEED A PROGRAM THAT WORKS FOR REPLACEMENT SELECTION ALGORITHIM FOR VARIABLE LENGTH RECORD.

           IN This program i  have do external sortin, data structure can be anything.
pls do help me sir
0
 

Author Comment

by:pad_anu
ID: 13933250
i am doing project. classical replacement selection algorithim that works for fixed length record is available in net. but i neeed the program that works for variable length record.

i have referred IEEE paper- EXTERNAL SORTING:RUN FORMATION-REVISTED.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 13934542

Hi pad_anu,

I'm refer you back to my original statement where I told you that I can not do your homework for you.  Then I suggest you go back and reread the membership agreement that you promised to honor when you signed up at EE.

If you want help, ask specific questions.

If you want a program, hire a consultant.


0
 
LVL 4

Expert Comment

by:smpoojary
ID: 13942434
First read the topic thoroughly in the text book and tell us the algorithm  step by step. Then only we will able to guide you to how to write program for that algorithm.
-Mahesh
0
 

Author Comment

by:pad_anu
ID: 13949586
sir,
         External sorting is done in two phase. 1.run formation 2.merge phase.
run formation can be done by two algorithim. 1.load sort store -algorithim, 2. replacement selection algorithim.

               i am using replacment selection algorithim. in this sorting is to bre done based on some key. so a certain number of records is placed in memory. the record which hass the smallest key value is found and written in to output buffer.in that place the next record from the input file is replaced. and the key value of the record which is placed in output buffer is compared with the key value of the newly placed record.if the value of the key value of the new record is less the one that is placed out,then the new recorded is marked for next run. like this it continues and the run files are formed.

after run files are formed then by polyphase it is merged into a single  sorted output file.

0
 
LVL 4

Expert Comment

by:smpoojary
ID: 13958316
hello,
Iread the explanation you sent me about the sorting, very frankly I could not comprehend most of it,I got confused with the fact that you were comparing the key you pushed to the output buffer with the key you put in the place of the key you pushed to the putput buffer, it would be great if you could clarify this point.
0
 
LVL 20

Assisted Solution

by:jmcg
jmcg earned 1000 total points
ID: 13959337
The algorithm you describe is simple to implement for fixed-length records but becomes complicated for variable-length records because you must now manage a dynamic storage area for the records. The new record you read in will not necessarily fit in the place of the record you have just written out.

The advantage of a replacement algorithm is that it can give you longer and fewer run files that need to be merged when the input data is already partially in-order. I couldn't venture a guess as to whether this advantage is lost if the storage management becomes more complicated.

0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 13959706
The simplest way to implement a variable length record strategy using a fixed-length-record algorithm is to create a fixed-length index to the variable length file.

Like this:

Input file:

Now
Is
The
Time
For
All
Good
Men
To
Com
To
The
Aid
Of
The
Party

Make and index file containing the offsets into the variable length file for each line:

0000
0004
0007
...

Then, whenever you wish to read a record, use your fixed-length index file entry to provide you with an offset into your variable-length file.

Does this make sense? If not, please let me know.

Paul

0
 

Author Comment

by:pad_anu
ID: 14008990
for the implementation of replacement  i am using tree structure. now to an external node i need to attach a set of element in the array. the pointer pointing to the first location of the array is to be stored in one field of the external node.

             please suggest how to write the code for it
0
 
LVL 20

Expert Comment

by:jmcg
ID: 14009174
In practice, I've always found that storing the value of a pointer to an internal data structure in external storage is a mistake. Perhaps you could give more of an explanation of what you're trying to do and we could be of more help.
0
 

Author Comment

by:pad_anu
ID: 14186142
sir i couldn't gt the proper ans. so plese refund and delete my questions
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question