Skip to main content

PROBLEM SOLVING AND PYTHON PROGRAMMING QUIZ

1) What is the first step in problem-solving? A) Writing code B) Debugging C) Understanding the problem D) Optimizing the solution Answer: C 2) Which of these is not a step in the problem-solving process? A) Algorithm development B) Problem analysis C) Random guessing D) Testing and debugging Answer: C 3) What is an algorithm? A) A high-level programming language B) A step-by-step procedure to solve a problem C) A flowchart D) A data structure Answer: B 4) Which of these is the simplest data structure for representing a sequence of elements? A) Dictionary B) List C) Set D) Tuple Answer: B 5) What does a flowchart represent? A) Errors in a program B) A graphical representation of an algorithm C) The final solution to a problem D) A set of Python modules Answer: B 6) What is pseudocode? A) Code written in Python B) Fake code written for fun C) An informal high-level description of an algorithm D) A tool for testing code Answer: C 7) Which of the following tools is NOT commonly used in pr...

CPU SCHEDULING

CPU Scheduling
* Maximum CPU utilization obtained with
multiprogramming
* CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait
* CPU burst distribution
Alternating Sequence of CPU & I/O Bursts

CPU Scheduler
* Selects from among the processes in memory that are ready to implement, and allocates the CPU to one of them
* CPU scheduling solutions may take place when a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates
* Scheduling under 1 and 4 is nonpreemptive
* All other scheduling is preemptive
Dispatcher
* Dispatcher module gives manage of the CPU to the process selected by the short-term scheduler; this involves:
- switching context
- switching to user mode
- jumping to the proper location in the user program to resume that program
* Dispatch latency – time it takes for the dispatcher to end one process and start another running
 
Scheduling Criteria
* CPU utilization – keep the CPU as busy as possible
* Throughput – No. of processes that finish their execution per time unit
* Turnaround time – amount of time to implement a particular process
* Waiting time – amount of time a process has been waiting in the ready queue
* Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
Optimization Criteria
* Max CPU utilization
* Max throughput
* Min turnaround time 
* Min waiting time 
* Min response time
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
 P1                24
 P2                  3
 P3                  3
Suppose that the processes enter in the order: P1 , P2 , P3 
The Gantt Chart for the schedule is:
* Waiting time for P1 = 0; P2 = 24; P3 = 27
* Average waiting time: (0 + 24 + 27)/3 = 17
* Suppose that the processes arrive in the order
P2 , P3 , P1
* The Gantt chart for the organizer is:
* Waiting time for P1 = 6; P2 = 0; P3 = 3
* Average waiting time: (6 + 0 + 3)/3 = 3
* Much better than previous case
* Convoy effect small process behind large process
Shortest-Job-First (SJF) Scheduling
* Associate with each process the length of its next CPU burst. Use these lengths to organise the process with the shortest time
* Two schemes: 
- nonpreemptive – once CPU given to the process it cannot be preempted until finishes its CPU burst
- preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is known as the 
Shortest-Remaining-Time-First (SRTF)
* SJF is optimal – gives less average waiting time for a given set of processes
Process   Arrival Time  Burst Time 
P1                  0.0                  7
P2                  2.0                  4
P3                  4.0                 1
P4                  5.0                 4
SJF (non-preemptive)
* Average waiting time = (0 + 6 + 3 + 7)/4 =4
Example of Preemptive SJF
Process   Arrival Time   Burst Time 
P1                  0.0                  7
P2                  2.0                  4
P3                  4.0                  1
P4                  5.0                  4
* SJF (preemptive)
* Average waiting time = (9 + 1 + 0 +2)/4 = 3
Priority Scheduling
* A priority number (integer) is related with each process
* The CPU is allocated to the process with the highest priority (smallest integer =highest priority)
 - Preemptive
 - Non preemptive
* SJF is a priority scheduling where priority is the forecasted next CPU burst time
* Problem = Starvation – low priority processes may never implement
* Solution = Aging - as time progresses increase the priority of the process (means Aging increases the priority of the processes so that to terminate in finite amount of time).
Round Robin (RR)
* Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has progressed, the process is preempted and added to the end of the ready queue.
* If there are n processes in the ready queue and the time quantum is q, then each process gets(1/n)of the CPU time in blocks of at most q time units at once. No process waits more than (n-1)q 
time units.
* Performance
 - q large ->FIFO
 - q small -> q must be large with respect to context switch, otherwise projecting is too high
