# 0.9 Exercises

 Page 1 / 5

## Exercises

(From Introduction to Algorithms, Second Edition. MIT Press, ISBN: 0262032937)

Exercises 2.1

Implement a stack using a singly linked list L. The operations PUSH and POP should still take O(1) time.

Exercises 2.2

Implement a queue by a singly linked list L. The operations ENQUEUE and DEQUEUE should still take O(1) time.

Exercises 2.3

The dynamic-set operation UNION takes two disjoint sets S1 and S2 as input, and it returns a set S = S1 _ S2 consisting of all the elements of S1 and S2. The sets S1 and S2 are usually destroyed by the operation. Show how to support UNION in O(1) time using a suitable list data structure.

Exercises 2.4

Explain how to implement doubly linked lists using only one pointer value np[x] per item

instead of the usual two (next and prev). Assume that all pointer values can be interpreted as k-bit integers, and define np[x] to be np[x]= next[x] XOR prev[x], the k-bit "exclusive-or" of next[x] and prev[x]. (The value NIL is represented by 0.) Be sure to describe what information is needed to access the head of the list. Show how to implement the SEARCH, INSERT, and DELETE operations on such a list. Also show how to reverse such a list in O(1) time.

## Chapter 3. stack and queue

Exercises 3.1

Using Figure above as a model, illustrate the result of each operation in the sequence PUSH(S, 4), PUSH(S, 1), PUSH(S, 3), POP(S), PUSH(S, 8), and POP(S) on an initially empty stack S stored in array S[1 _ 6].

Exercises 3.2

Explain how to implement two stacks in one array A[1 _ n] in such a way that neither stack overflows unless the total number of elements in both stacks together is n. The PUSH and POP operations should run in O(1) time.

Exercises 3.3

Using Figure above as a model, illustrate the result of each operation in the sequence

ENQUEUE(Q, 4), ENQUEUE(Q, 1), ENQUEUE(Q, 3), DEQUEUE(Q), ENQUEUE(Q, 8), and DEQUEUE(Q) on an initially empty queue Q stored in array Q[1 _ 6].

Exercises 3.4

Rewrite ENQUEUE and DEQUEUE to detect underflow and overflow of a queue.

Exercises 3.5

Whereas a stack allows insertion and deletion of elements at only one end, and a queue allows insertion at one end and deletion at the other end, a deque (double-ended queue) allows insertion and deletion at both ends. Write four O(1)-time procedures to insert elements into and delete elements from both ends of a deque constructed from an array.

Exercises 3.6

Show how to implement a queue using two stacks. Analyze the running time of the queue operations.

Exercises 3.7.

Show how to implement a stack using two queues. Analyze the running time of the stack operations.

## Chapter 4. designing algorithms

Exercises 4.1.

Using Figure below as a model, illustrate the operation of merge sort on the array A = _3, 41, 52, 26, 38, 57, 9, 49_.

Exercises 4.2.

Rewrite the MERGE procedure so that it does not use sentinels, instead stopping once either array L or R has had all its elements copied back to A and then copying the remainder of the other array back into A.

Exercises 4.3

Insertion sort can be expressed as a recursive procedure as follows. In order to sort A[1 _ n], we recursively sort A[1 _ n -1]and then insert A[n] into the sorted array A[1 _ n - 1]. Write a recurrence for the running time of this recursive version of insertion sort.

