Unilak
Course: Data structure
Lecturer : Mr Calpephore NKIKABAHIZI
Model Question 1
1. What is data structure
2. What is algorithm?
3. Why we need to do algorithm analysis?
4. What are the criteria of algorithm analysis?
5. What is asymptotic analysis of an algorithm?
6. Differentiate linear data structure from nonlinear data structure?
7. Discuss the role of set in data structure
8. A) Use a graph to illustrate the taxonomy to classify data structures
B) Discuss at least 2 applications of each data structure
9. A) Differentiate and discuss three categories of arrays
B) Differentiate:
Arrays from list
Set from Arrays
10. Construct a flowchart to determine whether a given number is
a) Even or odd.
b) Positive or negative
c) Double , integer or float
11. Using your favorite programming language , write a program to calculate
a) The product of two entered float numbers using a function
b) The sum of two integers
c) The two names (Firstname , lastname )
12. The following rules are used to calculate the bonus for the employees of an organization.
(i) If the pay is more than 2,000Rwf, the bonus amount is fixed, and it is equal to 400Rwf
(ii) If the pay is more than 1,000Rwf but less than or equal to 2,000 Rwf , the bonus will
be 10% of the pay subject to a maximum of 250Rwf.
(iii) If the pay is less than or equal to 1,000Rws , the bonus is 15% of pay, subject to a
minimum of 100RWF
13. The salesmen of a sales firm are given a commission on sales achieved, using the
following rules to design the flowchart
Sales Rate of commission in RWF
<= 500 2% of sales + 1,000
> 5,00 but <= 1,000 3% of sales + 2,000
> 1000 but <= 2,000 45% of sales + 3,000
> 2000 but <= 2500 5% of sales + 4,000
> 2500 6% of sales + 5,000
14. Write an algorithm in flowchart that
a) Checks whether student of level II at Unilak has already cleared the intuition fees and is allowed
to do this CAT. The regulations from accountant office set 125,000 Rwf as at least minimum
payment.
b) Prints PASS if the marks of students is greater or equal to 45,or FAIL otherwise for Female. The
same flowchart also print ‘Pass’ if the marks is greater than 50 for Male, and FAIL otherwise
15. Given an array of data, write algorithms that return true if the value is found in a given
array, while using
a) linear search
b) binary search
16. An array contains the elements shown below. Using the binary search algorithm, trace the
steps followed to find 88. At each loop, including the last, show the contents of low,
middle, and high. A=[8 ,13, 17 ,26 ,44, 56 ,88, 97]
17. Given an array of data
A= 3 4 10 1 7
Sort the given array by using
a) Bubble sort
b) Insertion sort
c) Selection sort
d) Quick sort
18. Write an algorithm that allow you to:
a) Traverse an array
b) Add new element at the end of array
19. Given a data structure that has input L[2][2]={{ “One”, “Two”}, {“Three”, “Four”}}
a) Find the index of Two, Three
b) Write a syntax that allows to traverse all element of A,
c) Write a syntax that allows to retrieve the first row, last row, first column, and
last column,
20. Consider a two by three array A
a) Write a statement that declares and create A in java, python and C
b) How many rows does A have?
c) How many rows does A have?
d) Write the access expressions for all the elements in row 1 of A
e) Write the access expressions for all the elements in column 2 of A.
f) Write a single statement that sets the element of A in row 0 and column 1 to zero.
g) Write a series of statements that initializes each element of A to zero. Do not use
a repetition statement.
h) Write a nested for statement that initializes each element of A to zero.
i) Write a nested for statement that inputs the values for the elements of A from the
user.
j) Write a series of statements that determines and displays the smallest value in A
k) Write a statement that displays the elements of the first row of A . Do not use
repetition.
l) Write a statement that totals the elements of the third column of t. Do not use
repetition.
m) Write a series of statements that displays the contents of t in tabular format. List
the column indices as headings across the top, and list the row indices at the left of
each row.
21. Write statements that perform the following one-dimensional-array operations:
a) Set the 10 elements of integer array counts to zero
b) Add one to each of the 15 elements of integer array bonus
c) Display the five values of integer array best Scores in column format
22. Given a list of integer L=[2,3,2,4,2,2,3,4,3,3,4,3,4]
a) Find the return value of set (L)
b) Write a pseudocode that allow us to find the common value for two lists
L1=[‘a’,2,2,’b’,’a’, ’a’,3] and L2=[2,2,2,’a’,’c’,’d’]. Find its return value.
23. Given a data dictionary of students names and their ages:
D={Mary:17, Paul:22, Joel:22, Isac:17, Quiqui:20}
For i=0 To N, where N is the size of D, then compute
1) D[names], For names=0 to size of D
2) The algorithm which return the age greater than 17
3) Write a pseudocode that return the moth form 15th February 2024 into format
15/02/2024.
24. Discuss types of linked list
25. Name two advantages of using arrays over linked lists to store data.
26. Name two advantages of using linked lists over arrays to store data.
27. Given the following linked list
a) Graphically insert the node, which is illustrated bellow, between Node B and Node C
b) from the graph resulted from a, delete Node B
c) Add a new node at the right end of node named Last node and has data 20.
d) Discuss three different ways insertion and deletion are performed in linked list
e)Write peusocode/algorithm that allow use to
e1) insert node at beginning, between nodes, and at the end
e2) Delete node at the beginning, between nodes, and at the end
28. Differentiate Input restricted de-queue from Output restricted de-queue
29. Discuss priority Queue
30. What are applications of a) queue, b)stack
31. Give your example of queue /queue and represent it using both list and linked list
32. Given a two dimension array for Game board
a) Write a statement that allow you to place eight queens on a chessboard
b) initialize board game to false
c) Write a statement that allow the validity of moves in the given game board
d) Write a syntax that allow to move in game board in : upward, downward , rightward,
leftward, lower right diagonal, lower left diagonal, upper right diagonal and upper left
diagonal
e) Check the position of queen
33. Differentiate stack from Queue
34. A letter means push and an asterisk means pop in the following sequence. Write a
Pseudocode and give the sequence of values returned by the pop operations when this
sequence of operations is performed on an initially empty LIFO stack. E A S * Y * Q U
E * * * S T * * * I O * N * * *RU
35. A letter means put and an asterisk means get in the following sequence. Write a
Pseudocode and give the sequence of values returned by the get operation when this
sequence of operations is performed on an initially empty FIFO queue. E A S * Y * Q U
E * * * S T * * * I O * N *NO * *
36. Write a program that reads in a sequence of characters and prints them in reverse order.
Use a stack
37. Discuss and give your own example on each types of recursion function
a)Write a statement that computes the recursion of
1. Fibonacci function ,
2. f(x)=1+2+3+…..+n
3. factorial function
4. Binary search function
38. Discuss the algorithms notions
39. Do flowchart, Syntax and pseudocode of exercises that are in Practice 1-6