Example of RR with Time Quantum = 20
Process    Burst Time
P1                  53
P2                  17
P3                  68
P4                  24
The Gantt chart is:
* Typically, higher average turnaround than SJF, but better response
Multilevel Queue Scheduling
* Ready queue is partitioned into separate queues:
foreground (interactive)
background (batch)
* Each queue has its own scheduling algorithm
 - foreground – RR
 - background – FCFS
* Scheduling must be done between the queues
 - Fixed priority scheduling; (i.e., serve all from foreground then from background). 
Possibility of starvation.
 - Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR
 -  20% to background in FCFS 
Multilevel Feedback Queue Scheduling
* A process can move between the various queues; aging can be implemented this way
* Multilevel-feedback-queue scheduler defined by the following parameters:
 - number of queues
 - scheduling algorithms for each queue
 - method used to determine when to upgrade a process
 - method used to determine when to demote a process
 - method used to determine which queue a process will enter when that process needs service
Thread Scheduling
* Local Scheduling – How the threads library decides which thread to put onto an available LWP
* Global Scheduling – How the kernel decides which kernel thread to run next
Multiple-Processor Scheduling
* CPU scheduling more complex when multiple CPUs are available
* Homogeneous processors within a multiprocessor
* Load sharing
* Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing
Operating System Examples
Windows XP Priorities
Linux Scheduling
* Two algorithms: time-sharing and real-time
* Time-sharing
 - Prioritized credit-based – process with most credits is scheduled next
 - Credit subtracted when timer interrupt occurs
 - When credit = 0, another process chosen
* When all processes have credit = 0, recrediting occurs
 - Based on factors including priority and history
* Real-time
 - Soft real-time
 - Posix.1b compliant – two classes
          • FCFS and RR
          • Highest priority process always runs first
Java Thread Scheduling
* JVM Uses a Preemptive, Priority-Based Scheduling Algorithm
* FIFO Queue is Used if There Are Multiple Threads With the Same Priority
JVM Schedules a Thread to Run When:
     1. The Currently Running Thread Exits the Runnable State
     2. A Higher Priority Thread Enters the Runnable State
* Note – the JVM Does Not Specify Whether Threads are Time-Sliced or Not

Popular posts from this blog

Introduction to C Programs

INTRODUCTION The programming language ‘C’ was developed by Dennis Ritchie in the early 1970s at Bell Laboratories. Although C was first developed for writing system software, today it has become such a famous language that a various of software programs are written using this language. The main advantage of using C for programming is that it can be easily used on different types of computers. Many other programming languages such as C++ and Java are also based on C which means that you will be able to learn them easily in the future. Today, C is mostly used with the UNIX operating system. Structure of a C program A C program contains one or more functions, where a function is defined as a group of statements that perform a well-defined task.The program defines the structure of a C program. The statements in a function are written in a logical series to perform a particular task. The most important function is the main() function and is a part of every C program. Rather, the execution o...

Performance

Performance ( Optional ) * The I/O system is a main factor in overall system performance, and can place heavy loads on other main components of the system ( interrupt handling, process switching, bus contention, memory access and CPU load for device drivers just to name a few. ) * Interrupt handling can be relatively costly ( slow ), which causes programmed I/O to be faster than interrupt driven I/O when the time spent busy waiting is not excessive. * Network traffic can also loads a heavy load on the system. Consider for example the sequence of events that occur when a single character is typed in a telnet session, as shown in figure( And the fact that a similar group of events must happen in reverse to echo back the character that was typed. ) Sun uses in-kernel threads for the telnet daemon, improving the supportable number of simultaneous telnet sessions from the hundreds to the thousands.   fig: Intercomputer communications. * Rather systems use front-end processor...

Mathematics

MATHEMATICS           Mathematics is the science that deals with shapes, quantities and arrangements. Archmedes is known as the father of Mathematics (287BC-212BC). Mathematics seek and use patterns to formulates new conjuctures.They resove truth or false by using mathematical proof. Mathematics developed by counting, calculation, Measurements, Shapes and motion of physical objects.  Definition Mathematics has no general accepted definition. Until 18th century Aristotle defined mathematics as "the science of quantity". Many mathematicans take no interest in definition they simply say "Mathematics is what Mathematican do". Three leading definition of mathematics today are logicist, intutionist, and formalist. Logicist - In terms of Benjamin peirce, the definition of mathematics in terms of logic are "the science that draws necessary conclusion" and also said that " All mathematics is symbolic logic" by Mathematician Rusell. Intutionist - L.E.J.Bro...