Allocation Procedure: Analyzing Time Complexity

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Procedure
Click For Summary
SUMMARY

The discussion focuses on utilizing a Divide-and-Conquer procedure to compute the i greatest element in a row of integers, specifically through the implementation of a binary tree. Participants suggest using the Merge Sort algorithm, which has a time complexity of O(n log n), but emphasize the need for a more efficient approach. The allocation procedure involves using the malloc() function to dynamically create nodes in the binary tree. The proposed algorithm for finding the i greatest element utilizes a partitioning method, which is confirmed to be a valid Divide-and-Conquer strategy.

PREREQUISITES
  • Understanding of Divide-and-Conquer algorithms
  • Familiarity with binary tree data structures
  • Knowledge of dynamic memory allocation in C using malloc()
  • Basic understanding of sorting algorithms, particularly Merge Sort
NEXT STEPS
  • Research the implementation of binary trees in C
  • Learn about the time complexity analysis of Divide-and-Conquer algorithms
  • Explore advanced partitioning techniques for efficient element selection
  • Study the application of malloc() and free() for memory management in C
USEFUL FOR

Software developers, computer science students, and anyone interested in algorithm optimization and data structure implementation.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I am looking at the following exercise.
Use a [m]Divide-and-Conquer[/m] procedure for the computation of the [m] i [/m] greatest element at a row of integers.
Analyze the asymptotic time complexity of your algorithm.

Hint : Use the allocation procedure.I thought to sort the integers using the algorithm [m]Merge sort[/m].
But how could we use the hint? What is the [m] allocation procedure [/m] about? :confused:
 
Technology news on Phys.org
evinda said:
Hello! (Wave)

I am looking at the following exercise.
Use a [m]Divide-and-Conquer[/m] procedure for the computation of the [m] i [/m] greatest element at a row of integers.
Analyze the asymptotic time complexity of your algorithm.

Hint : Use the allocation procedure.I thought to sort the integers using the algorithm [m]Merge sort[/m].
But how could we use the hint? What is the [m] allocation procedure [/m] about? :confused:

Hey evinda! (Smile)

Merge sort has complexity O(n log n). The exercise is to do it more efficiently.
I believe you're supposed to create a binary tree.
The hint probably means you're to use [m]malloc()[/m] to construct the tree. (Wasntme)
 
I like Serena said:
Hey evinda! (Smile)

Merge sort has complexity O(n log n). The exercise is to do it more efficiently.
I believe you're supposed to create a binary tree.
The hint probably means you're to use [m]malloc()[/m] to construct the tree. (Wasntme)

So could we create a binary tree as follows?
Code:
struct node{
   int data;
   struct node *left;
   struct node *right;
}tree;tree *insert(tree *root, tree *element) {
  if (root == NULL)
     return element;
  else {
     if (element->data > root->data) {
        if (root->right != NULL) root->right = insert(root->right, element);
        else root->right = element;
     }
     else {
        if (root->left != NULL) root->left = insert(root->left, element);
       else root->left = element;
   }
   return root;
 }
}
Code:
struct node *create(int v) {
   struct node *tmp;
   tmp = (struct node*)malloc(sizeof(struct node));
   tmp->data = v;
   tmp->left = NULL;
   tmp->right = NULL;
   return tmp;
}Node;

Code:
int Algorithm(int array[0...n-1]){
    int i;
    tree T;
    Node temp_node;
    for (i=0; i<n; i++){
          temp_node = create(array[i]);
            T = insert(T, temp_node);
        }
}

How could we use a Divide-and-Conquer procedure for the computation of the [m]i[/m] greatest element, taking into consideration the binary tree? (Thinking)
 
Is the following algorithm right?

Code:
Algorithm ith(A,low,high){
   q=partition(A,low,high);
   if (high-i+1==q) return A[q];
   else if (high-i+1<q) ith(A,low,q-1);
   else ith(A,q+1,high);
}

Or don't we consider that [m] partition [/m] is a Divide and Conquer procedure? (Thinking)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
1
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K