1.it allows producers to learn and invent 2.it allows agent to take advantage of economic scale 3.it allow agents to focus in areas of
can someone explain the motive of money to me?
ask the question you don't know
ojo
opportunity cost
Sylvo
the motive of money is to pay for goods or services. it's also for transaction purposes bet it ordinary or unforseen
Silke
Money helps to reduce our scarcity problems. It can satisfy your wants to an extent
Okwori
How dose economics use science methods to explains it problems
according to Jhon Robinson the main problem of economics is what to produce? how to produce? whom to produce? economics tries to solve these problem scientifically by using its theories which are scientific in nature,basically micro and macro theories which just explain what the problem is...
Lavkesh
and now the solving techinique is also changed. only theories or its matematical +statistical version is not sufficient so the economist had developed Econometrics which includes economic theory+mathematical economics+statistics, for solving economic problem. This method treats economics as a pure
Lavkesh
..pure science so this technique is based on pure scientific methods.
Lavkesh
Economics is the scientific study of human behavior so there for science is used to solve economics problems using economics theories
Florence
economic is not higly subject of taminadu ...
Mutha
measurement of elasticity of demand
Price elasticity of demand= Percentage change in quantity demanded/ Percentage change in price
Jale
For example, suppose that a 10 percent increase in the price of an ice-cream cone causes the amount of ice cream you buy to fall by 20 percent. We calculate your elasticity of demand as
Jale
Price elasticity of demand =20 percent /10 percent = 2
Jale
In this example, the elasticity is 2, reflecting that the change in the quantity demanded is proportionately twice as large as the change in the price.
Jale
what is economic
economics is a social science that studies the relationship of human behavior between ends and scare...
Lawrence
Why is economics as a subject is so important to human being?
austine
it's significant in study of managing available resources to satisfy human needs and wants
mohamed
economics is the science of wealth
Aamir
it is also said that it is the science of scarcity
Aamir
why study economic
Neo
Economic helps to meet our needs and wants nd to make choices.
Abraham
careers or jobs associated with economics
Neo
Economics is more than choices, scarcity, resources etc. It has a lot to do with psychology, social psychology. Understand motivation for consumer decisons.
TOM
okey
Neo
How does commercial banks create credit
what is equilibrium price?
happen when demand curve and supply curve meet
Enockz
intersection point of demand and supply curve
Sarjeel
the equilibrium price is that price at which the quantity demanded is equal to the quantity supplied... i.e the price at which what people want to buy is equal to what the sellers want to sell.
Che
what is difference between demand and quantity demand
Sarjeel
the price which is prevailing in the market ,it is the price at which the consumer is getting maximum satisfaction and the producer is getting maximum profit.
Rather
at equilibrium price demand for commodity is equal to supply of commodity..
Rather
dear sareel, quantity demand means the quantity of commodity which is demanded at a particular price e,g , your demand is for 4 oranges when price of orange is 5,, on the other hand demand means the whole quantity price relationship, quantity demand is shown on a particular point on demand curve,
Rather
Rather
what is elasticity of demand
Evans
what is Economics?
Ahmed
Economics can be defined as a social sciences that study human behavior as a relationship between end and scarce mean which have alternative use
Azeez
What is taxation
Azeez
economics is the study of scarcity
Suleiman
dear Suleiman how?
Enockz
economics is a subject matter that studies different economic activities as directed towards maximization of income at level of individual and maximization of social welfare at the level of society as a whole
Rather
economics studies us how to allocate scarce resources to full fill the maximum human wants as the resources have alternative uses..and r very scare to fullfill the human wants as the wants of humans are unlimited
Rather
demand is what a buyer is able and willing to buy at a specific price where by quantity demanded is amount of demand the buyer is able and willing to buy at a specific price.
daudi
thanks che..
Stella
how does commercial banks create credit
Penda
write models of Aggregate Supply?
models of aggregate supply?
abdi
Then what's the law of elasticity?
austine
wat happen if money circulation failed to be controlled in any county?
the amount of money in circulation increases and cause aggregate demand to rise. Thus, hyperinflation.
Che
what's heteroscandacity
Crowther
price mechanism refers to the manner which price of goods and services affect the demand and supply of goods and services
Abaide
heteroscandacity: Is the circumstance where there is unequal variances across the observations.
Enockz
what is price mechanisms?
price mechanism refers to the manner which price of goods and services affect the demand and supply of goods and services
Abaide
what is demand
desire and ability to pay for a commodity is called demand.
Rather
i desire to become Prime Minister of India , is it demand ?please answer---
Rather
demand refers to the quantity demanded of a commodity that consumers are willing and able to buy at a particular price over a given period of time
Abigail
or the willingness power of a commoditythat is backed up by the ability to pay
Abigail
u r 100% right..
Rather
is ability to purchase a perticular goods at any price at a given time.
Neema
tanz Rather
Abigail
ur desire to become a prime minister of lndia is nt demand because u have nt made any efforts or willingness, it is called mere wish or lets say mere desire
Abigail
Thank you so much dear Abigail Mante for giving answer to my question..
Rather
U are welcome
Abigail
it's ok,dear..
Rather
The term ceteris paribus implies that
Oyelekan
Demand is the quantity demanded of a commodity at which a consumer is willing and able to purchase at various prices over a given period of time.
Suleman
ceteris parbus explains the law of demand,which states that at a higher price quantity demanded of a commodity is low and at a lower price quantity demanded of a commodity is high all other things being equal.
Abigail
U know right girl
Suleman
kk
Abigail
ceteris paribus is an economics terms used in situations where we considered other factors to remain unchanged
Ndeh
Oyelekan
please how does disposable income affect demand?
Che
hell. somebody must tell me what is the meaning if cetrasparibus
Darling
plz. guys
Darling
the quantity of a commodity that a consumer ready willing and able to purchase at a particular price and in a particular period of time is known as demand
The
ceterusparibus means constant i,e,(other things do not change or other things remains constant)
Rather
wht
Bilal
Sarjeel
things like what@Rather
Oyelekan
bilal sheikh why u has been written what
Sarjeel
e,g demand is determined by various factors like price of commodity, uses of good, expected changes in near future, nature of commodity , but when we learn price elasticity of demand , we keep other determinants of demand constant(i,e , we do not expect any change in price of good in near future,etc
Rather
i think u understand the term ceterus paribus..
Rather
bcz I can not understand
Bilal
what
Sarjeel
ok bro
Bilal
wht is other factors
Bilal
income of consumer, taste,
Sarjeel
Gold. Medlist in economics and. Lecturer of economics
HAZRAT
hello..what's are the factors affecting cross elasticity of demand.? at least five factors
Elzevery
The time it takes to get a product to market. That time limit has a name call "Just in Time."
William
thanks guys
kabeer
hey guys what is inelastic demand
Abaide
when there is no change in quantity demanded due to change in price then elasticity of demand is inelastic
Rather
Hi sucker how are you...
HAZRAT
Abaide
HAZRAT
yes. what is the main cause of Heteroscedasticity
Abaide
hi
Habib
waht is elasticity of demand
Sarparah
elasticity of demand means change in quantity demanded divided by change in any of its determinent ,e,g , price ed= % change in quantity demanded/ % change in price.
Rather
elasticity of demand is the degree of responsiveness of quantity demanded of a commodity to a change in price of the commodity in question ,price of other related commodity n the consumers income
Abigail
yes
Kumako
ok
Abigail
guys what is monopoly
kabeer
A single seller in the market.
Tahir
what are the importance of economics
what causes the demand curve to shift.
Stephen
other factors except price.it include test of a consumer fashen presence of substitute advatisment
Neema
factors other than price
Rather
Its helps to determine the price
Mavis
state three factors that affect demand and supply
1,price of the product 2,expectations in near future 3,uses of product
Rather
Abigail
1.alternative products on market. 2.changes on price 3.consumer's expectations
Anusia
what is cheque
resources of exchanging of money to any where
Dinesh
it is a writen order to a bank to pay a specific sum of money to a person
Richard
what is the meaning of money
a device agreed upon by a group of people to be used interchangeably for goods and/or services.
drquackery
Money is anything that is generally accepted by people in certain country as a medium of exchange and in a settlement of debt
Amos
is anything which is legally asepted in any society to be used as a medium of exchange
Enockz
is it legal to cut money or burn money
Rather
Money is a durable commodity, that is acceptable as means payment, settlement of debt and medium of exchange.
olayiwola
No it is not legal,that is an abuse to its path
Oyelekan
Money is anything that is generally considered and accepted in exchange of goods and services.
Hanes
money is anything generally acceptable by people in a particular society fr the buying of goods and services and for the settlement of debts. Money acts as legal tender.
Penda
money is anything generally accepted by the public for the settlement. of debt n for the payment of goods and services
Bertilla
Difference between extinct and extici spicies
in a comparison of the stages of meiosis to the stage of mitosis, which stages are unique to meiosis and which stages have the same event in botg meiosis and mitosis
Got questions? Join the online conversation and get instant answers!