Addressing Modes Example Instruction Meaning When Used: Complexity and Big-O Notation
Addressing Modes Example Instruction Meaning When Used: Complexity and Big-O Notation
Addressing
modes
Register
Immediate
Displacement
Register
deffered
Indexed
Direct
Memory
deferred
Autoincrement
Autodecrement
Scaled
Example
Instruction
Add R4,R3
Add R4, #3
Add R4,
100(R1)
Meaning
When used
R4 <- R4 + R3
R4 <- R4 + 3
R4 <- R4 + M[R1]
All are important but we will mostly talk about CPU time in 367. Other classes will discuss other
resources (e.g., disk usage may be an important topic in a database class).
Be careful to differentiate between:
Some methods perform the same number of operations every time they are called. For example,
the size method of the List class always performs just one operation: return numItems; the
number of operations is independent of the size of the list. We say that methods like this (that
always perform a fixed number of basic operations) require constant time.
Other methods may perform different numbers of operations, depending on the value of a
parameter or a field. For example, for the array implementation of the List class,
the remove method has to move over all of the items that were to the right of the item that was
removed (to fill in the gap). The number of moves depends both on the position of the removed
item and the number of items in the list. We call the important factors (the parameters and/or
fields whose values affect the number of operations performed) theproblem size or the input
size.
When we consider the complexity of a method, we don't really care about the exact number of
operations that are performed; instead, we care about how the number of operations relates to the
problem size. If the problem size doubles, does the number of operations stay the same? double?
increase in some other way? For constant-time methods like the size method, doubling the
problem size does not affect the number of operations (which stays the same).
We are usually interested in the worst case: what is the most operations that might be performed
for a given problem size. For example, as discussed above, the remove method has to move all of
the items that come after the removed item one place to the left in the array. In the worst
case, all of the items in the array must be moved. Therefore, in the worst case, the time
for remove is proportional to the number of items in the list, and we say that the worst-case time
for remove is linear in the number of items in the list. For a linear-time method, if the problem
size doubles, the number of operations also doubles.
Elements are added at the rear end and the elements are deleted at front end of the queue
Both the front and the rear pointers points to the beginning of the array.
It is also called as Ring buffer.
Items can inserted and deleted from a queue in O(1) time.
Step 1) start
Step 2) create anode with the following fields to store information and the address of the next
node.
Structure node
begin
int info
pointer to structure node called next
end
Step 3) create a class called clist with the member variables of pointer to structure nodes called
root, prev, next and the member functions create ( ) to create the circular linked list and display (
) to display the circular linked list.
Step 4) create an object called C of clist type
Step 5) call C. create ( ) member function
Step 6) call C. display ( ) member function
Step 7) stop
Algorithm for create ( ) function:Step 1) allocate the memory for newnode
newnode = new (node )
Step 2) newnode->next=newnode. // circular
Step 3) Repeat the steps from 4 to 5 until choice = n
Step 4) if (root=NULL)
root = prev=newnode // prev is a running pointer which points last node of a list
else
newnode->next = root
prev->next = newnode
prev = newnode
Step 5) Read the choice
Step 6) return
Algorithm for display ( ) function :Step 1) start
Step 2) declare a variable of pointer to structure node called temp, assign root to temp
temp = root
Step 3) display temp->info
Step 4) temp = temp->next
Step 5) repeat the steps 6 until temp = root
Step 6) display temp info
Step 7) temp=temp->next
Step 8) return
Using array
In arrays the range of a subscript is 0 to n-1 where n is the maximum size. To make the array as a
circular array by making the subscript 0 as the next address of the subscript n-1 by using the
formula subscript = (subscript +1) % maximum size. In circular queue the front and rear pointer
are updated by using the above formula.
The following figure shows circular array:
Step 1. start
Step 2. if ((front == rear) && (rear == -1))
Print error circular queue underflow
Step 3. else
{ element = Q[front]
If (front == rear) front=rear = -1
Else
Front = (front + 1) % max
}
Step 4. stop