Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
C-LOOK Disk Scheduling Algorithm
Next article icon

C-LOOK Disk Scheduling Algorithm

Last Updated : 03 Aug, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

C-LOOK Disk Scheduling Algorithm is an enhanced version of both SCAN as well as LOOK disk scheduling algorithms. This algorithm also uses the idea of wrapping the tracks as a circular cylinder as the C-SCAN Algorithm but the seek time is better than the C-SCAN algorithm. We know that C-SCAN is used to avoid starvation and services all the requests more uniformly, the same goes for C-LOOK. 

In this algorithm, the head services request only in one direction(either left or right) until all the requests in this direction are not serviced and then jumps back to the farthest request in the other direction and services the remaining requests which gives a better uniform servicing as well as avoids wasting seek time for going till the end of the disk.

In this article, we will see given an array of disk track numbers and initial head position, our task is to find the total number of seek operations to access all the requested tracks if the C-LOOK disk scheduling algorithm is used. Also, write a program to find the seek sequence using the C-LOOK disk scheduling algorithm.

Basic Steps Involved in the C-LOOK Algorithm

  • Determine the initial position of the disk head.
  • Sort the pending disk requests in the order in which they will be serviced.
  • Scan the disk in the chosen direction, servicing requests as they are encountered.
  • When the last request in the current direction has been serviced, immediately return to the beginning of the disk and repeat the process.

Advantages of the C-LOOK Disk Scheduling Algorithm

  • It can provide better performance than the LOOK algorithm because it reduces the number of head movements required to access data on the disk.
  • It is relatively simple to implement and does not require a large amount of memory or processing power.
  • It can be efficient in terms of disk usage because it scans only the areas of the disk where data is located.

Disadvantages of the C-LOOK Disk Scheduling Algorithm

  • It may not be optimal in situations where there are large amounts of data to be read or written in one direction, as it could lead to a large number of requests being queued up in the opposite direction.
  • It may not be suitable for real-time systems where fast response times are critical, as it does not prioritize requests based on their urgency or importance.
  • It may lead to starvation of requests that are located far away from the current position of the disk head.

Algorithm of C-LOOK Disk Scheduling Algorithm

Step 1: Let the Request array represents an array storing indexes of the tracks that have been requested in ascending order of their time of arrival and the head is the position of the disk head.

Step 2: The initial direction in which the head is moving is given and it services in the same direction.

Step 3: The head services all the requests one by one in the direction it is moving.

Step 4: The head continues to move in the same direction until all the requests in this direction have been serviced.

Step 5: While moving in this direction, calculate the absolute distance of the tracks from the head.

Step 6: Increment the total seek count with this distance.

Step 7: Currently serviced track position now becomes the new head position.

Step 8: Go to step 5 until we reach the last request in this direction.

Step 9: If we reach the last request in the current direction then reverse the direction and move the head in this direction until we reach the last request that is needed to be serviced in this direction without servicing the intermediate requests.

Step 10: Reverse the direction and go to step 3 until all the requests have not been serviced.

Example: 

Input: 
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114} 
Initial head position = 50 
Direction = right (Moving from left to right) Output: 
Initial position of head: 50 
Total number of seek operations = 321 
Seek Sequence is 60, 79 , 92 , 114 , 176, 11 , 34, 41

The following chart shows the sequence in which requested tracks are serviced using C-LOOK.

Therefore, the total seek count = (60 - 50) + (79 - 60) + (92 - 79) +
(114 - 92) + (176 - 114) + (176 - 11) + (34 - 11) + (41 - 34) = 321
C-LOOK Disk Scheduling Algorithm
C-LOOK Disk Scheduling Algorithm

Implementation of C-LOOK Disk Scheduling Algorithm

The implementation of the C-LOOK algorithm is given below. The distance variable is used to store the absolute distance between the head and the current track position, disk_size is the size of the disk. Vectors left and right store all the request tracks on the left-hand side and the right-hand side of the initial head position respectively.

