Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Asmelash Girmay
Department of Information Technology
The Need of Data Structure
• Once ADT specification is done, a data type can then be implemented in:
• Hardwire – Circuitry as part of a computer
• Software – using the existing hard wired instructions
• It’s important in creating a linked list, dynamic stack and queue, tree, and
other data structures.
• While loop
• while (i<n) {//Statements; i++;}
• Do…while loop
• do {//Statements; i++;} while (i<n);
• The amount of space used by recursive functions is called recursive stack space.
• This space depends on:
• The size of each local variables
• The depth of the recursion
• Counting all operations performed in the algorithm will help in calculating time
• The total running time (or time complexity) includes the initializations and several other
iterative statements through the loop.
• Based on the time complexity representation of the big Oh notation, an algorithm can
be:
• Example:
• Factorial: f(n) = n*f(n-1), where f(0) = 1 for n>0.
• Fibonacci numbers f(n-1) + f(n-2), where f(0) = 0, f(1) = 1.
• Fibonacci:
• Fibonacci(n)
• if n <= 1 Return n;
• else Return Fibonacci(n-1) + Fibonacci(n-2);
• A recursion function is a function which calls itself from its body again
and again.