Thursday, October 3, 2013

Unix : Memory Managment

Based on Notes made by Sharon Francis, Steffi Devasia, Remi Rajan,Yashaswi Alva

Modified by : Jibrael Jos

  • Primary memory is a precious resource that frequently cannot contain all active processes in the system.
  • The memory management system decides which processes should reside (at least partially) in main memory.
  • It monitors the amount of available primary memory and may periodically write processes to a secondary device called the swap device to provide more space in primary memory.
  • At a later time, the kernel reads the data from swap device back to main memory.
UNIX systems transfers’ entire processes between Primary memory and the swap device, but does not transfer parts of a process independently, except for shared text. Such a memory management policy is called swapping.
Swapping The swap device is a block device in a configurable section of a disk.
Space allocated for files is used statically, since it’ll exist for long time. Allocation of space on swap device is transitory, depending on the pattern of process scheduling.
Kernel allocates contiguous space on the swap device without fragmentation.
The kernel maintains free space for file system in a linked list of free blocks, accessible from the file system super block.
It maintains free space of the swap device in an in-core table, called map.
The kernel treats each unit of the swap map as group of disk blocks.
As kernel allocates and frees resources, it updates the map accordingly.
A map is an array where each entry consists of an address of an allocable resource and the number of resource units available there.
A map initially consists of one entry that indicates the address and the total number of resources.
Algorithm malloc(refer page 273)
Input:address_of_map,number_of_unit
Output: address if successful. 0,

Swapping Process Out   
    Kernel swaps a process out when it needs space in memory, which might result from any of the following:
  • The fork system call must allocate space for a child process.
  • The brk system call increases the size of process, when a process becomes larger by the natural growth of its stack.
  • The kernel wants to free space in memory for processes it had previously swapped out and should now swap in.
  • The kernel must gather the page addresses of data at primary memory to be swapped out.
  • Kernel copies the physical memory assigned to a process to the allocated space on the swap device.
  • The mapping between physical memory and swap device is kept in page table entry.
Fork Swap    fork() is a system call to create a child process. When the parent process calls fork() system call, the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. When the memory will be available the child process will be swapped into the main memory.

Expansion Swap
If a process requires more memory it reserves enough space on the swap device to contain the memory space of the process, including the newly requested space
Then it adjust the address translation mapping of the process
Finally, it swaps the process out on newly allocated space in swapping device
When the process swaps the process into memory, it will allocate physical memory according to new address translation map
Swapping Process In 
Swapper: - The only process that swaps processes in from swap device and swaps processes out if it needs space in main memory.
Sleep if there is no work for it to do or if it is unable to do any work.
Executes only in kernel mode.
Uses internal kernel functions to do swapping.

Algorithm swapper

