Permalink
Browse files

Add DFS Search

  • Loading branch information...
1 parent 4dbef9c commit 024cf4aeb7f52cf852e9f90fb661f8b8e54b49e1 @option0417 committed May 1, 2012
Showing with 74 additions and 7 deletions.
  1. +33 −0 src/Algorithms/BTreeDFS.c
  2. +24 −0 src/Algorithms/BTreeDFS.h
  3. +1 −1 src/Others/OPUtils.c
  4. +16 −6 src/main.c
View
@@ -0,0 +1,33 @@
+/*
+ * BTreeDFS.c
+ *
+ * Created on: May 1, 2012
+ * Author: option0417
+ */
+#include "BTreeDFS.h"
+
+int bTreeTrace(int* root, size_t size, int val) {
+ static int level = 1;
+
+ size_t cnt = 0;
+ size_t idx = 0;
+ for (cnt = 0; cnt < size; cnt++) {
+ for (idx = cnt; idx < size; idx = idx*2+1) {
+ if (root[idx] == val) {
+ return level;
+ } else {
+ level++;
+ }
+ }
+ idx--;
+ idx /= 2;
+ idx++;
+ for (; idx > 0; idx/=2) {
+ if (root[idx] == val) {
+ return level;
+ }
+ }
+ }
+
+ return 0;
+}
View
@@ -0,0 +1,24 @@
+/*
+ * BTreeDFS.h
+ *
+ * Created on: May 1, 2012
+ * Author: option0417
+ */
+
+#ifndef BTREEDFS_H_
+#define BTREEDFS_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * root : Root of Tree
+ * size : Number of Nodes
+ * val : Value for Search
+ * return = 0 : Not found
+ * return = n : Found record and return search times
+ */
+int bTreeTrace(int* root, size_t size, int val);
+
+#endif /* BTREEDFS_H_ */
View
@@ -18,7 +18,7 @@ int* getRandomList(int _size) {
srand(time(NULL));
while (index < size) {
- list[index++] = rand() % 100000 + 1;
+ list[index++] = rand() % 10000 + 1;
}
return list;
View
@@ -16,26 +16,36 @@
#include "Algorithms/SelectionSort.h"
#include "Algorithms/InsertionSort.h"
#include "Algorithms/QuickSort.h"
+#include "Algorithms/BTreeDFS.h"
-#define SIZE 100000000
+#define SIZE 100000
int main(void) {
+ //Variables for mesure program performance
clock_t s, f;
+
int* list = getRandomList(SIZE);
- //showList(list, SIZE);
+ showList(list, SIZE);
+ //Start record
s = getClock();
printf("Start Time : %ld\n", s);
+
+ //Algorithm Function
//bubbleSort(list, SIZE);
//selectionSort(list, SIZE);
//insertionSort(list, SIZE);
- quickSort(list, 0, SIZE-1);
+ //quickSort(list, 0, SIZE-1);
+ //bTreeTrace(list, 20000, 1234);
+
+ //Finish record
f = getClock();
printf("End Time : %ld\n", f);
- //system("pause");
- //showList(list, SIZE);
- printf("Program Execution Time : %ld", f - s);
+ showList(list, SIZE);
+
+ printf("Program Execution Time : %ld", f - s);
free(list);
+
return EXIT_SUCCESS;
}

0 comments on commit 024cf4a

Please sign in to comment.