Follow Me

ADTs exercises in C Programming in C

  • ADT for a point: Provide an ADT specification for a point in a two dimensional space. By definition, to create such a point, you need to provide two coordinates. Supplement your ADT with adequately chosen query functions....
  • ADT for a robot: We aim to define a \(\texttt{Robot}\) ADT moving in a two dimensional space with functions allowing to: Create a robot from a position \((x, y)\) and a direction (\(\texttt{North}\), \(\texttt{South}\), \(\texttt{East}\), \(\texttt{West}\)) that beco...
  • ADT for Boolean type: Provide an ADT specification for \(\texttt{Boolean}\) type. By definition, a Boolean is either \(\texttt{true}\) or \(\texttt{false}\). The negation (\(\texttt{Not}\)) of a Boolean is also a Boolean. The \(\texttt{and}\) and \(\texttt{or}\) between t...
  • ADT for a set of n elements: Write an ADT specification for a set of n elements. Operations include (create set, add an element to a set, delete an element from a set, check whether an element is in a set, union of 2 sets, intersection of 2 sets, cardinality of a set, complement...
  • ADT for a circle: We define an ADT specification for a point in a two dimensional space as follows: Name: \(\texttt{point}\)Use: \(\texttt{float, Boolean}\)Functions:\(\begin{array}{p{1cm} l l l} & \textbf{Init} & \texttt{float} \times \texttt{float} & \rightarrow \texttt{point}\\ & \textbf{Move} & \texttt{point} \times \texttt{float} \times \texttt{float} & \rightarrow \texttt{point}\\ & \textbf{Distance} & \texttt{point} \times \texttt{point} & \rightarrow \texttt{float}\\ & \textbf{Equal} & \texttt{point} \times \texttt{point} & \rightarrow \texttt{Boolean}\\ \end{array}\)...
  • ADT for a tuple of n floats: We define \(\texttt{tuple}\) ADT allowing to manipulate, for any value of \(n\), the tuple of floats \((x_1,\cdots,x_n)\), as follows: Type: \(\texttt{tuple}\)Use: \(\texttt{float, integer}\)Functions:\(\begin{array}{p{1cm} l l l} & \textbf{Create} & \texttt{integer} & \rightarrow \texttt{tuple} \text{ (creates a tuple with null elements)}\\ & \textbf{Assign} & \texttt{tuple} \times \texttt{integer} \times \texttt{float} & \rightarrow \texttt{tuple} \text{ (assigns a value to the } i^{th} \text{ element } x_i \text{ of a tuple)}\\ & \textbf{Nth} & \texttt{tuple} \times \texttt{integer} & \rightarrow \texttt{float} \text{ (returns the } n^{th} \text{ element of a tuple)}\\ & \textbf{Rank} & \texttt{tuple} & \rightarrow \texttt{integer} \text{ (number of a tuple elements)}\\ & \textbf{Sum} & \texttt{tuple} \times \texttt{tuple} & \rightarrow \texttt{tuple}\\ & \textbf{Product} & \texttt{tuple} \times \texttt{float} & \rightarrow \texttt{tuple} \text{ (multiplies all tuple elements by a given float)}\\ \end{array}\)...
  • ADT for a set of pairs of values: A set of pairs consists of \(\texttt{key}-\texttt{value}\) pairs where the keys belong to a given type \(\texttt{key_type}\) and values to another type \(\texttt{val_type}\). The set \(\{\texttt{<size-170>, <age-18>, <weight-71>, <number-12>}\}\)...
  • ADT for a Deque: Complete the following abstract data type \(\texttt{Q2En}\) (Queue with 2 ends), which is a linked structure of elements supporting the insertion and removal of elements at the beginning and at the end, by including operators allowing to: create a \(\texttt{Q2En}\)...
  • ADT for a drink distributor: We would like to model a soft drink distributor available to the employees of a company. We assume that there are several types of drinks belonging to type \(\texttt{t_drink}\). There are 2 types of users: customers and service agents. Operations to ...
  • ADT for a polynomial: Given the following polynomial of maximum degree \(N_{Max}\): \( P(x)=a_n x^n + a_{n-1} x^{n-1} + \cdots a_1 x + a_0 \) where \(n\) (polynomial degree) \(\leq\) \(n_{max}\) and \(a_i\) are real numbers. The operations of the abstract data type \(\texttt{Polynomial}\)...
  • ADT for Ternary trees: We define the abstract data type \(\texttt{Ternary_Tree}\) (3 children tree) as follows: Type: \(\texttt{TT(element)}\)Use: \(\texttt{Boolean}\) Functions:\(\begin{array}{p{1cm} l l l l} & \textbf{Init}: & \texttt{TT} & \rightarrow \texttt{TT} & \text{// creates an empty TT} \\ & \textbf{Construct}: & \texttt{element} \times \texttt{TT} \times \texttt{TT} \times \texttt{TT} & \rightarrow \texttt{TT} & \text{// construct a tree by giving the root value and its 3 children} \\ & \textbf{LeftChildren}: & \texttt{TT} & \rightarrow \texttt{TT}&  return TT left children  \\ & \textbf{MiddleChildren}: & \texttt{TT}  & \rightarrow \texttt{TT} & \text{// return TT middle children}  \\ & \textbf{RightChildren}: & \texttt{TT}  & \rightarrow \texttt{TT} & \text{// return TT right children}  \\ & \textbf{Root}: & \texttt{TT}  & \rightarrow \texttt{element} & \text{// return root value}  \\ & \textbf{isEmpty}: & \texttt{TT} & \rightarrow \texttt{Boolean} & \text{// test if TT is empty}\\ & \textbf{Rotation}: & \texttt{TT}   & \rightarrow \texttt{TT} & \text{// replace left subtree by middle subtree, middle subtree by right subtree, and right subtree by the left one and leave the root unchanged. If the tree is empty then the operation has no effect} \\   & \textbf{CutM}: & \texttt{TT}   & \rightarrow \texttt{TT} & \text{// replace the middle subtree by an empty tree} \\ \end{array}\)...
  • ADT for Intervals: A non empty interval of integer is defined by two integers $$[lowerb, upperb]$$ where: $$lowerb$$ is the lower bound, $$upperb$$ the upper bound, and $$lowerb \leq upperb$$; empty interval $$[]$$ is defined as having no lower bound nor upper bound. W...
  • ADT for Inverted Phonebooks: Consider the ADT \(\texttt{IP}\) (inverted phonebook) which is a set of entries, each consisting in the phone number and the name of a person, that is used to find the person name from his phone number (like True caller): Type: \(\texttt{IP}\)Paramet...
  • ADT for priority queues: Consider the ADT \(\texttt{PQ}\) (priority queue) which is a data structure used by a computer system to deal with processes having each a unique identifier and a priority. It is obvious that the processes having the highest priority will be executed...

Back to the list of exercises