Input and output : none
{
Loop

    For(checks all ready to run but swapped out processes)
        Select the swapped out longest process;
    If (no such process)
    {
        Sleep until a process on swap device wakes up;
        Goto loop;
    }

    If(enough room in main memory for process)
    {
        Swap process in and goto loop;
    }
    For( all process loaded in main memory, not zombie and not locked in    memory)
{
    If(Sleeping process)
        Choose process with highest value for priority + residence time;
    Else
        Choose process with highest value for residence time + nice;
}
If (chosen process is not sleeping or requirements not satisfied)
    Sleep till a process is swapped in;
Else
    Swap out process;
Goto loop;

Note:
Clock handler - Measures the time that each process has been in core or swapped out.
Zombie processes and process that are locked in memory do not get swapped out.
Kernel swaps out sleeping process rather than those “ready to run because of greater chance of “ready to run” processes for getting scheduled.

Flaws of the Algo to choose a process to Swap out
  • It may swap out a process that does not provide enough memory for incoming process.
  • If swapper sleeps as it could not find enough memory, it searches again for a process to swap in although it had chosen one. 
  • If the Swapper chooses a “ready to run” process to swap out, it is possible that the process had not executed since it was previously swapped in.
  • If swapper attempts to swap out a process but cannot find space on swap device, a system deadlock may arise if several conditions are met.

Demand paging 
Locality- Process tends to execute in small portions of their text space.
Working set – Set of pages that the process has referenced in last n memory references, where n is the window.
Page default – When a process accesses a page that is not part of working set.

Data structures for demand paging (refer diagram in page 288)
  • Page table entry
  • Disk block descriptors
  • Page frame data table
  • Swap use table
Page Table Entry contains the physical address of page and the following bits:-
  • Valid: whether the page content legal
  • Reference: whether the page is referenced  recently
  • Modify: whether the page content is modified
  • copy on write: kernel must create a new copy when a process modifies its content
  • Age: Age of the page
  • Protection: Read/ write permission

The pfdata table describes each page of physical memory. Fields of an entry are       
  • Page state.
  • No. of processes that reference the page.
  • Logical device and block number.
  • Pointers to other pfdata table entries.

The swap use table contains an entry for every page on swap device

Fork in paging system
  • The kernel of a swapping system makes a physical copy of the parent’s address space.
  • On the paging system, the kernel avoids copying the page by manipulating the region tables, page table entries and increments the region reference count of shared regions.
  • The kernel allocates a new region table entry and page table for data and stack regions and examines each parent page table entry.
  • If page is valid, increments the reference countindicating the number of processes that share the page. If page exists on a swap device, it increments the swap use table reference count.
  • The page can be referenced through both regions, which share a page until a process writes to it. The kernel copies it so that each region has a private version.
  • If either process writes the page, it incurs a protection fault and in handling the fault, the kernel makes a new copy of the page for the faulting process. The physical copy is deferred until a process needs it.
  • In BSD system
  • The fork system call makes a physical copy of the pages of the parent process.
  • It also contains the vfork system call, which assumes that a child process will immediately invoke exec on return from the vfork call.
  •  Vfork does not copy page tables, hence faster than System V implementation.
  • Child process executes in the same physical address space as the parent process and can thus overwrite the parent’s date and stack.
Exec in paging systemOn a demand paged system, however the executable file may be too large to fit in main memory. The kernel does not preassign memory to the executable file but ‘faults’ it in, assigning memory as needed.
First assigns the page tables and disk block descriptors for the executable file, marking the page table entries “demand fill” or “demand zero’.
The fault handler notes whether the page is “demand fill”, meaning its contents will immediately be overwritten with the contents of the executable file so it need not be cleared, or that it is “demand zero,” meaning that its contents should be cleared.
If the process cannot fit into memory, the page stealer process periodically swaps pages from memory, making for the incoming file.
A process may incur a page fault while reading each page, even though it may never access the page. The page stealer may swap pages from memory before the exec is done. To make exec more efficient, the kernel can demand page directly from the executable file.
If a process incurs a page fault during a read system call it would overwrite the fields to read the page from the file system.
To page directly from the executable file, the kernel finds all the disk block numbers of the executable file when it does the exec and attaches the list to the file inode.
The page stealer process
  • The page stealer is a kernel process that swaps out memory pages that are no longer part of the working set of a process.
  • The kernel creates the page stealer during system initialization and invokes it throughout the lifetime of the system when low on free pages. It locks a region when a process faults on a page in the region.
  • There are two paging states for a page in memory: the page is aging and is not yet eligible for swapping or the page is eligible for swapping and is available for reassignment to other virtual pages.
  • The first state indicates that a process recently accessed the page, and the page is in its working set and assigns a reference bit whenever a page is referenced.
  • When the reference number exceeds a threshold value, the kernel puts the page into the second state ready to be swapped.
  • If two or more processes share a region, they update the reference bits of the same set of page table entries. If a page is part of the working set of any process, it remains in memory; if it is not part of the working set of any process, it is eligible for swapping.
  • When the page stealer decides to swap out a page, it considers whether a copy of the page is on a swap device. There are three possibilities:
  • If no copy of the page is on the swap device, the kernel schedules the page for swapping: the page stealer places the page on a list of pages to be swapped out and continues. When the list of pages to be swapped reaches a limit, the kernel writes the pages to the swap device.
  • If a copy of the page is already on the swap device and no process has modified its in core contents. The kernel clears the in core page table entry, decrements the reference count and puts the entry on free list for future allocation.
  • If a copy of the page is on a swap device but a process has modified its contents in memory, the kernel schedules the page for swapping and frees the space it currently occupies on the swap device.

Page faults A page fault occurs when a process accesses a virtual page for which there is no page table entry(PTE) in the page table or whose PTE in some way prohibits the access, e.g., because the page is not present or because the access is in conflict with the access rights of the page.
Two types
  • Validity faults
  • Protection faults
When the fault handlers execute there is an I/O execution happening i.e., reading a page from disk to memory and hence fault handlers go to sleep which is an exception from other interrupt handlers.
Validity fault handler
Demand paging has a data structure called page table entry which has a valid bit.
If a process referring a page in the main memory whose valid bit is not set i.e., 0, it results in validity fault.
 The valid bit is not set for those pages:
that are outside the virtual address space of a process
that are the part of the virtual address space of the process but no physical address is assigned to it.



Algorithm vfault(refer page 299)

Input: address where process faulted
Output: none

STEPS :-
Finds PTE and  Disk block descriptor(DBD)
Locks the region
Finds if record is in disk block
If no exit by sending Segmentation violation signal
If yes allocate a page and initiate read process
Checks if page in cache
If yes update PTE
If contents not valid sleep till it becomes valid
If no assign new page and update PTE
Set the valid bit ,unlock the region   

The page that caused faults can be in one of the 5 states:-
On a swap device and not in memory It’s been swapped out of memory
Disk block descriptor contains the block info where the page is stored
Updates page table entry if not in cache to point it to the page about to be read
Initiates read operation
Faulting process sleeps until the completion of I/O
On the free page list in memory Page is swapped out but not been reassigned
Block number found in the disk block descriptor
Reassigns page table entry to point to the page just found
Remove from free list
In an executable fileExists on the executable file and not on swapping device
examines disk block descriptor, finds logical block number in the file that contains page, finds the inode
using disk block number it reads the page into memory
Marked “demand zero”kernel allocates free page in memory
updates the appropriate page table entry
it clears the  page to zero and also “demand zero” flags marked “demand zero”
Marked “demand fill”kernel allocates free page in memory
updates the appropriate page table entry
it clears the  “demand fill” flags

Validity fault handler concludes by setting validity bit of the page and clearing the modify bit
At the end checks for the process priority since it was put to sleep and also for the signals and returns to user mode

Protection fault handler
Protection fault refers to the process accessing the pages, which do not have the access permission. A process also incur the protection fault when it attempts to write a page whose copy on write bit was set during the fork() system call.

Algorithm pfault(refer page 304)Input: address where process faulted
Output: none

Steps:-Finds appropriate region, page table entry, disk block descriptor
Lock the region
If invalid page
    Unlock the region and quit
If copy on write bit not set
    Unlock the region and quit
If copy on write bit is set and if page is shared by another process i.e. page frame reference count is >1
    Allocate a new page and copy the contents of the old page to it
    Update page table entry with new page number
    Decrement the reference count of old page frame data entry
If copy on write bit is set and if it’s not shared by any other process/* when no process is using it*/
    If copy of page exists on swap device
Free space on swap disk wen count drops to 0
    If page is on page hash queue
        Remove from the queue
Set modify bit, Clear copy on write bit in page table entry
unlock the region

If the page is invalid the fault handler returns immediately and the process will incur a validity fault.
Validity fault is handled but the process will incur the protection fault again
At the end checks for the process priority since it was put to sleep and also for the signals and returns to user mode

Wednesday, October 2, 2013

Unix Algo Part 2

By Khusboo Breja (M.Sc 2013)


Algo  Chapter             Input  Output
getblk(to get a block) 3 File System number locked buffer that can now be used for block
    block number  
brelse(to release a block) 3 locked buffer none
bread(Agorithm to read a block) 3 file system block number buffer containing data
breada(Algorith to read a block ahead) 3 (1)file system block number containing for immediate read buffer containing data for immediate read
    (2)file system block number for asynchronous read  
bwrite(to write a block) 3 buffer none
iget( for allocation of In-core Inodes  4 file system inode number locked inode
iput(to release an Inode) 4 pointer to in-core inode none
bmap(to convert byte offset to block number in file system) 4 (1)inode (1)block number in file system
    (2)byte offset (2)byte offset into block
      (3)bytes of I/O in block
      (4)read ahead block number
namei(to convert path name to an Inode) 4 path name locked inode
ialloc( for assigning new Inodes) 4 file  system locked inode
ifree( for freeing Inode) 4 file system inode number none
alloc( for allocating disk blocks) 4 file system number buffer for new block


Unix Algo Part 1

Listed by Anu Varghese (M.Sc 2013)

In chapter 3 there are mainly 5 types of algorithm. The algorithms describe below.      
1. Buffer Allocation:- The algorithms for reading and writing disk blocks use the algorithm getblk to allocate buffers from the pool.      
2. releasing a buffer :- The kernel may read data from the disk to the buffer and manipulate it or write data to the buffer and possibly to the disk.      
3. Reading a Disk Block :- The disk driver notifies the disk controller hardware that it wants to read data, and the disk controller later transmits the data to the buffer.      
4. Block Read Ahead :- The kernel checks if the first block is in the cache and, if it is not there, invokes the disk driver to read that block.       
5. writing a disk block :- The kernel informs the disk driver that it has a buffer whose contents should be output , and the disk driver schedules the block for I/O.      
      
    In chapter 4 there are mainly 7 types of algorithms. The algorithms describe below.  
1. Allocation of In-Core Inodes :- The kernel maps the device number and inode number into a hash queue and searches the queue for the inode.      
2. Releasing an Inode:- When the kernel releases an inode , it decrements its in-core reference count.      
3. Conversion of Byte Offset to Block Number in File System:- It gives the algorithm bmap for converting a file byte offset into a physical disk block.      
4. Conversion of a Path Name to an Inode :- The kernel works internally with inodes rather than with path names, it converts the path names to inodes to access files.      
5. Assigning New Inodes:- Whenever the kernel assigns a disk inode, it decrements the free inode count recorded in the super block.      
6. Freeing Inode:- This algorithm much simpler after incrementing the total number of available inodes in the file system, the kernel checks the lock on the super block.      
7. Allocating Disk Block:- The algorithm free for freeing a block is the reverse of the one for allocating a block.      
      
    In chapter 5 there are mainly 12 types of algorithms. The algorithms describe below.  
1. Opening a File:- The kernel searches a parameter namei it checks permissions for opening the file after it finds the in-core inode and allocates an entry in the file table for the open file.      
2. Reading a File:- The algorithm read for reading a regular a regular file.      
3. Creating a File:- The create system call proceeds according to the same algorithm as the open system call.      
4. Making  New Node:-  This algorithm mknod for making a new node.      
5. Changing Current Directory:- This algorithm chdir changes the current directory of a process.      
6. Creation of Pipes:- The kernel assigns an inode for a pipe from a file system designated the pipe device using algorithm ialloc.      
7. Mounting a File System:- The kernel only allows processes owned by a superuser to mount or umount file systems.      
8. Revised Accessing an Inode:- For the case of crossing the mount point from the mounted-on file system to the mounted file system,consider the revised iget.      
9. Revised Parsing a File Name:- After finding the inode number for a path name component in a directory, the kernel checks if the inode number is the root inode of a file system.      
10. Unmounting a File System:- When unmounting a file system ,the kernel accesses the inode of the device to be unmounted , retrieves the device number for the special file.      
11. Linking Files:- The kernel first locates the inode for the source file using algorithm namei, increments its link count, updates the disk copy of the inode, and unlocks the inode.      
12. Unlinking a File:- The kernel first uses a variation of algorithm namei to find the file that it must unlink.      

Unix : System Call for Time

I : stime    allows superuser to set a global kernel variable to a value that gives current time                   
                       
usage    stime(pvalue)                        where pvalue points to a long integer that gives seconds from Jan 1 1970                   
                       
important    clock interrupt handler increments the the kernal variable once a second                   
                       
II : time    retrievs the time as set by stime                   
                       
usage     time(tloc)                        where tloc points to a location in the user process for the return value                   
                       
important    commands such as date use time to determine current time                   


III : times    retrieves the cumulative times that the calling process spent executing in                        
        user mode                   
        kernel mode                   
    retrieves the cumulative times that all zombie children had executes in                         
        user mode                   
        kernel mode                   
                           
usage    times(tbuffer)                       
                           
    struct tms*buffer;        struct tms {    time_t    tms_utime    // user time   
                time_t    tms_stime    // kernel time   
                time_t    tms_cutime    // children user time   
                time_t    tms_cstime    // children kernel time   
                           
    times returns the elapsed time “from an arbitary point in the past”                       
    (usually the boot time)                       
IV : Alarm is used to set an alarm to remind the process of something while it is working on somethings else
Sleep on the other hand also wakes up a process but in that case process is not active. In Alarm system call the process can continue to run     
Example :     42      signal(SIGALRM,wakeup);
                      43      alarm(10);

Example for times:

     18    pt1=times(pb1);   
     19    for(i=0;i less than 3; i++)       
     20       if(fork()==0)
     21          child(i);
     22       
     23
     24    for(i=0;i is less than 3 ;i ++) // why do we need this loop ??
     25           wait((int *)0);
     26    pt2=times(pb2);
     27
     28    printf("\n Parent real %ld user %ld sys %ld",pt2-pt1,
     29                     pb2.tms_utime-pb1.tms_utime,
     30                     pb2.tms_stime-pb1.tms_stime);
     31    printf("\n Parent child user %ld sys %ld",
     32                     pb2.tms_cutime-pb1.tms_cutime,
     33                     pb2.tms_cstime-pb1.tms_cstime);

Function of Clock Interrupt Handler                           
    restart the clock                    c   
    schedule invocation of internal kernel functions    f   
    provide execution profiling                p   
    gather system and process accounting stats        s   
    keep track of time                    t   
    send alarm signals to process on request        a   
    periodically wakeup the swapper process            s   
    control the process scheduling                p   
                           
                    p2as2t    cf   
                    past    coffee   

Code Guru: Gateways 2013

Very tight finish for the first 5 places
 

Parth Vora (I)
Samik Banik(II)
Udhay Raj (III) 

Rank 4-10 in order 

Vivian Ambrose,
Tenzin Chemi,
Talat Ahmed ,
Palak Goyal,
Pramod Das, 
Dharmappa Immannavar,
Bharat Lakkur

Congratulations !!!!


      World War Z

50 by 50 array where 
0 is empty 
1 is soldier
2 is Bullet
3 is Mine

       Level 1 Viewer   
               (Show 0 as space and soldiers as #, bullet as | and mine as * )
       Level 2 Set Army (x1,y1,x2,y2)  
       Level 3 March Past ( make a group of soldiers march in different directions N S E W)
       Level 4 Silver Bullet(when soldiers walk into it they die and bullet can kill umlimited no of soldiers)
       Level 5 Land Mine   (when soldiers step on it all around die)
       Level 6 Moving Bouncing Bullet
       Level 7 Armies, Bullets,Mines (support multiple battalions, mines and bullets)

Inter Process Communication : Part I

If there is one chapter in Design of Unix Operating System (Maurice Bach) you should read then it would be the chapter on IPC.

First time I taught this paper, I hardly understood it well ... second time around I did the coding myself and found some of the topics very interesting. Third time around you realise the clarity in the previous year was quite disconcerting :-)

Ummmm and do I expect students to understand it in first go .. well not really ... but then students are smarter than teachers !!!

I had studied the Dining Philosphers Problem and Locking Problems like "dirty read". I had used applications like OS, Databases, Compilers and Debuggers. I had worked 6 years in Unix Enviorment ....... but alas my concepts were still a bit weak. That is why teaching is such a good thing ... you learn in the process even if the students don't :-)

Some cool things Unix can do :

fork : A process can clone itself !! A ditto copy .... if recursion was difficult to teach then this in a league in itself.

Coding is easy : a=fork(); if (a==0) {// child code} else {// parent code}

but Understanding is another matter ..... what happens in this code
      for(i=0;i<5 a="=0)" ello="" else="" i="" if="" p="" printf="">
       What is the output you expect? How many Hi and Hello and in what order ?

exec: A process is overwritten by an exe in other words "memory is overlayed!!". In the following example first a fork is called (the current process is cloned) .... and then memory is overlayed in the child (using exec) !!

Lets say this app is called forkapp.exe then if we did ps command on another terminal

when code was going to run line 7: you will see two forkapp.exe due to cloning

but after line 7 : you will see 1 forkapp.exe and 1 date due to overlaying

      6    if(fork() == 0)
      7    {    execl("/bin/date","date",0);
      8         printf("Execl failed");
      9         return;
     10    }
           When will line 8 be executed? Why don't we check the return value of execl
        You have seen recursion, where a function calls a function .. what happens here .. any idea

        execl(argv[0],argv[0],0);

semaphore:
      The difficult thing in locking is that we can write a code like

      if (lock_flg==false)
      {      lock_flg=true
            // code to use some resource
       }
      but to implement locking in a multiple process system the risk is that a process p1 after calling the if line and before it calls the assignment line the kernel may give a chance to somebody else (process p2)

     This other process p2 also happens to be executing the same code and he may also check the flag and then set the flag not knowing that process p1 has already intending to lock the same resource.

    Very soon chaos will result with both process using the same resource without realizing that somebody else is also using the same resource (say a printer !!)

      
     Djikstra came up with a clean solution called semaphore (read on wiki)

      semget : create or get an existing semaphore
      semctl : to control semaphore, you can SETALL GETALL IPC_RMID etc
      semop : To increment or decrement a semaphore

We can create an array of semaphore or just a single one and that is a very cool thing because not only we solve Locking problem we also solve the dreadful "deadlock" problem. How Exactly .... you tell me ?
     
 Following Code is the menu:

     22    while (ch!=0)
     23    {
     24       printf("\n 1. Create Semaphore if does not exist");
     25       printf("\n 2. Set All to 1         ");
     26       printf("\n 3. Get All ");
     27       printf("\n 4. P Operation / Decrement / Lock");
     28       printf("\n 5. V Operation / Increment / Unlock");
     29       printf("\n 6. Clean Up");
     30       printf("\n 0. Exit ");
     31       printf("\n\t-----------------------");
     32       scanf("%d",&ch);


      We will create semaphore using semget

     34    if(ch == 1)
     35    {
     36       semid=semget(0X22,2,IPC_CREAT|0777);     37
     38       printf("\n\t Sem Id is %d",semid);
     39       printf("\n setting semaphore");
     40    }

        Here we are creating an array of 2 semaphore

     To set values in the semaphore we use semctl 
     41    if(ch == 2)
     42    {
     43       rval=semctl(semid, 2 , SETALL, r);     44
     45       printf("\n semaphore val is %d %d rval is %d",r[0],r[1],rval);
     46       printf("\n set semaphore");
     47    }
        Q: What is r ?
          To get the values of semaphore we again use semctl
     48    if(ch == 3) // check what is status
     49    {
     50       semid=semget(0X22,2,0777);
     51       printf("\n getting semaphore");
     52       rval=semctl(semid, 2 , GETALL, o);
   
53       printf("\n semaphore val is %d %d rval is %d",o[0],o[1],rval);
     54    }

        Q: What is o ?

         To lock we use semop with op set as -1 (line 61)
     55    if(ch == 4) // try to take lock
     56    {
     57       semid=semget(0X22,2,0777);
     58       printf("\n\t If part Sem Id is %d",semid);
     59       printf("\n Process Before Semaphore %d ... Trying to get lock",semid);
     60       sop.sem_num=0; // set the first semaphore
     61       sop.sem_op=-1; // lock
     62       sop.sem_flg=SEM_UNDO;
     63       a = semop(semid , &sop , 1);
     64
     65       printf("\n Process semop %d ",a);
     66       printf("\n Process in critical section");
     67       printf("\n Process Locked ");
     68     }

         To unlock we use semop again but this time we set op to 1
     69    if(ch == 5) // Unlock
     70    {
     71       semid=semget(0X22,2,0777);
     72       sop.sem_num=0; // set the first semaphore
     73       sop.sem_op=1; // unlock
     74       sop.sem_flg=SEM_UNDO;
     75       a = semop(semid , &sop , 1);
     76
     77       printf("\n Process Over is %d ",a);
     78       getchar();
     79    }

          To remove we use semctl again
     80    if(ch == 6) // clean Up
     81    {
     82       semid=semget(0X22,2,0777);
     83       printf("\n getting semaphore");
     84       rval=semctl(semid, 2 , IPC_RMID, 0);
     85    }
     Check the man pages of your installation but you would need to include some header files like the following
       2 #include
      3 #include 
 

      And would also need to declare a few things like
     10    short r[2];
     11    short o[2];
     12    struct sembuf sop;

 
Hope you find the blog useful. All the best ....
      
 In part II I will touch on Message Queues and ptrace


Further Reading

Wiki Semaphore
Dining Philosphers Problem
 

Wednesday, February 6, 2013

Code Guru : Revelation 2013


This time the event saw around 30-40 of the best coders in PG Courses of Computer Science. Winners/Code Gurus were
I. Benjamin Varghese
II. Muffadal Kagda
III. Talat Ahmed


Remaining Top 10 are:
4. Parth Vora – II MCA
5. Samanjana Baidya – IV MCA
6. Udhayaraj R – II MSc
7. Ankita Goyal – IV MCA
8. Vinnas Kuttery – IV MCA
9. Palak Goyal – IV MCA
10. Vivian Ambrose – IV MCA

Congrats, it is not easy to code under pressure when I keep announcing time left and who is leading ... Congratulations to Top 10
Time Limit : 50 minutes
Compiler: Of your choice Help/Textbook/Online all allowed
Questions :



Create a 10 by 10 integer array, 0 Means empty,
Levels
1. Grow Tree (0 means nothing 1 means tree trunk)
2. Grow Tree with leaves (2 means leaf)
3. Tree Spilts after 3 levels
4. Tree further splits after every 3 levels
5. Grow 2 trees at random position
6. Tree has a full canopy of leaves
7. One tree grows under the tree as much as it can but preference for bigger tree
9. Grow a Random Forest of trees