C++
// C++ implementation of the approach #include <bits/stdc++.h> using namespace std; int size = 8; int disk_size = 200;  // Function to perform C-LOOK on the request // array starting from the given head void CLOOK(int arr[], int head) {     int seek_count = 0;     int distance, cur_track;     vector<int> left, right;     vector<int> seek_sequence;      // Tracks on the left of the     // head will be serviced when     // once the head comes back     // to the beginning (left end)     for (int i = 0; i < size; i++) {         if (arr[i] < head)             left.push_back(arr[i]);         if (arr[i] > head)             right.push_back(arr[i]);     }      // Sorting left and right vectors     std::sort(left.begin(), left.end());     std::sort(right.begin(), right.end());      // First service the requests     // on the right side of the     // head     for (int i = 0; i < right.size(); i++) {         cur_track = right[i];          // Appending current track to seek sequence         seek_sequence.push_back(cur_track);          // Calculate absolute distance         distance = abs(cur_track - head);          // Increase the total count         seek_count += distance;          // Accessed track is now new head         head = cur_track;     }      // Once reached the right end     // jump to the last track that     // is needed to be serviced in     // left direction     seek_count += abs(head - left[0]);     head = left[0];      // Now service the requests again     // which are left     for (int i = 0; i < left.size(); i++) {         cur_track = left[i];          // Appending current track to seek sequence         seek_sequence.push_back(cur_track);          // Calculate absolute distance         distance = abs(cur_track - head);          // Increase the total count         seek_count += distance;          // Accessed track is now the new head         head = cur_track;     }      cout << "Total number of seek operations = "          << seek_count << endl;      cout << "Seek Sequence is" << endl;      for (int i = 0; i < seek_sequence.size(); i++) {         cout << seek_sequence[i] << endl;     } }  // Driver code int main() {     // Request array     int arr[size] = { 176, 79, 34, 60,                       92, 11, 41, 114 };     int head = 50;      cout << "Initial position of head: " << head << endl;      CLOOK(arr, head);      return 0; } 
Java
// Java implementation of the approach  import java.util.*;  class GFG{   static int size = 8;  static int disk_size = 200;     // Function to perform C-LOOK on the request  // array starting from the given head  public static void CLOOK(int arr[], int head)  {      int seek_count = 0;      int distance, cur_track;           Vector<Integer> left = new Vector<Integer>();      Vector<Integer> right = new Vector<Integer>();      Vector<Integer> seek_sequence = new Vector<Integer>();         // Tracks on the left of the      // head will be serviced when      // once the head comes back      // to the beginning (left end)      for(int i = 0; i < size; i++)     {         if (arr[i] < head)              left.add(arr[i]);          if (arr[i] > head)              right.add(arr[i]);      }         // Sorting left and right vectors      Collections.sort(left);       Collections.sort(right);          // First service the requests      // on the right side of the      // head      for(int i = 0; i < right.size(); i++)      {         cur_track = right.get(i);             // Appending current track          // to seek sequence          seek_sequence.add(cur_track);             // Calculate absolute distance          distance = Math.abs(cur_track - head);             // Increase the total count          seek_count += distance;             // Accessed track is now new head          head = cur_track;      }         // Once reached the right end      // jump to the last track that      // is needed to be serviced in      // left direction      seek_count += Math.abs(head - left.get(0));      head = left.get(0);         // Now service the requests again      // which are left      for(int i = 0; i < left.size(); i++)     {          cur_track = left.get(i);             // Appending current track to         // seek sequence          seek_sequence.add(cur_track);             // Calculate absolute distance          distance = Math.abs(cur_track - head);             // Increase the total count          seek_count += distance;             // Accessed track is now the new head          head = cur_track;      }           System.out.println("Total number of seek " +                         "operations = " + seek_count);        System.out.println("Seek Sequence is");         for(int i = 0; i < seek_sequence.size(); i++)     {         System.out.println(seek_sequence.get(i));     }  }   // Driver code public static void main(String []args) {          // Request array      int arr[] = { 176, 79, 34, 60,                   92, 11, 41, 114 };      int head = 50;         System.out.println("Initial position of head: " +                        head);         CLOOK(arr, head);  } }  // This code is contributed by divyesh072019 
Python3
# Python3 implementation of the approach size = 8 disk_size = 200  # Function to perform C-LOOK on the request # array starting from the given head def CLOOK(arr, head):          seek_count = 0     distance = 0     cur_track = 0      left = []     right = []      seek_sequence = []      # Tracks on the left of the     # head will be serviced when     # once the head comes back     # to the beginning (left end)     for i in range(size):         if (arr[i] < head):             left.append(arr[i])         if (arr[i] > head):             right.append(arr[i])      # Sorting left and right vectors     left.sort()     right.sort()      # First service the requests     # on the right side of the     # head     for i in range(len(right)):         cur_track = right[i]                  # Appending current track          # seek sequence         seek_sequence.append(cur_track)          # Calculate absolute distance         distance = abs(cur_track - head)          # Increase the total count         seek_count += distance          # Accessed track is now new head         head = cur_track      # Once reached the right end     # jump to the last track that     # is needed to be serviced in     # left direction     seek_count += abs(head - left[0])     head = left[0]      # Now service the requests again     # which are left     for i in range(len(left)):         cur_track = left[i]          # Appending current track to         # seek sequence         seek_sequence.append(cur_track)          # Calculate absolute distance         distance = abs(cur_track - head)          # Increase the total count         seek_count += distance          # Accessed track is now the new head         head = cur_track      print("Total number of seek operations =",           seek_count)     print("Seek Sequence is")      for i in range(len(seek_sequence)):         print(seek_sequence[i])  # Driver code  # Request array arr = [ 176, 79, 34, 60,         92, 11, 41, 114 ] head = 50  print("Initial position of head:", head)  CLOOK(arr, head)  # This code is contributed by rag2127 
C#
// C# implementation of the approach  using System; using System.Collections.Generic;  class GFG{      static int size = 8;      // Function to perform C-LOOK on the request  // array starting from the given head  static void CLOOK(int[] arr, int head)  {      int seek_count = 0;      int distance, cur_track;            List<int> left = new List<int>();      List<int> right = new List<int>();      List<int> seek_sequence = new List<int>();          // Tracks on the left of the      // head will be serviced when      // once the head comes back      // to the beginning (left end)      for(int i = 0; i < size; i++)     {         if (arr[i] < head)              left.Add(arr[i]);          if (arr[i] > head)              right.Add(arr[i]);      }          // Sorting left and right vectors      left.Sort();       right.Sort();           // First service the requests      // on the right side of the      // head      for(int i = 0; i < right.Count; i++)      {         cur_track = right[i];              // Appending current track          // to seek sequence          seek_sequence.Add(cur_track);              // Calculate absolute distance          distance = Math.Abs(cur_track - head);              // Increase the total count          seek_count += distance;              // Accessed track is now new head          head = cur_track;      }          // Once reached the right end      // jump to the last track that      // is needed to be serviced in      // left direction      seek_count += Math.Abs(head - left[0]);      head = left[0];          // Now service the requests again      // which are left      for(int i = 0; i < left.Count; i++)     {          cur_track = left[i];              // Appending current track to         // seek sequence          seek_sequence.Add(cur_track);              // Calculate absolute distance          distance = Math.Abs(cur_track - head);              // Increase the total count          seek_count += distance;              // Accessed track is now the new head          head = cur_track;      }            Console.WriteLine("Total number of seek " +                        "operations = " + seek_count);         Console.WriteLine("Seek Sequence is");          for(int i = 0; i < seek_sequence.Count; i++)     {         Console.WriteLine(seek_sequence[i]);     }  }   // Driver code static void Main()  {          // Request array      int[] arr = { 176, 79, 34, 60,                   92, 11, 41, 114 };      int head = 50;          Console.WriteLine("Initial position of head: " +                        head);          CLOOK(arr, head);  } }  // This code is contributed by divyeshrabadiya07 
JavaScript
<script>      // Javascript implementation of the approach          let size = 8;          // Function to perform C-LOOK on the request     // array starting from the given head     function CLOOK(arr, head)     {         let seek_count = 0;         let distance, cur_track;          let left = [];         let right = [];         let seek_sequence = [];          // Tracks on the left of the         // head will be serviced when         // once the head comes back         // to the beginning (left end)         for(let i = 0; i < size; i++)         {             if (arr[i] < head)                 left.push(arr[i]);             if (arr[i] > head)                 right.push(arr[i]);         }          // Sorting left and right vectors         left.sort(function(a, b){return a - b});         right.sort(function(a, b){return a - b});          // First service the requests         // on the right side of the         // head         for(let i = 0; i < right.length; i++)         {             cur_track = right[i];              // Appending current track             // to seek sequence             seek_sequence.push(cur_track);              // Calculate absolute distance             distance = Math.abs(cur_track - head);              // Increase the total count             seek_count += distance;              // Accessed track is now new head             head = cur_track;         }          // Once reached the right end         // jump to the last track that         // is needed to be serviced in         // left direction         seek_count += Math.abs(head - left[0]);         head = left[0];          // Now service the requests again         // which are left         for(let i = 0; i < left.length; i++)         {             cur_track = left[i];              // Appending current track to             // seek sequence             seek_sequence.push(cur_track);              // Calculate absolute distance             distance = Math.abs(cur_track - head);              // Increase the total count             seek_count += distance;              // Accessed track is now the new head             head = cur_track;         }          document.write("Total number of seek " +                           "operations = " + seek_count + "</br>");          document.write("Seek Sequence is" + "</br>");          for(let i = 0; i < seek_sequence.length; i++)         {             document.write(seek_sequence[i] + "</br>");         }     }          // Request array     let arr = [ 176, 79, 34, 60, 92, 11, 41, 114 ];     let head = 50;          document.write("Initial position of head: " + head + "</br>");          CLOOK(arr, head);      </script> 

Output:

Initial Position of Head: 50 Total Number of Seek Operations: 321 Seek Sequence: 60, 79, 92, 114, 176, 11, 34, 41 

Next Article
C-LOOK Disk Scheduling Algorithm

S

sid779
Improve
Article Tags :
  • C++ Programs
  • Operating Systems
  • GATE CS

Similar Reads

    FCFS - First Come First Serve CPU Scheduling
    First Come, First Serve (FCFS) is one of the simplest types of CPU scheduling algorithms. It is exactly what it sounds like: processes are attended to in the order in which they arrive in the ready queue, much like customers lining up at a grocery store. FCFS Scheduling is a non-preemptive algorithm
    4 min read
    Implementation of Quick sort using MPI, OMP and Posix thread
    QuickSort is a Divide and Conquer Algorithm. It picks an element as a pivot and partitions the array around the picked pivot. There are many ways of choosing the pivot elements. They are: Always pick the first element as a pivot.Always pick the last element as the pivot (implemented below)Pick a ran
    15+ min read
    Implementation of all Partition Allocation Methods in Memory Management
    Prerequisite: Partition Allocation Methods in Memory Management In Partition Allocation, when there is more than one partition freely available to accommodate a process request, a partition must be selected. To choose a particular partition, a partition allocation method is needed. A partition alloc
    15 min read
    LOOK Disk Scheduling Algorithm
    The LOOK Disk Scheduling Algorithm is the advanced version of the SCAN (elevator) disk scheduling algorithm which gives slightly better seek time than any other algorithm in the hierarchy (FCFS->SRTF->SCAN->C-SCAN->LOOK). It is used to reduce the amount of time it takes to access data on
    13 min read
    C-SCAN Disk Scheduling Algorithm
    Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations to access all the requested tracks if a C-SCAN Disk Scheduling algorithm is used.The Circular SCAN (C-SCAN) Scheduling Algorithm is a modified version of the SCAN Disk Scheduling A
    12 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences